6
from bzrlib.selftest import InTempDir, TestBase
7
from bzrlib.branch import ScratchBranch, Branch
8
from bzrlib.errors import NotBranchError, NotVersionedError
11
class Unknowns(InTempDir):
13
b = Branch('.', init=True)
15
self.build_tree(['hello.txt',
18
self.assertEquals(list(b.unknowns()),
23
class ValidateRevisionId(TestBase):
25
from bzrlib.revision import validate_revision_id
26
validate_revision_id('mbp@sourcefrog.net-20050311061123-96a255005c7c9dbe')
28
self.assertRaises(ValueError,
33
self.assertRaises(ValueError,
35
'mbp@sourcefrog.net-20050311061123-96a255005c7c9dbe\n')
38
self.assertRaises(ValueError,
40
' mbp@sourcefrog.net-20050311061123-96a255005c7c9dbe')
42
self.assertRaises(ValueError,
44
'Martin Pool <mbp@sourcefrog.net>-20050311061123-96a255005c7c9dbe')
48
class PendingMerges(InTempDir):
49
"""Tracking pending-merged revisions."""
51
b = Branch('.', init=True)
53
self.assertEquals(b.pending_merges(), [])
55
b.add_pending_merge('foo@azkhazan-123123-abcabc')
57
self.assertEquals(b.pending_merges(), ['foo@azkhazan-123123-abcabc'])
59
b.add_pending_merge('foo@azkhazan-123123-abcabc')
61
self.assertEquals(b.pending_merges(), ['foo@azkhazan-123123-abcabc'])
63
b.add_pending_merge('wibble@fofof--20050401--1928390812')
64
self.assertEquals(b.pending_merges(),
65
['foo@azkhazan-123123-abcabc',
66
'wibble@fofof--20050401--1928390812'])
69
class Revert(InTempDir):
70
"""Test selected-file revert"""
72
b = Branch('.', init=True)
74
self.build_tree(['hello.txt'])
75
file('hello.txt', 'w').write('initial hello')
77
self.assertRaises(NotVersionedError,
78
b.revert, ['hello.txt'])
81
b.commit('create initial hello.txt')
83
self.check_file_contents('hello.txt', 'initial hello')
84
file('hello.txt', 'w').write('new hello')
85
self.check_file_contents('hello.txt', 'new hello')
87
# revert file modified since last revision
88
b.revert(['hello.txt'])
89
self.check_file_contents('hello.txt', 'initial hello')
90
self.check_file_contents('hello.txt~', 'new hello')
92
# reverting again clobbers the backup
93
b.revert(['hello.txt'])
94
self.check_file_contents('hello.txt', 'initial hello')
95
self.check_file_contents('hello.txt~', 'initial hello')
99
class RenameDirs(InTempDir):
100
"""Test renaming directories and the files within them."""
102
b = Branch('.', init=True)
103
self.build_tree(['dir/', 'dir/sub/', 'dir/sub/file'])
104
b.add(['dir', 'dir/sub', 'dir/sub/file'])
106
b.commit('create initial state')
108
# TODO: lift out to a test helper that checks the shape of
111
revid = b.revision_history()[0]
112
self.log('first revision_id is {%s}' % revid)
114
inv = b.get_revision_inventory(revid)
115
self.log('contents of inventory: %r' % inv.entries())
117
self.check_inventory_shape(inv,
118
['dir', 'dir/sub', 'dir/sub/file'])
120
b.rename_one('dir', 'newdir')
122
self.check_inventory_shape(b.inventory,
123
['newdir', 'newdir/sub', 'newdir/sub/file'])
125
b.rename_one('newdir/sub', 'newdir/newsub')
126
self.check_inventory_shape(b.inventory,
127
['newdir', 'newdir/newsub',
128
'newdir/newsub/file'])
133
class BranchPathTestCase(TestBase):
134
"""test for branch path lookups
136
Branch.relpath and bzrlib.branch._relpath do a simple but subtle
137
job: given a path (either relative to cwd or absolute), work out
138
if it is inside a branch and return the path relative to the base.
142
from bzrlib.branch import _relpath
143
import tempfile, shutil
145
savedir = os.getcwdu()
146
dtmp = tempfile.mkdtemp()
149
return _relpath(dtmp, p)
152
# check paths inside dtmp while standing outside it
153
self.assertEqual(rp(os.path.join(dtmp, 'foo')), 'foo')
156
self.assertEqual(rp(dtmp), '')
158
self.assertRaises(NotBranchError,
162
# now some near-miss operations -- note that
163
# os.path.commonprefix gets these wrong!
164
self.assertRaises(NotBranchError,
166
dtmp.rstrip('\\/') + '2')
168
self.assertRaises(NotBranchError,
170
dtmp.rstrip('\\/') + '2/foo')
172
# now operations based on relpath of files in current
173
# directory, or nearby
176
self.assertEqual(rp('foo/bar/quux'), 'foo/bar/quux')
178
self.assertEqual(rp('foo'), 'foo')
180
self.assertEqual(rp('./foo'), 'foo')
182
self.assertEqual(rp(os.path.abspath('foo')), 'foo')
184
self.assertRaises(NotBranchError,