409
404
self.wt.rename_one('file1', 'dir1/file1')
410
405
old_tree = self.b.repository.revision_tree('rev-1')
411
406
new_tree = self.b.repository.revision_tree('rev-4')
412
out = self.get_diff(old_tree, new_tree, specific_files=['dir1'],
407
out = self.get_diff(old_tree, new_tree, specific_files=['dir1'],
413
408
working_tree=self.wt)
414
409
self.assertContainsRe(out, 'file1\t')
415
out = self.get_diff(old_tree, new_tree, specific_files=['dir2'],
410
out = self.get_diff(old_tree, new_tree, specific_files=['dir2'],
416
411
working_tree=self.wt)
417
412
self.assertNotContainsRe(out, 'file1\t')
787
782
self.assertEquals(unique_lcs('ab', 'ab'), [(0,0), (1,1)])
788
783
self.assertEquals(unique_lcs('abcde', 'cdeab'), [(2,0), (3,1), (4,2)])
789
784
self.assertEquals(unique_lcs('cdeab', 'abcde'), [(0,2), (1,3), (2,4)])
790
self.assertEquals(unique_lcs('abXde', 'abYde'), [(0,0), (1,1),
785
self.assertEquals(unique_lcs('abXde', 'abYde'), [(0,0), (1,1),
792
787
self.assertEquals(unique_lcs('acbac', 'abc'), [(2,1)])
1129
1124
, list(unified_diff(txt_a, txt_b,
1130
1125
sequencematcher=psm)))
1127
def test_patience_unified_diff_with_dates(self):
1128
txt_a = ['hello there\n',
1130
'how are you today?\n']
1131
txt_b = ['hello there\n',
1132
'how are you today?\n']
1133
unified_diff = bzrlib.patiencediff.unified_diff
1134
psm = self._PatienceSequenceMatcher
1135
self.assertEquals(['--- a\t2008-08-08\n',
1136
'+++ b\t2008-09-09\n',
1137
'@@ -1,3 +1,2 @@\n',
1140
' how are you today?\n'
1142
, list(unified_diff(txt_a, txt_b,
1143
fromfile='a', tofile='b',
1144
fromfiledate='2008-08-08',
1145
tofiledate='2008-09-09',
1146
sequencematcher=psm)))
1133
1149
class TestPatienceDiffLib_c(TestPatienceDiffLib):
1135
_test_needs_features = [CompiledPatienceDiffFeature]
1151
_test_needs_features = [compiled_patiencediff_feature]
1137
1153
def setUp(self):
1138
1154
super(TestPatienceDiffLib_c, self).setUp()
1275
1291
def test_from_string(self):
1276
1292
diff_obj = DiffFromTool.from_string('diff', None, None, None)
1277
1293
self.addCleanup(diff_obj.finish)
1278
self.assertEqual(['diff', '%(old_path)s', '%(new_path)s'],
1294
self.assertEqual(['diff', '@old_path', '@new_path'],
1279
1295
diff_obj.command_template)
1281
1297
def test_from_string_u5(self):
1282
diff_obj = DiffFromTool.from_string('diff -u\\ 5', None, None, None)
1298
diff_obj = DiffFromTool.from_string('diff "-u 5"', None, None, None)
1283
1299
self.addCleanup(diff_obj.finish)
1284
self.assertEqual(['diff', '-u 5', '%(old_path)s', '%(new_path)s'],
1300
self.assertEqual(['diff', '-u 5', '@old_path', '@new_path'],
1285
1301
diff_obj.command_template)
1286
1302
self.assertEqual(['diff', '-u 5', 'old-path', 'new-path'],
1287
1303
diff_obj._get_command('old-path', 'new-path'))
1305
def test_from_string_path_with_backslashes(self):
1306
self.requireFeature(BackslashDirSeparatorFeature)
1307
tool = 'C:\\Tools\\Diff.exe'
1308
diff_obj = DiffFromTool.from_string(tool, None, None, None)
1309
self.addCleanup(diff_obj.finish)
1310
self.assertEqual(['C:\\Tools\\Diff.exe', '@old_path', '@new_path'],
1311
diff_obj.command_template)
1312
self.assertEqual(['C:\\Tools\\Diff.exe', 'old-path', 'new-path'],
1313
diff_obj._get_command('old-path', 'new-path'))
1289
1315
def test_execute(self):
1290
1316
output = StringIO()
1291
1317
diff_obj = DiffFromTool(['python', '-c',
1292
'print "%(old_path)s %(new_path)s"'],
1318
'print "@old_path @new_path"'],
1293
1319
None, None, output)
1294
1320
self.addCleanup(diff_obj.finish)
1295
1321
diff_obj._execute('old', 'new')
1313
1339
tree.commit('old tree')
1314
1340
tree.lock_read()
1315
1341
self.addCleanup(tree.unlock)
1342
basis_tree = tree.basis_tree()
1343
basis_tree.lock_read()
1344
self.addCleanup(basis_tree.unlock)
1316
1345
diff_obj = DiffFromTool(['python', '-c',
1317
'print "%(old_path)s %(new_path)s"'],
1346
'print "@old_path @new_path"'],
1347
basis_tree, tree, output)
1319
1348
diff_obj._prepare_files('file-id', 'file', 'file')
1320
self.assertReadableByAttrib(diff_obj._root, 'old\\file', r'old\\file')
1321
self.assertReadableByAttrib(diff_obj._root, 'new\\file', r'new\\file')
1349
# The old content should be readonly
1350
self.assertReadableByAttrib(diff_obj._root, 'old\\file',
1352
# The new content should use the tree object, not a 'new' file anymore
1353
self.assertEndsWith(tree.basedir, 'work/tree')
1354
self.assertReadableByAttrib(tree.basedir, 'file', r'work\\tree\\file$')
1323
1356
def assertReadableByAttrib(self, cwd, relpath, regex):
1324
1357
proc = subprocess.Popen(['attrib', relpath],
1325
1358
stdout=subprocess.PIPE,
1328
result = proc.stdout.read()
1329
self.assertContainsRe(result, regex)
1360
(result, err) = proc.communicate()
1361
self.assertContainsRe(result.replace('\r\n', '\n'), regex)
1331
1363
def test_prepare_files(self):
1332
1364
output = StringIO()
1346
1379
tree.lock_read()
1347
1380
self.addCleanup(tree.unlock)
1348
1381
diff_obj = DiffFromTool(['python', '-c',
1349
'print "%(old_path)s %(new_path)s"'],
1382
'print "@old_path @new_path"'],
1350
1383
old_tree, tree, output)
1351
1384
self.addCleanup(diff_obj.finish)
1352
1385
self.assertContainsRe(diff_obj._root, 'bzr-diff-[^/]*')
1353
1386
old_path, new_path = diff_obj._prepare_files('file-id', 'oldname',
1355
1388
self.assertContainsRe(old_path, 'old/oldname$')
1356
self.assertEqual(0, os.stat(old_path).st_mtime)
1357
self.assertContainsRe(new_path, 'new/newname$')
1389
self.assertEqual(315532800, os.stat(old_path).st_mtime)
1390
self.assertContainsRe(new_path, 'tree/newname$')
1358
1391
self.assertFileEqual('oldcontent', old_path)
1359
1392
self.assertFileEqual('newcontent', new_path)
1360
1393
if osutils.host_os_dereferences_symlinks():
1361
1394
self.assertTrue(os.path.samefile('tree/newname', new_path))
1362
1395
# make sure we can create files with the same parent directories
1363
1396
diff_obj._prepare_files('file2-id', 'oldname2', 'newname2')
1399
class TestGetTreesAndBranchesToDiffLocked(TestCaseWithTransport):
1401
def call_gtabtd(self, path_list, revision_specs, old_url, new_url):
1402
"""Call get_trees_and_branches_to_diff_locked. Overridden by
1403
TestGetTreesAndBranchesToDiff.
1405
return get_trees_and_branches_to_diff_locked(
1406
path_list, revision_specs, old_url, new_url, self.addCleanup)
1408
def test_basic(self):
1409
tree = self.make_branch_and_tree('tree')
1410
(old_tree, new_tree,
1411
old_branch, new_branch,
1412
specific_files, extra_trees) = self.call_gtabtd(
1413
['tree'], None, None, None)
1415
self.assertIsInstance(old_tree, RevisionTree)
1416
self.assertEqual(_mod_revision.NULL_REVISION, old_tree.get_revision_id())
1417
self.assertEqual(tree.basedir, new_tree.basedir)
1418
self.assertEqual(tree.branch.base, old_branch.base)
1419
self.assertEqual(tree.branch.base, new_branch.base)
1420
self.assertIs(None, specific_files)
1421
self.assertIs(None, extra_trees)
1423
def test_with_rev_specs(self):
1424
tree = self.make_branch_and_tree('tree')
1425
self.build_tree_contents([('tree/file', 'oldcontent')])
1426
tree.add('file', 'file-id')
1427
tree.commit('old tree', timestamp=0, rev_id="old-id")
1428
self.build_tree_contents([('tree/file', 'newcontent')])
1429
tree.commit('new tree', timestamp=0, rev_id="new-id")
1431
revisions = [RevisionSpec.from_string('1'),
1432
RevisionSpec.from_string('2')]
1433
(old_tree, new_tree,
1434
old_branch, new_branch,
1435
specific_files, extra_trees) = self.call_gtabtd(
1436
['tree'], revisions, None, None)
1438
self.assertIsInstance(old_tree, RevisionTree)
1439
self.assertEqual("old-id", old_tree.get_revision_id())
1440
self.assertIsInstance(new_tree, RevisionTree)
1441
self.assertEqual("new-id", new_tree.get_revision_id())
1442
self.assertEqual(tree.branch.base, old_branch.base)
1443
self.assertEqual(tree.branch.base, new_branch.base)
1444
self.assertIs(None, specific_files)
1445
self.assertEqual(tree.basedir, extra_trees[0].basedir)
1448
class TestGetTreesAndBranchesToDiff(TestGetTreesAndBranchesToDiffLocked):
1449
"""Apply the tests for get_trees_and_branches_to_diff_locked to the
1450
deprecated get_trees_and_branches_to_diff function.
1453
def call_gtabtd(self, path_list, revision_specs, old_url, new_url):
1454
return self.applyDeprecated(
1455
deprecated_in((2, 2, 0)), get_trees_and_branches_to_diff,
1456
path_list, revision_specs, old_url, new_url)