149
150
"""When a directory has been moved, its children are preserved."""
150
151
tree = self.make_branch_and_tree('tree')
151
152
tree.lock_write()
153
self.addCleanup(tree.unlock)
152
154
self.build_tree_contents([('tree/foo/', ''),
153
155
('tree/foo/bar', 'bar'),
154
156
('tree/foo/empty', '')])
158
160
os.rename('tree/foo', 'tree/baz')
159
161
RenameMap.guess_renames(tree)
160
162
self.assertEqual('baz/empty', tree.id2path('empty-id'))
164
def test_guess_renames_dry_run(self):
165
tree = self.make_branch_and_tree('tree')
167
self.addCleanup(tree.unlock)
168
self.build_tree(['tree/file'])
169
tree.add('file', 'file-id')
170
tree.commit('Added file')
171
os.rename('tree/file', 'tree/file2')
172
RenameMap.guess_renames(tree, dry_run=True)
173
self.assertEqual('file', tree.id2path('file-id'))
176
def captureNotes(cmd, *args, **kwargs):
178
def my_note(fmt, *args):
179
notes.append(fmt % args)
180
old_note = trace.note
183
result = cmd(*args, **kwargs)
185
trace.note = old_note
188
def test_guess_renames_output(self):
189
"""guess_renames emits output whether dry_run is True or False."""
190
tree = self.make_branch_and_tree('tree')
192
self.addCleanup(tree.unlock)
193
self.build_tree(['tree/file'])
194
tree.add('file', 'file-id')
195
tree.commit('Added file')
196
os.rename('tree/file', 'tree/file2')
197
notes = self.captureNotes(RenameMap.guess_renames, tree,
199
self.assertEqual('file => file2', ''.join(notes))
200
notes = self.captureNotes(RenameMap.guess_renames, tree,
202
self.assertEqual('file => file2', ''.join(notes))