4
from bzrlib.selftest import TestCaseInTempDir, TestCase
4
from bzrlib.tests import TestCaseWithTransport, TestCase
5
5
from bzrlib.branch import ScratchBranch, Branch
6
from bzrlib.errors import NotBranchError
9
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
def test_no_changes(self):
21
from bzrlib.errors import PointlessCommit
23
b = Branch.initialize('.')
25
self.build_tree(['hello.txt'])
27
self.assertRaises(PointlessCommit,
28
b.working_tree().commit,
29
'commit without adding',
30
allow_pointless=False)
32
b.working_tree().commit('commit pointless tree',
37
b.working_tree().commit('commit first added file',
38
allow_pointless=False)
40
self.assertRaises(PointlessCommit,
41
b.working_tree().commit,
42
'commit after adding file',
43
allow_pointless=False)
45
b.working_tree().commit('commit pointless revision with one file',
49
class MoreTests(TestCaseInTempDir):
51
def test_rename_dirs(self):
52
"""Test renaming directories and the files within them."""
53
b = Branch.initialize('.')
54
self.build_tree(['dir/', 'dir/sub/', 'dir/sub/file'])
55
b.add(['dir', 'dir/sub', 'dir/sub/file'])
57
b.working_tree().commit('create initial state')
59
# TODO: lift out to a test helper that checks the shape of
62
revid = b.revision_history()[0]
63
self.log('first revision_id is {%s}' % revid)
65
inv = b.get_revision_inventory(revid)
66
self.log('contents of inventory: %r' % inv.entries())
68
self.check_inventory_shape(inv,
69
['dir', 'dir/sub', 'dir/sub/file'])
71
b.rename_one('dir', 'newdir')
73
self.check_inventory_shape(b.working_tree().read_working_inventory(),
74
['newdir', 'newdir/sub', 'newdir/sub/file'])
76
b.rename_one('newdir/sub', 'newdir/newsub')
77
self.check_inventory_shape(b.working_tree().read_working_inventory(),
78
['newdir', 'newdir/newsub',
79
'newdir/newsub/file'])
6
from bzrlib.errors import PathNotChild
7
from bzrlib.osutils import relpath, pathjoin, abspath, realpath
10
class MoreTests(TestCaseWithTransport):
81
12
def test_relpath(self):
82
13
"""test for branch path lookups
85
16
job: given a path (either relative to cwd or absolute), work out
86
17
if it is inside a branch and return the path relative to the base.
88
from bzrlib.osutils import relpath
89
19
import tempfile, shutil
91
21
savedir = os.getcwdu()
92
22
dtmp = tempfile.mkdtemp()
93
23
# On Mac OSX, /tmp actually expands to /private/tmp
94
dtmp = os.path.realpath(dtmp)
97
27
return relpath(dtmp, p)
100
30
# check paths inside dtmp while standing outside it
101
self.assertEqual(rp(os.path.join(dtmp, 'foo')), 'foo')
31
self.assertEqual(rp(pathjoin(dtmp, 'foo')), 'foo')
104
34
self.assertEqual(rp(dtmp), '')
106
self.assertRaises(NotBranchError,
36
self.assertRaises(PathNotChild,
110
40
# now some near-miss operations -- note that
111
41
# os.path.commonprefix gets these wrong!
112
self.assertRaises(NotBranchError,
42
self.assertRaises(PathNotChild,
114
44
dtmp.rstrip('\\/') + '2')
116
self.assertRaises(NotBranchError,
46
self.assertRaises(PathNotChild,
118
48
dtmp.rstrip('\\/') + '2/foo')
121
51
# directory, or nearby
124
FOO_BAR_QUUX = os.path.join('foo', 'bar', 'quux')
125
self.assertEqual(rp('foo/bar/quux'), FOO_BAR_QUUX)
54
self.assertEqual(rp('foo/bar/quux'), 'foo/bar/quux')
127
56
self.assertEqual(rp('foo'), 'foo')
129
58
self.assertEqual(rp('./foo'), 'foo')
131
self.assertEqual(rp(os.path.abspath('foo')), 'foo')
60
self.assertEqual(rp(abspath('foo')), 'foo')
133
self.assertRaises(NotBranchError,
62
self.assertRaises(PathNotChild,