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(
30
'target').open_workingtree()
29
target_tree = source_tree.controldir.sprout('target').open_workingtree()
31
30
self.build_tree(['source/dir/', 'source/dir/contents'])
32
31
source_tree.add(['dir', 'dir/contents'], [b'dir-id', b'contents-id'])
33
32
source_tree.commit('added dir')
55
54
tree = self.make_branch_and_tree('tree')
56
55
tree.commit('empty tree')
57
merge_target = tree.controldir.sprout(
58
'merge_target').open_workingtree()
56
merge_target = tree.controldir.sprout('merge_target').open_workingtree()
59
57
self.build_tree(['tree/new_file'])
61
59
# newly-added files should not be deleted
86
84
def tree_with_executable(self):
87
85
tree = self.make_branch_and_tree('tree')
88
tt = tree.get_transform()
89
tt.new_file('newfile', tt.root, [b'helooo!'], b'newfile-id', True)
86
tt = transform.TreeTransform(tree)
87
tt.new_file('newfile', tt.root, 'helooo!', 'newfile-id', True)
91
with tree.lock_write():
92
91
self.assertTrue(tree.is_executable('newfile'))
93
92
tree.commit('added newfile')
96
97
def test_preserve_execute(self):
97
98
tree = self.tree_with_executable()
98
tt = tree.get_transform()
99
tt = transform.TreeTransform(tree)
99
100
newfile = tt.trans_id_tree_path('newfile')
100
101
tt.delete_contents(newfile)
101
tt.create_file([b'Woooorld!'], newfile)
102
tt.create_file('Woooorld!', newfile)
103
104
tree = workingtree.WorkingTree.open('tree')
104
105
tree.lock_write()
105
106
self.addCleanup(tree.unlock)
106
107
self.assertTrue(tree.is_executable('newfile'))
107
108
transform.revert(tree, tree.basis_tree(), None, backups=True)
108
with tree.get_file('newfile', 'rb') as f:
109
self.assertEqual(b'helooo!', f.read())
109
self.assertEqual('helooo!', tree.get_file('newfile').read())
110
110
self.assertTrue(tree.is_executable('newfile'))
112
112
def test_revert_executable(self):
113
113
tree = self.tree_with_executable()
114
tt = tree.get_transform()
114
tt = transform.TreeTransform(tree)
115
115
newfile = tt.trans_id_tree_path('newfile')
116
116
tt.set_executability(False, newfile)
124
124
tree = self.make_branch_and_tree('.')
125
125
self.build_tree(['file'])
127
rev1 = tree.commit('added file')
128
with tree.lock_read():
129
file_sha = tree.get_file_sha1('file')
127
tree.commit('added file', rev_id=b'rev1')
130
128
os.unlink('file')
131
129
tree.commit('removed file')
132
130
self.assertPathDoesNotExist('file')
133
tree.revert(old_tree=tree.branch.repository.revision_tree(rev1))
134
self.assertEqual({'file': file_sha}, tree.merge_modified())
131
tree.revert(old_tree=tree.branch.repository.revision_tree(b'rev1'))
135
132
self.assertPathExists('file')
137
134
self.assertPathDoesNotExist('file')
141
138
tree = self.make_branch_and_tree('.')
142
139
self.build_tree(['dir/', 'dir/file1', 'dir/file2'])
143
140
tree.add(['dir', 'dir/file1', 'dir/file2'],
144
[b'dir-id', b'file1-id', b'file2-id'])
141
['dir-id', 'file1-id', 'file2-id'])
145
142
tree.commit("Added files")
146
143
os.unlink('dir/file1')
147
144
os.unlink('dir/file2')
150
147
tree.revert(['dir/file1'])
151
148
self.assertPathExists('dir/file1')
152
149
self.assertPathDoesNotExist('dir/file2')
153
self.assertEqual(b'dir-id', tree.path2id('dir'))
150
self.assertEqual('dir-id', tree.path2id('dir'))
155
152
def test_revert_root_id_change(self):
156
153
tree = self.make_branch_and_tree('.')
159
156
tree.add(['file1'])
160
157
tree.commit('first')
161
158
tree.set_root_id(b'temp-root-id')
162
self.assertEqual(b'temp-root-id', tree.path2id(''))
159
self.assertEqual('temp-root-id', tree.get_root_id())
164
self.assertEqual(b'initial-root-id', tree.path2id(''))
161
self.assertEqual('initial-root-id', tree.get_root_id())