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