~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_diff.py

  • Committer: Robert Collins
  • Date: 2010-04-08 04:34:03 UTC
  • mfrom: (5138 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5139.
  • Revision ID: robertc@robertcollins.net-20100408043403-56z0d07vdqrx7f3t
Update bugfix for 528114 to trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
import os
18
18
import os.path
19
19
from cStringIO import StringIO
20
20
import errno
21
21
import subprocess
 
22
import sys
22
23
from tempfile import TemporaryFile
23
24
 
24
25
from bzrlib import tests
31
32
    external_diff,
32
33
    internal_diff,
33
34
    show_diff_trees,
 
35
    get_trees_and_branches_to_diff,
34
36
    )
35
37
from bzrlib.errors import BinaryFile, NoDiff, ExecutableMissing
36
38
import bzrlib.osutils as osutils
 
39
import bzrlib.revision as _mod_revision
37
40
import bzrlib.transform as transform
38
41
import bzrlib.patiencediff
39
42
import bzrlib._patiencediff_py
40
43
from bzrlib.tests import (Feature, TestCase, TestCaseWithTransport,
41
44
                          TestCaseInTempDir, TestSkipped)
42
 
 
43
 
 
44
 
class _CompiledPatienceDiffFeature(Feature):
 
45
from bzrlib.revisiontree import RevisionTree
 
46
from bzrlib.revisionspec import RevisionSpec
 
47
 
 
48
from bzrlib.tests.test_win32utils import BackslashDirSeparatorFeature
 
49
 
 
50
 
 
51
class _AttribFeature(Feature):
45
52
 
46
53
    def _probe(self):
 
54
        if (sys.platform not in ('cygwin', 'win32')):
 
55
            return False
47
56
        try:
48
 
            import bzrlib._patiencediff_c
49
 
        except ImportError:
 
57
            proc = subprocess.Popen(['attrib', '.'], stdout=subprocess.PIPE)
 
58
        except OSError, e:
50
59
            return False
51
 
        return True
 
60
        return (0 == proc.wait())
52
61
 
53
62
    def feature_name(self):
54
 
        return 'bzrlib._patiencediff_c'
55
 
 
56
 
CompiledPatienceDiffFeature = _CompiledPatienceDiffFeature()
57
 
 
58
 
 
59
 
class _UnicodeFilename(Feature):
60
 
    """Does the filesystem support Unicode filenames?"""
61
 
 
62
 
    def _probe(self):
63
 
        try:
64
 
            os.stat(u'\u03b1')
65
 
        except UnicodeEncodeError:
66
 
            return False
67
 
        except (IOError, OSError):
68
 
            # The filesystem allows the Unicode filename but the file doesn't
69
 
            # exist.
70
 
            return True
71
 
        else:
72
 
            # The filesystem allows the Unicode filename and the file exists,
73
 
            # for some reason.
74
 
            return True
75
 
 
76
 
UnicodeFilename = _UnicodeFilename()
77
 
 
78
 
 
79
 
class TestUnicodeFilename(TestCase):
80
 
 
81
 
    def test_probe_passes(self):
82
 
        """UnicodeFilename._probe passes."""
83
 
        # We can't test much more than that because the behaviour depends
84
 
        # on the platform.
85
 
        UnicodeFilename._probe()
86
 
        
 
63
        return 'attrib Windows command-line tool'
 
64
 
 
65
AttribFeature = _AttribFeature()
 
66
 
 
67
 
 
68
compiled_patiencediff_feature = tests.ModuleAvailableFeature(
 
69
                                    'bzrlib._patiencediff_c')
 
70
 
87
71
 
88
72
def udiff_lines(old, new, allow_binary=False):
89
73
    output = StringIO()
194
178
                              StringIO(), diff_opts=['-u'])
195
179
        finally:
196
180
            os.environ['PATH'] = orig_path
197
 
        
 
181
 
198
182
    def test_internal_diff_default(self):
