19
from breezy import merge, tests, transform, workingtree
19
from bzrlib import merge, tests, transform, workingtree
22
22
class TestRevert(tests.TestCaseWithTransport):
26
26
"""Reverting a merge that adds a directory deletes the directory"""
27
27
source_tree = self.make_branch_and_tree('source')
28
28
source_tree.commit('empty tree')
29
target_tree = source_tree.controldir.sprout('target').open_workingtree()
29
target_tree = source_tree.bzrdir.sprout('target').open_workingtree()
30
30
self.build_tree(['source/dir/', 'source/dir/contents'])
31
source_tree.add(['dir', 'dir/contents'], [b'dir-id', b'contents-id'])
31
source_tree.add(['dir', 'dir/contents'], ['dir-id', 'contents-id'])
32
32
source_tree.commit('added dir')
33
33
target_tree.lock_write()
34
34
self.addCleanup(target_tree.unlock)
54
54
tree = self.make_branch_and_tree('tree')
55
55
tree.commit('empty tree')
56
merge_target = tree.controldir.sprout('merge_target').open_workingtree()
56
merge_target = tree.bzrdir.sprout('merge_target').open_workingtree()
57
57
self.build_tree(['tree/new_file'])
59
59
# newly-added files should not be deleted
77
77
# files should not be deleted if changed after a merge
78
78
merge_target.merge_from_branch(tree.branch)
79
79
self.assertPathExists('merge_target/new_file')
80
self.build_tree_contents([('merge_target/new_file', b'new_contents')])
80
self.build_tree_contents([('merge_target/new_file', 'new_contents')])
81
81
merge_target.revert()
82
82
self.assertPathExists('merge_target/new_file')
97
97
def test_preserve_execute(self):
98
98
tree = self.tree_with_executable()
99
99
tt = transform.TreeTransform(tree)
100
newfile = tt.trans_id_tree_path('newfile')
100
newfile = tt.trans_id_tree_file_id('newfile-id')
101
101
tt.delete_contents(newfile)
102
102
tt.create_file('Woooorld!', newfile)
104
104
tree = workingtree.WorkingTree.open('tree')
105
105
tree.lock_write()
106
106
self.addCleanup(tree.unlock)
107
self.assertTrue(tree.is_executable('newfile'))
107
self.assertTrue(tree.is_executable('newfile-id'))
108
108
transform.revert(tree, tree.basis_tree(), None, backups=True)
109
self.assertEqual('helooo!', tree.get_file('newfile').read())
110
self.assertTrue(tree.is_executable('newfile'))
109
self.assertEqual('helooo!', tree.get_file('newfile-id').read())
110
self.assertTrue(tree.is_executable('newfile-id'))
112
112
def test_revert_executable(self):
113
113
tree = self.tree_with_executable()
114
114
tt = transform.TreeTransform(tree)
115
newfile = tt.trans_id_tree_path('newfile')
115
newfile = tt.trans_id_tree_file_id('newfile-id')
116
116
tt.set_executability(False, newfile)
118
118
tree.lock_write()
119
119
self.addCleanup(tree.unlock)
120
120
transform.revert(tree, tree.basis_tree(), None)
121
self.assertTrue(tree.is_executable('newfile'))
121
self.assertTrue(tree.is_executable('newfile-id'))
123
123
def test_revert_deletes_files_from_revert(self):
124
124
tree = self.make_branch_and_tree('.')
125
125
self.build_tree(['file'])
127
tree.commit('added file', rev_id=b'rev1')
127
tree.commit('added file', rev_id='rev1')
128
128
os.unlink('file')
129
129
tree.commit('removed file')
130
130
self.assertPathDoesNotExist('file')
152
152
def test_revert_root_id_change(self):
153
153
tree = self.make_branch_and_tree('.')
154
tree.set_root_id(b'initial-root-id')
154
tree.set_root_id('initial-root-id')
155
155
self.build_tree(['file1'])
156
156
tree.add(['file1'])
157
157
tree.commit('first')
158
tree.set_root_id(b'temp-root-id')
158
tree.set_root_id('temp-root-id')
159
159
self.assertEqual('temp-root-id', tree.get_root_id())
161
161
self.assertEqual('initial-root-id', tree.get_root_id())