4
4
from bzrlib.selftest import TestCaseInTempDir, TestCase
5
5
from bzrlib.branch import ScratchBranch, Branch
6
from bzrlib.errors import NotBranchError, NotVersionedError
6
from bzrlib.errors import NotBranchError
9
9
class TestBranch(TestCaseInTempDir):
25
25
self.build_tree(['hello.txt'])
27
27
self.assertRaises(PointlessCommit,
28
b.working_tree().commit,
29
29
'commit without adding',
30
30
allow_pointless=False)
32
b.commit('commit pointless tree',
32
b.working_tree().commit('commit pointless tree',
33
33
allow_pointless=True)
37
b.commit('commit first added file',
37
b.working_tree().commit('commit first added file',
38
38
allow_pointless=False)
40
40
self.assertRaises(PointlessCommit,
41
b.working_tree().commit,
42
42
'commit after adding file',
43
43
allow_pointless=False)
45
b.commit('commit pointless revision with one file',
45
b.working_tree().commit('commit pointless revision with one file',
46
46
allow_pointless=True)
49
49
class MoreTests(TestCaseInTempDir):
51
def test_revert(self):
52
"""Test selected-file revert"""
53
b = Branch.initialize('.')
55
self.build_tree(['hello.txt'])
56
file('hello.txt', 'w').write('initial hello')
58
self.assertRaises(NotVersionedError,
59
b.revert, ['hello.txt'])
62
b.commit('create initial hello.txt')
64
self.check_file_contents('hello.txt', 'initial hello')
65
file('hello.txt', 'w').write('new hello')
66
self.check_file_contents('hello.txt', 'new hello')
68
# revert file modified since last revision
69
b.revert(['hello.txt'])
70
self.check_file_contents('hello.txt', 'initial hello')
71
self.check_file_contents('hello.txt~', 'new hello')
73
# reverting again clobbers the backup
74
b.revert(['hello.txt'])
75
self.check_file_contents('hello.txt', 'initial hello')
76
self.check_file_contents('hello.txt~', 'initial hello')
78
51
def test_rename_dirs(self):
79
52
"""Test renaming directories and the files within them."""
80
53
b = Branch.initialize('.')
81
54
self.build_tree(['dir/', 'dir/sub/', 'dir/sub/file'])
82
55
b.add(['dir', 'dir/sub', 'dir/sub/file'])
84
b.commit('create initial state')
57
b.working_tree().commit('create initial state')
86
59
# TODO: lift out to a test helper that checks the shape of
98
71
b.rename_one('dir', 'newdir')
100
self.check_inventory_shape(b.inventory,
73
self.check_inventory_shape(b.working_tree().read_working_inventory(),
101
74
['newdir', 'newdir/sub', 'newdir/sub/file'])
103
76
b.rename_one('newdir/sub', 'newdir/newsub')
104
self.check_inventory_shape(b.inventory,
77
self.check_inventory_shape(b.working_tree().read_working_inventory(),
105
78
['newdir', 'newdir/newsub',
106
79
'newdir/newsub/file'])