199
183
        # Default internal diff encoding is utf8
200
184
        output = StringIO()
365
349
+file2 contents at rev 3
366
350
 
367
351
''')
368
 
        
 
352
 
369
353
    def test_diff_add_files(self):
370
 
        tree1 = self.b.repository.revision_tree(None)
 
354
        tree1 = self.b.repository.revision_tree(_mod_revision.NULL_REVISION)
371
355
        tree2 = self.b.repository.revision_tree('rev-1')
372
356
        output = self.get_diff(tree1, tree2)
373
357
        # the files have the epoch time stamp for the tree in which
407
391
        self.wt.rename_one('file1', 'file1b')
408
392
        old_tree = self.b.repository.revision_tree('rev-1')
409
393
        new_tree = self.b.repository.revision_tree('rev-4')
410
 
        out = self.get_diff(old_tree, new_tree, specific_files=['file1b'], 
 
394
        out = self.get_diff(old_tree, new_tree, specific_files=['file1b'],
411
395
                            working_tree=self.wt)
412
396
        self.assertContainsRe(out, 'file1\t')
413
397
 
419
403
        self.wt.rename_one('file1', 'dir1/file1')
420
404
        old_tree = self.b.repository.revision_tree('rev-1')
421
405
        new_tree = self.b.repository.revision_tree('rev-4')
422
 
        out = self.get_diff(old_tree, new_tree, specific_files=['dir1'], 
 
406
        out = self.get_diff(old_tree, new_tree, specific_files=['dir1'],
423
407
                            working_tree=self.wt)
424
408
        self.assertContainsRe(out, 'file1\t')
425
 
        out = self.get_diff(old_tree, new_tree, specific_files=['dir2'], 
 
409
        out = self.get_diff(old_tree, new_tree, specific_files=['dir2'],
426
410
                            working_tree=self.wt)
427
411
        self.assertNotContainsRe(out, 'file1\t')
428
412
 
548
532
        is a binary file in the diff.
549
533
        """
550
534
        # See https://bugs.launchpad.net/bugs/110092.
551
 
        self.requireFeature(UnicodeFilename)
 
535
        self.requireFeature(tests.UnicodeFilenameFeature)
552
536
 
553
537
        # This bug isn't triggered with cStringIO.
554
538
        from StringIO import StringIO
573
557
 
574
558
    def test_unicode_filename(self):
575
559
        """Test when the filename are unicode."""
576
 
        self.requireFeature(UnicodeFilename)
 
560
        self.requireFeature(tests.UnicodeFilenameFeature)
577
561
 
578
562
        alpha, omega = u'\u03b1', u'\u03c9'
579
563
        autf8, outf8 = alpha.encode('utf8'), omega.encode('utf8')
714
698
            r'--- olddir/oldfile.*\n\+\+\+ newdir/newfile.*\n\@\@ -1,1 \+0,0'
715
699
             ' \@\@\n-old\n\n')
716
700
        self.assertContainsRe(self.differ.to_file.getvalue(),
717
 
                              "=== target is 'new'\n")
 
701
                              "=== target is u'new'\n")
718
702
 
719
703
    def test_diff_directory(self):
720
704
        self.build_tree(['new-tree/new-dir/'])
780
764
        self._PatienceSequenceMatcher = \
781
765
            bzrlib._patiencediff_py.PatienceSequenceMatcher_py
782
766
 
 
767
    def test_diff_unicode_string(self):
 
768
        a = ''.join([unichr(i) for i in range(4000, 4500, 3)])
 
769
        b = ''.join([unichr(i) for i in range(4300, 4800, 2)])
 
770
        sm = self._PatienceSequenceMatcher(None, a, b)
 
771
        mb = sm.get_matching_blocks()
 
772
        self.assertEquals(35, len(mb))
 
773
 
783
774
    def test_unique_lcs(self):
784
775
        unique_lcs = self._unique_lcs
785
776
        self.assertEquals(unique_lcs('', ''), [])
790
781
        self.assertEquals(unique_lcs('ab', 'ab'), [(0,0), (1,1)])
791
782
        self.assertEquals(unique_lcs('abcde', 'cdeab'), [(2,0), (3,1), (4,2)])
792
783
        self.assertEquals(unique_lcs('cdeab', 'abcde'), [(0,2), (1,3), (2,4)])
793
 
        self.assertEquals(unique_lcs('abXde', 'abYde'), [(0,0), (1,1), 
 
784
        self.assertEquals(unique_lcs('abXde', 'abYde'), [(0,0), (1,1),
794
785
                                                         (3,3), (4,4)])
795
786
        self.assertEquals(unique_lcs('acbac', 'abc'), [(2,1)])
796
787
 
811
802
        test_one('abcdbce', 'afbcgdbce', [(0,0), (1, 2), (2, 3), (3, 5),
812
803
                                          (4, 6), (5, 7), (6, 8)])
813
804
 
814
 
        # recurse_matches doesn't match non-unique 
 
805
        # recurse_matches doesn't match non-unique
815
806
        # lines surrounded by bogus text.
816
807
        # The update has been done in patiencediff.SequenceMatcher instead
817
808
 
954
945
                 ('delete', 1,2, 1,1),
955
946
                 ('equal',  2,3, 1,2),
956
947
                ])
957
 
        chk_ops('aBccDe', 'abccde', 
 
948
        chk_ops('aBccDe', 'abccde',
958
949
                [('equal',   0,1, 0,1),
959
950
                 ('replace', 1,5, 1,5),
960
951
                 ('equal',   5,6, 5,6),
961
952
                ])
962
 
        chk_ops('aBcDec', 'abcdec', 
 
953
        chk_ops('aBcDec', 'abcdec',
963
954
                [('equal',   0,1, 0,1),
964
955
                 ('replace', 1,2, 1,2),
965
956
                 ('equal',   2,3, 2,3),
966
957
                 ('replace', 3,4, 3,4),
967
958
                 ('equal',   4,6, 4,6),
968
959
                ])
969
 
        chk_ops('aBcdEcdFg', 'abcdecdfg', 
 
960
        chk_ops('aBcdEcdFg', 'abcdecdfg',
970
961
                [('equal',   0,1, 0,1),
971
962
                 ('replace', 1,8, 1,8),
972
963
                 ('equal',   8,9, 8,9)
973
964
                ])
974
 
        chk_ops('aBcdEeXcdFg', 'abcdecdfg', 
 
965
        chk_ops('aBcdEeXcdFg', 'abcdecdfg',
975
966
                [('equal',   0,1, 0,1),
976
967
                 ('replace', 1,2, 1,2),
977
968
                 ('equal',   2,4, 2,4),
1037
1028
    """
1038
1029
    gnxrf_netf = ['svyr*']
1039
1030
    gnxrf_bcgvbaf = ['ab-erphefr']
1040
 
  
 
1031
 
1041
1032
    qrs eha(frys, svyr_yvfg, ab_erphefr=Snyfr):
1042
1033
        sebz omeyvo.nqq vzcbeg fzneg_nqq, nqq_ercbegre_cevag, nqq_ercbegre_ahyy
1043
1034
        vs vf_dhvrg():
1051
1042
'''.splitlines(True), '''\
1052
1043
    trg nqqrq jura lbh nqq n svyr va gur qverpgbel.
1053
1044
 
1054
 
    --qel-eha jvyy fubj juvpu svyrf jbhyq or nqqrq, ohg abg npghnyyl 
 
1045
    --qel-eha jvyy fubj juvpu svyrf jbhyq or nqqrq, ohg abg npghnyyl
1055
1046
    nqq gurz.
1056
1047
    """
1057
1048
    gnxrf_netf = ['svyr*']
1086
1077
                 'how are you today?\n']
1087
1078
        unified_diff = bzrlib.patiencediff.unified_diff
1088
1079
        psm = self._PatienceSequenceMatcher
1089
 
        self.assertEquals([ '---  \n',
1090
 
                           '+++  \n',
 
1080
        self.assertEquals(['--- \n',
 
1081
                           '+++ \n',
1091
1082
                           '@@ -1,3 +1,2 @@\n',
1092
1083
                           ' hello there\n',
1093
1084
                           '-world\n',
1098
1089
        txt_a = map(lambda x: x+'\n', 'abcdefghijklmnop')
1099
1090
        txt_b = map(lambda x: x+'\n', 'abcdefxydefghijklmnop')
1100
1091
        # This is the result with LongestCommonSubstring matching
1101
 
        self.assertEquals(['---  \n',
1102
 
                           '+++  \n',
 
1092
        self.assertEquals(['--- \n',
 
1093
                           '+++ \n',
1103
1094
                           '@@ -1,6 +1,11 @@\n',
1104
1095
                           ' a\n',
1105
1096
                           ' b\n',
1114
1105
                           ' f\n']
1115
1106
                          , list(unified_diff(txt_a, txt_b)))
1116
1107
        # And the patience diff
1117
 
        self.assertEquals(['---  \n',
1118
 
                           '+++  \n',
 
1108
        self.assertEquals(['--- \n',
 
1109
                           '+++ \n',
1119
1110
                           '@@ -4,6 +4,11 @@\n',
1120
1111
                           ' d\n',
1121
1112
                           ' e\n',
1132
1123
                          , list(unified_diff(txt_a, txt_b,
1133
1124
                                 sequencematcher=psm)))
1134
1125
 
 
1126
    def test_patience_unified_diff_with_dates(self):
 
1127
        txt_a = ['hello there\n',
 
1128
                 'world\n',
 
1129
                 'how are you today?\n']
 
1130
        txt_b = ['hello there\n',
 
1131
                 'how are you today?\n']
 
1132
        unified_diff = bzrlib.patiencediff.unified_diff
 
1133
        psm = self._PatienceSequenceMatcher
 
1134
        self.assertEquals(['--- a\t2008-08-08\n',
 
1135
                           '+++ b\t2008-09-09\n',
 
1136
                           '@@ -1,3 +1,2 @@\n',
 
1137
                           ' hello there\n',
 
1138
                           '-world\n',
 
1139
                           ' how are you today?\n'
 
1140
                          ]
 
1141
                          , list(unified_diff(txt_a, txt_b,
 
1142
                                 fromfile='a', tofile='b',
 
1143
                                 fromfiledate='2008-08-08',
 
1144
                                 tofiledate='2008-09-09',
 
1145
                                 sequencematcher=psm)))
 
1146
 
1135
1147
 
1136
1148
class TestPatienceDiffLib_c(TestPatienceDiffLib):
1137
1149
 
1138
 
    _test_needs_features = [CompiledPatienceDiffFeature]
 
1150
    _test_needs_features = [compiled_patiencediff_feature]
1139
1151
 
1140
1152
    def setUp(self):
1141
1153
        super(TestPatienceDiffLib_c, self).setUp()
1177
1189
 
1178
1190
        unified_diff_files = bzrlib.patiencediff.unified_diff_files
1179
1191
        psm = self._PatienceSequenceMatcher
1180
 
        self.assertEquals(['--- a1 \n',
1181
 
                           '+++ b1 \n',
 
1192
        self.assertEquals(['--- a1\n',
 
1193
                           '+++ b1\n',
1182
1194
                           '@@ -1,3 +1,2 @@\n',
1183
1195
                           ' hello there\n',
1184
1196
                           '-world\n',
1193
1205
        open('b2', 'wb').writelines(txt_b)
1194
1206
 
1195
1207
        # This is the result with LongestCommonSubstring matching
1196
 
        self.assertEquals(['--- a2 \n',
1197
 
                           '+++ b2 \n',
 
1208
        self.assertEquals(['--- a2\n',
 
1209
                           '+++ b2\n',
1198
1210
                           '@@ -1,6 +1,11 @@\n',
1199
1211
                           ' a\n',
1200
1212
                           ' b\n',
1210
1222
                          , list(unified_diff_files('a2', 'b2')))
1211
1223
 
1212
1224
        # And the patience diff
1213
 
        self.assertEquals(['--- a2 \n',
1214
 
                           '+++ b2 \n',
 
1225
        self.assertEquals(['--- a2\n',
 
1226
                           '+++ b2\n',
1215
1227
                           '@@ -4,6 +4,11 @@\n',
1216
1228
                           ' d\n',
1217
1229
                           ' e\n',
1231
1243
 
1232
1244
class TestPatienceDiffLibFiles_c(TestPatienceDiffLibFiles):
1233
1245
 
1234
 
    _test_needs_features = [CompiledPatienceDiffFeature]
 
1246
    _test_needs_features = [compiled_patiencediff_feature]
1235
1247
 
1236
1248
    def setUp(self):
1237
1249
        super(TestPatienceDiffLibFiles_c, self).setUp()
1243
1255
class TestUsingCompiledIfAvailable(TestCase):
1244
1256
 
1245
1257
    def test_PatienceSequenceMatcher(self):
1246
 
        if CompiledPatienceDiffFeature.available():
 
1258
        if compiled_patiencediff_feature.available():
1247
1259
            from bzrlib._patiencediff_c import PatienceSequenceMatcher_c
1248
1260
            self.assertIs(PatienceSequenceMatcher_c,
1249
1261
                          bzrlib.patiencediff.PatienceSequenceMatcher)
1253
1265
                          bzrlib.patiencediff.PatienceSequenceMatcher)
1254
1266
 
1255
1267
    def test_unique_lcs(self):
1256
 
        if CompiledPatienceDiffFeature.available():
 
1268
        if compiled_patiencediff_feature.available():
1257
1269
            from bzrlib._patiencediff_c import unique_lcs_c
1258
1270
            self.assertIs(unique_lcs_c,
1259
1271
                          bzrlib.patiencediff.unique_lcs)
1263
1275
                          bzrlib.patiencediff.unique_lcs)
1264
1276
 
1265
1277
    def test_recurse_matches(self):
1266
 
        if CompiledPatienceDiffFeature.available():
 
1278
        if compiled_patiencediff_feature.available():
1267
1279
            from bzrlib._patiencediff_c import recurse_matches_c
1268
1280
            self.assertIs(recurse_matches_c,
1269
1281
                          bzrlib.patiencediff.recurse_matches)
1278
1290
    def test_from_string(self):
1279
1291
        diff_obj = DiffFromTool.from_string('diff', None, None, None)
1280
1292
        self.addCleanup(diff_obj.finish)
1281
 
        self.assertEqual(['diff', '%(old_path)s', '%(new_path)s'],
 
1293
        self.assertEqual(['diff', '@old_path', '@new_path'],
1282
1294
            diff_obj.command_template)
1283
1295
 
1284
1296
    def test_from_string_u5(self):
1285
 
        diff_obj = DiffFromTool.from_string('diff -u\\ 5', None, None, None)
 
1297
        diff_obj = DiffFromTool.from_string('diff "-u 5"', None, None, None)
1286
1298
        self.addCleanup(diff_obj.finish)
1287
 
        self.assertEqual(['diff', '-u 5', '%(old_path)s', '%(new_path)s'],
 
1299
        self.assertEqual(['diff', '-u 5', '@old_path', '@new_path'],
1288
1300
                         diff_obj.command_template)
1289
1301
        self.assertEqual(['diff', '-u 5', 'old-path', 'new-path'],
1290
1302
                         diff_obj._get_command('old-path', 'new-path'))
 
1303
        
 
1304
    def test_from_string_path_with_backslashes(self):
 
1305
        self.requireFeature(BackslashDirSeparatorFeature)
 
1306
        tool = 'C:\\Tools\\Diff.exe'
 
1307
        diff_obj = DiffFromTool.from_string(tool, None, None, None)
 
1308
        self.addCleanup(diff_obj.finish)
 
1309
        self.assertEqual(['C:\\Tools\\Diff.exe', '@old_path', '@new_path'],
 
1310
                         diff_obj.command_template)
 
1311
        self.assertEqual(['C:\\Tools\\Diff.exe', 'old-path', 'new-path'],
 
1312
                         diff_obj._get_command('old-path', 'new-path'))
1291
1313
 
1292
1314
    def test_execute(self):
1293
1315
        output = StringIO()
1294
1316
        diff_obj = DiffFromTool(['python', '-c',
1295
 
                                 'print "%(old_path)s %(new_path)s"'],
 
1317
                                 'print "@old_path @new_path"'],
1296
1318
                                None, None, output)
1297
1319
        self.addCleanup(diff_obj.finish)
1298
1320
        diff_obj._execute('old', 'new')
1307
1329
        self.assertEqual('a-tool-which-is-unlikely-to-exist could not be found'
1308
1330
                         ' on this machine', str(e))
1309
1331
 
 
1332
    def test_prepare_files_creates_paths_readable_by_windows_tool(self):
 
1333
        self.requireFeature(AttribFeature)
 
1334
        output = StringIO()
 
1335
        tree = self.make_branch_and_tree('tree')
 
1336
        self.build_tree_contents([('tree/file', 'content')])
 
1337
        tree.add('file', 'file-id')
 
1338
        tree.commit('old tree')
 
1339
        tree.lock_read()
 
1340
        self.addCleanup(tree.unlock)
 
1341
        basis_tree = tree.basis_tree()
 
1342
        basis_tree.lock_read()
 
1343
        self.addCleanup(basis_tree.unlock)
 
1344
        diff_obj = DiffFromTool(['python', '-c',
 
1345
                                 'print "@old_path @new_path"'],
 
1346
                                basis_tree, tree, output)
 
1347
        diff_obj._prepare_files('file-id', 'file', 'file')
 
1348
        # The old content should be readonly
 
1349
        self.assertReadableByAttrib(diff_obj._root, 'old\\file',
 
1350
                                    r'R.*old\\file$')
 
1351
        # The new content should use the tree object, not a 'new' file anymore
 
1352
        self.assertEndsWith(tree.basedir, 'work/tree')
 
1353
        self.assertReadableByAttrib(tree.basedir, 'file', r'work\\tree\\file$')
 
1354
 
 
1355
    def assertReadableByAttrib(self, cwd, relpath, regex):
 
1356
        proc = subprocess.Popen(['attrib', relpath],
 
1357
                                stdout=subprocess.PIPE,
 
1358
                                cwd=cwd)
 
1359
        (result, err) = proc.communicate()
 
1360
        self.assertContainsRe(result.replace('\r\n', '\n'), regex)
 
1361
 
1310
1362
    def test_prepare_files(self):
1311
1363
        output = StringIO()
1312
1364
        tree = self.make_branch_and_tree('tree')
1313
1365
        self.build_tree_contents([('tree/oldname', 'oldcontent')])
 
1366
        self.build_tree_contents([('tree/oldname2', 'oldcontent2')])
1314
1367
        tree.add('oldname', 'file-id')
 
1368
        tree.add('oldname2', 'file2-id')
1315
1369
        tree.commit('old tree', timestamp=0)
1316
1370
        tree.rename_one('oldname', 'newname')
 
1371
        tree.rename_one('oldname2', 'newname2')
1317
1372
        self.build_tree_contents([('tree/newname', 'newcontent')])
 
1373
        self.build_tree_contents([('tree/newname2', 'newcontent2')])
1318
1374
        old_tree = tree.basis_tree()
1319
1375
        old_tree.lock_read()
1320
1376
        self.addCleanup(old_tree.unlock)
1321
1377
        tree.lock_read()
1322
1378
        self.addCleanup(tree.unlock)
1323
1379
        diff_obj = DiffFromTool(['python', '-c',
1324
 
                                 'print "%(old_path)s %(new_path)s"'],
 
1380
                                 'print "@old_path @new_path"'],
1325
1381
                                old_tree, tree, output)
1326
1382
        self.addCleanup(diff_obj.finish)
1327
1383
        self.assertContainsRe(diff_obj._root, 'bzr-diff-[^/]*')
1329
1385
                                                     'newname')
1330
1386
        self.assertContainsRe(old_path, 'old/oldname$')
1331
1387
        self.assertEqual(0, os.stat(old_path).st_mtime)
1332
 
        self.assertContainsRe(new_path, 'new/newname$')
 
1388
        self.assertContainsRe(new_path, 'tree/newname$')
1333
1389
        self.assertFileEqual('oldcontent', old_path)
1334
1390
        self.assertFileEqual('newcontent', new_path)
1335
 
        if osutils.has_symlinks():
 
1391
        if osutils.host_os_dereferences_symlinks():
1336
1392
            self.assertTrue(os.path.samefile('tree/newname', new_path))
1337
1393
        # make sure we can create files with the same parent directories
1338
 
        diff_obj._prepare_files('file-id', 'oldname2', 'newname2')
 
1394
        diff_obj._prepare_files('file2-id', 'oldname2', 'newname2')
 
1395
 
 
1396
 
 
1397
class TestGetTreesAndBranchesToDiff(TestCaseWithTransport):
 
1398
 
 
1399
    def test_basic(self):
 
1400
        tree = self.make_branch_and_tree('tree')
 
1401
        (old_tree, new_tree,
 
1402
         old_branch, new_branch,
 
1403
         specific_files, extra_trees) = \
 
1404
            get_trees_and_branches_to_diff(['tree'], None, None, None)
 
1405
 
 
1406
        self.assertIsInstance(old_tree, RevisionTree)
 
1407
        #print dir (old_tree)
 
1408
        self.assertEqual(_mod_revision.NULL_REVISION, old_tree.get_revision_id())
 
1409
        self.assertEqual(tree.basedir, new_tree.basedir)
 
1410
        self.assertEqual(tree.branch.base, old_branch.base)
 
1411
        self.assertEqual(tree.branch.base, new_branch.base)
 
1412
        self.assertIs(None, specific_files)
 
1413
        self.assertIs(None, extra_trees)
 
1414
 
 
1415
    def test_with_rev_specs(self):
 
1416
        tree = self.make_branch_and_tree('tree')
 
1417
        self.build_tree_contents([('tree/file', 'oldcontent')])
 
1418
        tree.add('file', 'file-id')
 
1419
        tree.commit('old tree', timestamp=0, rev_id="old-id")
 
1420
        self.build_tree_contents([('tree/file', 'newcontent')])
 
1421
        tree.commit('new tree', timestamp=0, rev_id="new-id")
 
1422
 
 
1423
        revisions = [RevisionSpec.from_string('1'),
 
1424
                     RevisionSpec.from_string('2')]
 
1425
        (old_tree, new_tree,
 
1426
         old_branch, new_branch,
 
1427
         specific_files, extra_trees) = \
 
1428
            get_trees_and_branches_to_diff(['tree'], revisions, None, None)
 
1429
 
 
1430
        self.assertIsInstance(old_tree, RevisionTree)
 
1431
        self.assertEqual("old-id", old_tree.get_revision_id())
 
1432
        self.assertIsInstance(new_tree, RevisionTree)
 
1433
        self.assertEqual("new-id", new_tree.get_revision_id())
 
1434
        self.assertEqual(tree.branch.base, old_branch.base)
 
1435
        self.assertEqual(tree.branch.base, new_branch.base)
 
1436
        self.assertIs(None, specific_files)
 
1437
        self.assertEqual(tree.basedir, extra_trees[0].basedir)