132
132
"%s is not modified, %s are" % (str(expected_modified_entry),
135
def assertContent(self, branch, tree, path, content):
136
file_id = tree.inventory.path2id(path)
138
self.addCleanup(branch.unlock)
139
self.assertEqual(tree.get_file_text(file_id), content)
141
def assertSymlinkTarget(self, branch, tree, path, target):
142
file_id = tree.inventory.path2id(path)
144
self.addCleanup(branch.unlock)
145
self.assertEqual(tree.get_symlink_target(file_id), target)
147
def assertRevisionRoot(self, revtree, path):
148
self.assertEqual(revtree.get_revision_id(),
149
revtree.inventory.root.children[path].revision)
152
class TestModify(TestCaseForGenericProcessor):
154
def file_command_iter(self, path, kind='file'):
156
author = ['', 'bugs@a.com', time.time(), time.timezone]
157
committer = ['', 'elmer@a.com', time.time(), time.timezone]
159
yield commands.FileModifyCommand(path, kind, False,
161
yield commands.CommitCommand('head', '1', author,
162
committer, "commit 1", None, [], files_one)
164
yield commands.FileModifyCommand(path, kind, False,
166
yield commands.CommitCommand('head', '2', author,
167
committer, "commit 2", ":1", [], files_two)
170
def test_modify_file_in_root(self):
171
handler, branch = self.get_handler()
173
handler.process(self.file_command_iter(path))
174
revtree0, revtree1 = self.assertChanges(branch, 1,
175
expected_added=[(path,)])
176
revtree1, revtree2 = self.assertChanges(branch, 2,
177
expected_modified=[(path,)])
178
self.assertContent(branch, revtree1, path, "aaa")
179
self.assertContent(branch, revtree2, path, "bbb")
180
self.assertRevisionRoot(revtree1, path)
181
self.assertRevisionRoot(revtree2, path)
183
def test_modify_file_in_subdir(self):
184
handler, branch = self.get_handler()
186
handler.process(self.file_command_iter(path))
187
revtree0, revtree1 = self.assertChanges(branch, 1,
188
expected_added=[('a',), (path,)])
189
revtree1, revtree2 = self.assertChanges(branch, 2,
190
expected_modified=[(path,)])
191
self.assertContent(branch, revtree1, path, "aaa")
192
self.assertContent(branch, revtree2, path, "bbb")
194
def test_modify_symlink_in_root(self):
195
handler, branch = self.get_handler()
197
handler.process(self.file_command_iter(path, kind='symlink'))
198
revtree1, revtree2 = self.assertChanges(branch, 2,
199
expected_modified=[(path,)])
200
self.assertSymlinkTarget(branch, revtree1, path, "aaa")
201
self.assertSymlinkTarget(branch, revtree2, path, "bbb")
202
self.assertRevisionRoot(revtree1, path)
203
self.assertRevisionRoot(revtree2, path)
205
def test_modify_symlink_in_subdir(self):
206
handler, branch = self.get_handler()
208
handler.process(self.file_command_iter(path, kind='symlink'))
209
revtree0, revtree1 = self.assertChanges(branch, 1,
210
expected_added=[('a',), (path,)])
211
revtree1, revtree2 = self.assertChanges(branch, 2,
212
expected_modified=[(path,)])
213
self.assertSymlinkTarget(branch, revtree1, path, "aaa")
214
self.assertSymlinkTarget(branch, revtree2, path, "bbb")
136
217
class TestRename(TestCaseForGenericProcessor):
157
238
handler.process(self.get_command_iter(old_path, new_path))
158
revtree1, revtree2 = self.assertChanges(branch, 1,
239
revtree1, revtree2 = self.assertChanges(branch, 2,
159
240
expected_renamed=[(old_path, new_path)])
160
self.assertEqual(revtree1.get_revision_id(),
161
revtree1.inventory.root.children['a'].revision)
162
self.assertEqual(revtree2.get_revision_id(),
163
revtree2.inventory.root.children['b'].revision)
241
self.assertRevisionRoot(revtree1, old_path)
242
self.assertRevisionRoot(revtree2, new_path)
165
244
def test_rename_in_subdir(self):
166
245
handler, branch = self.get_handler()
169
248
handler.process(self.get_command_iter(old_path, new_path))
170
self.assertChanges(branch, 1, expected_renamed=[(old_path, new_path)])
249
self.assertChanges(branch, 2, expected_renamed=[(old_path, new_path)])
172
251
def test_move_to_new_dir(self):
173
252
handler, branch = self.get_handler()
176
255
handler.process(self.get_command_iter(old_path, new_path))
177
self.assertChanges(branch, 1, expected_renamed=[(old_path, new_path)],
256
self.assertChanges(branch, 2, expected_renamed=[(old_path, new_path)],
178
257
expected_added=[('b',)])
181
260
class TestCopy(TestCaseForGenericProcessor):
183
def file_command_iter(self, src_path, dest_path):
262
def file_command_iter(self, src_path, dest_path, kind='file'):
184
263
def command_list():
185
264
author = ['', 'bugs@a.com', time.time(), time.timezone]
186
265
committer = ['', 'elmer@a.com', time.time(), time.timezone]
188
yield commands.FileModifyCommand(src_path, 'file', False,
267
yield commands.FileModifyCommand(src_path, kind, False,
190
269
yield commands.CommitCommand('head', '1', author,
191
270
committer, "commit 1", None, [], files_one)
195
274
committer, "commit 2", ":1", [], files_two)
196
275
return command_list
198
def assertContent(self, branch, tree, path, content):
199
file_id = tree.inventory.path2id(path)
201
self.addCleanup(branch.unlock)
202
self.assertEqual(tree.get_file_text(file_id), content)
204
277
def test_copy_file_in_root(self):
205
278
handler, branch = self.get_handler()
208
281
handler.process(self.file_command_iter(src_path, dest_path))
209
revtree1, revtree2 = self.assertChanges(branch, 1,
282
revtree1, revtree2 = self.assertChanges(branch, 2,
210
283
expected_added=[(dest_path,)])
284
self.assertContent(branch, revtree1, src_path, "aaa")
285
self.assertContent(branch, revtree2, src_path, "aaa")
211
286
self.assertContent(branch, revtree2, dest_path, "aaa")
212
self.assertEqual(revtree1.get_revision_id(),
213
revtree1.inventory.root.children['a'].revision)
214
self.assertEqual(revtree2.get_revision_id(),
215
revtree2.inventory.root.children['b'].revision)
287
self.assertRevisionRoot(revtree1, src_path)
288
self.assertRevisionRoot(revtree2, dest_path)
217
290
def test_copy_file_in_subdir(self):
218
291
handler, branch = self.get_handler()
220
293
dest_path = 'a/b'
221
294
handler.process(self.file_command_iter(src_path, dest_path))
222
revtree1, revtree2 = self.assertChanges(branch, 1,
295
revtree1, revtree2 = self.assertChanges(branch, 2,
223
296
expected_added=[(dest_path,)])
297
self.assertContent(branch, revtree1, src_path, "aaa")
298
self.assertContent(branch, revtree2, src_path, "aaa")
224
299
self.assertContent(branch, revtree2, dest_path, "aaa")
226
301
def test_copy_file_to_new_dir(self):
229
304
dest_path = 'b/a'
230
305
handler.process(self.file_command_iter(src_path, dest_path))
231
revtree1, revtree2 = self.assertChanges(branch, 1,
306
revtree1, revtree2 = self.assertChanges(branch, 2,
232
307
expected_added=[('b',), (dest_path,)])
308
self.assertContent(branch, revtree1, src_path, "aaa")
309
self.assertContent(branch, revtree2, src_path, "aaa")
233
310
self.assertContent(branch, revtree2, dest_path, "aaa")
235
def symlink_command_iter(self, src_path, dest_path):
237
author = ['', 'bugs@a.com', time.time(), time.timezone]
238
committer = ['', 'elmer@a.com', time.time(), time.timezone]
240
yield commands.FileModifyCommand(src_path, 'symlink', False,
242
yield commands.CommitCommand('head', '1', author,
243
committer, "commit 1", None, [], files_one)
245
yield commands.FileCopyCommand(src_path, dest_path)
246
yield commands.CommitCommand('head', '2', author,
247
committer, "commit 2", ":1", [], files_two)
250
def assertSymlinkTarget(self, branch, tree, path, target):
251
file_id = tree.inventory.path2id(path)
253
self.addCleanup(branch.unlock)
254
self.assertEqual(tree.get_symlink_target(file_id), target)
256
312
def test_copy_symlink_in_root(self):
257
313
handler, branch = self.get_handler()
260
handler.process(self.symlink_command_iter(src_path, dest_path))
261
revtree1, revtree2 = self.assertChanges(branch, 1,
316
handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
317
revtree1, revtree2 = self.assertChanges(branch, 2,
262
318
expected_added=[(dest_path,)])
319
self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
320
self.assertSymlinkTarget(branch, revtree2, src_path, "aaa")
263
321
self.assertSymlinkTarget(branch, revtree2, dest_path, "aaa")
264
self.assertEqual(revtree1.get_revision_id(),
265
revtree1.inventory.root.children['a'].revision)
266
self.assertEqual(revtree2.get_revision_id(),
267
revtree2.inventory.root.children['b'].revision)
322
self.assertRevisionRoot(revtree1, src_path)
323
self.assertRevisionRoot(revtree2, dest_path)
269
325
def test_copy_symlink_in_subdir(self):
270
326
handler, branch = self.get_handler()
272
328
dest_path = 'a/b'
273
handler.process(self.symlink_command_iter(src_path, dest_path))
274
revtree1, revtree2 = self.assertChanges(branch, 1,
329
handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
330
revtree1, revtree2 = self.assertChanges(branch, 2,
275
331
expected_added=[(dest_path,)])
332
self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
333
self.assertSymlinkTarget(branch, revtree2, src_path, "aaa")
276
334
self.assertSymlinkTarget(branch, revtree2, dest_path, "aaa")
278
336
def test_copy_symlink_to_new_dir(self):
279
337
handler, branch = self.get_handler()
281
339
dest_path = 'b/a'
282
handler.process(self.symlink_command_iter(src_path, dest_path))
283
revtree1, revtree2 = self.assertChanges(branch, 1,
340
handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
341
revtree1, revtree2 = self.assertChanges(branch, 2,
284
342
expected_added=[('b',), (dest_path,)])
343
self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
344
self.assertSymlinkTarget(branch, revtree2, src_path, "aaa")
285
345
self.assertSymlinkTarget(branch, revtree2, dest_path, "aaa")