4
from bzrlib.selftest import TestCaseInTempDir, TestCase
4
from bzrlib.tests import TestCaseInTempDir, TestCase
5
5
from bzrlib.branch import ScratchBranch, Branch
6
from bzrlib.errors import NotBranchError
6
from bzrlib.errors import PathNotChild
7
from bzrlib.osutils import relpath, pathjoin, abspath, realpath
9
10
class TestBranch(TestCaseInTempDir):
11
def test_unknowns(self):
12
b = Branch.initialize('.')
14
self.build_tree(['hello.txt',
17
self.assertEquals(list(b.unknowns()),
20
12
def test_no_changes(self):
21
13
from bzrlib.errors import PointlessCommit
23
b = Branch.initialize('.')
15
b = Branch.initialize(u'.')
25
17
self.build_tree(['hello.txt'])
51
43
def test_rename_dirs(self):
52
44
"""Test renaming directories and the files within them."""
53
b = Branch.initialize('.')
45
b = Branch.initialize(u'.')
54
46
self.build_tree(['dir/', 'dir/sub/', 'dir/sub/file'])
55
b.add(['dir', 'dir/sub', 'dir/sub/file'])
47
b.working_tree().add(['dir', 'dir/sub', 'dir/sub/file'])
57
49
b.working_tree().commit('create initial state')
68
60
self.check_inventory_shape(inv,
69
61
['dir', 'dir/sub', 'dir/sub/file'])
71
b.rename_one('dir', 'newdir')
63
b.working_tree().rename_one('dir', 'newdir')
73
65
self.check_inventory_shape(b.working_tree().read_working_inventory(),
74
66
['newdir', 'newdir/sub', 'newdir/sub/file'])
76
b.rename_one('newdir/sub', 'newdir/newsub')
68
b.working_tree().rename_one('newdir/sub', 'newdir/newsub')
77
69
self.check_inventory_shape(b.working_tree().read_working_inventory(),
78
70
['newdir', 'newdir/newsub',
79
71
'newdir/newsub/file'])
85
77
job: given a path (either relative to cwd or absolute), work out
86
78
if it is inside a branch and return the path relative to the base.
88
from bzrlib.osutils import relpath
89
80
import tempfile, shutil
91
82
savedir = os.getcwdu()
92
83
dtmp = tempfile.mkdtemp()
93
84
# On Mac OSX, /tmp actually expands to /private/tmp
94
dtmp = os.path.realpath(dtmp)
97
88
return relpath(dtmp, p)
100
91
# check paths inside dtmp while standing outside it
101
self.assertEqual(rp(os.path.join(dtmp, 'foo')), 'foo')
92
self.assertEqual(rp(pathjoin(dtmp, 'foo')), 'foo')
104
95
self.assertEqual(rp(dtmp), '')
106
self.assertRaises(NotBranchError,
97
self.assertRaises(PathNotChild,
110
101
# now some near-miss operations -- note that
111
102
# os.path.commonprefix gets these wrong!
112
self.assertRaises(NotBranchError,
103
self.assertRaises(PathNotChild,
114
105
dtmp.rstrip('\\/') + '2')
116
self.assertRaises(NotBranchError,
107
self.assertRaises(PathNotChild,
118
109
dtmp.rstrip('\\/') + '2/foo')
121
112
# directory, or nearby
124
FOO_BAR_QUUX = os.path.join('foo', 'bar', 'quux')
125
self.assertEqual(rp('foo/bar/quux'), FOO_BAR_QUUX)
115
self.assertEqual(rp('foo/bar/quux'), 'foo/bar/quux')
127
117
self.assertEqual(rp('foo'), 'foo')
129
119
self.assertEqual(rp('./foo'), 'foo')
131
self.assertEqual(rp(os.path.abspath('foo')), 'foo')
121
self.assertEqual(rp(abspath('foo')), 'foo')
133
self.assertRaises(NotBranchError,
123
self.assertRaises(PathNotChild,