76
76
def test_diff_prefix(self):
77
77
"""diff --prefix appends to filenames in output"""
78
78
self.make_example_branch()
79
self.build_tree_contents([('hello', b'hello world!\n')])
79
self.build_tree_contents([('hello', 'hello world!\n')])
80
80
out, err = self.run_bzr('diff --prefix old/:new/', retcode=1)
81
81
self.assertEqual(err, '')
82
82
self.assertEqualDiff(subst_dates(out), '''\
93
93
# There was an error in error reporting for this option
94
94
out, err = self.run_bzr('diff --prefix old/', retcode=3)
95
95
self.assertContainsRe(err,
96
'--prefix expects two values separated by a colon')
96
'--prefix expects two values separated by a colon')
98
98
def test_diff_p1(self):
99
99
"""diff -p1 produces lkml-style diffs"""
100
100
self.make_example_branch()
101
self.build_tree_contents([('hello', b'hello world!\n')])
101
self.build_tree_contents([('hello', 'hello world!\n')])
102
102
out, err = self.run_bzr('diff -p1', retcode=1)
103
103
self.assertEqual(err, '')
104
104
self.assertEqualDiff(subst_dates(out), '''\
114
114
def test_diff_p0(self):
115
115
"""diff -p0 produces diffs with no prefix"""
116
116
self.make_example_branch()
117
self.build_tree_contents([('hello', b'hello world!\n')])
117
self.build_tree_contents([('hello', 'hello world!\n')])
118
118
out, err = self.run_bzr('diff -p0', retcode=1)
119
119
self.assertEqual(err, '')
120
120
self.assertEqualDiff(subst_dates(out), '''\
133
133
self.make_example_branch()
134
134
out, err = self.run_bzr('diff does-not-exist', retcode=3,
135
error_regexes=('not versioned.*does-not-exist',))
135
error_regexes=('not versioned.*does-not-exist',))
137
137
def test_diff_illegal_revision_specifiers(self):
138
138
out, err = self.run_bzr('diff -r 1..23..123', retcode=3,
139
error_regexes=('one or two revision specifiers',))
139
error_regexes=('one or two revision specifiers',))
141
141
def test_diff_using_and_format(self):
142
142
out, err = self.run_bzr('diff --format=default --using=mydi', retcode=3,
143
error_regexes=('are mutually exclusive',))
143
error_regexes=('are mutually exclusive',))
145
145
def test_diff_nonexistent_revision(self):
146
146
out, err = self.run_bzr('diff -r 123', retcode=3,
147
error_regexes=("Requested revision: '123' does not "
148
"exist in branch:",))
147
error_regexes=("Requested revision: '123' does not "
148
"exist in branch:",))
150
150
def test_diff_nonexistent_dotted_revision(self):
151
151
out, err = self.run_bzr('diff -r 1.1', retcode=3)
152
152
self.assertContainsRe(err,
153
"Requested revision: '1.1' does not exist in branch:")
153
"Requested revision: '1.1' does not exist in branch:")
155
155
def test_diff_nonexistent_dotted_revision_change(self):
156
156
out, err = self.run_bzr('diff -c 1.1', retcode=3)
157
157
self.assertContainsRe(err,
158
"Requested revision: '1.1' does not exist in branch:")
158
"Requested revision: '1.1' does not exist in branch:")
160
160
def test_diff_unversioned(self):
161
161
# Get an error when diffing a non-versioned file.
174
174
branch1_tree.add('file')
175
175
branch1_tree.add('file2')
176
176
branch1_tree.commit(message='add file and file2')
177
branch2_tree = branch1_tree.controldir.sprout(
178
'branch2').open_workingtree()
179
self.build_tree_contents([('branch2/file', b'new content\n')])
177
branch2_tree = branch1_tree.controldir.sprout('branch2').open_workingtree()
178
self.build_tree_contents([('branch2/file', 'new content\n')])
180
179
branch2_tree.commit(message='update file')
181
180
return branch1_tree, branch2_tree
185
184
out, err = self.run_bzr(cmd, retcode=1)
186
185
self.assertEqual('', err)
187
186
self.assertEqual("=== modified file 'file'\n"
188
"--- old/file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
189
"+++ new/file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
192
"+contents of branch1/file\n"
193
"\n", subst_dates(out))
187
"--- old/file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
188
"+++ new/file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
191
"+contents of branch1/file\n"
192
"\n", subst_dates(out))
195
194
def check_b1_vs_b2(self, cmd):
196
195
# Compare branch1 vs branch2 using cmd and check the result
197
196
out, err = self.run_bzr(cmd, retcode=1)
198
197
self.assertEqual('', err)
199
198
self.assertEqualDiff("=== modified file 'file'\n"
200
"--- old/file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
201
"+++ new/file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
203
"-contents of branch1/file\n"
205
"\n", subst_dates(out))
199
"--- old/file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
200
"+++ new/file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
202
"-contents of branch1/file\n"
204
"\n", subst_dates(out))
207
206
def check_no_diffs(self, cmd):
208
207
# Check that running cmd returns an empty diff
251
250
def test_diff_revno_branches(self):
252
251
self.example_branches()
253
252
branch2_tree = workingtree.WorkingTree.open_containing('branch2')[0]
254
self.build_tree_contents([('branch2/file', b'even newer content')])
253
self.build_tree_contents([('branch2/file', 'even newer content')])
255
254
branch2_tree.commit(message='update file once more')
257
256
out, err = self.run_bzr('diff -r revno:1:branch2..revno:1:branch1',
263
262
self.assertEqual('', err)
264
263
self.assertEqualDiff("=== modified file 'file'\n"
265
"--- old/file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
266
"+++ new/file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
269
"+contents of branch1/file\n"
270
"\n", subst_dates(out))
272
def test_diff_color_always(self):
273
from ...terminal import colorstring
274
from ... import colordiff
275
self.overrideAttr(colordiff, 'GLOBAL_COLORDIFFRC', None)
276
self.example_branches()
277
branch2_tree = workingtree.WorkingTree.open_containing('branch2')[0]
278
self.build_tree_contents([('branch2/file', b'even newer content')])
279
branch2_tree.commit(message='update file once more')
281
out, err = self.run_bzr('diff --color=always -r revno:2:branch2..revno:1:branch1',
283
self.assertEqual('', err)
284
self.assertEqualDiff((
285
colorstring(b"=== modified file 'file'\n", 'darkyellow') +
286
colorstring(b"--- old/file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n", 'darkred') +
287
colorstring(b"+++ new/file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n", 'darkblue') +
288
colorstring(b"@@ -1 +1 @@\n", 'darkgreen') +
289
colorstring(b"-new content\n", 'darkred') +
290
colorstring(b"+contents of branch1/file\n", 'darkblue') +
291
colorstring(b"\n", 'darkwhite')).decode(),
264
"--- old/file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
265
"+++ new/file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
268
"+contents of branch1/file\n"
269
"\n", subst_dates(out))
294
271
def example_branch2(self):
295
272
branch1_tree = self.make_branch_and_tree('branch1')
296
self.build_tree_contents([('branch1/file1', b'original line\n')])
273
self.build_tree_contents([('branch1/file1', 'original line\n')])
297
274
branch1_tree.add('file1')
298
275
branch1_tree.commit(message='first commit')
299
self.build_tree_contents([('branch1/file1', b'repo line\n')])
276
self.build_tree_contents([('branch1/file1', 'repo line\n')])
300
277
branch1_tree.commit(message='second commit')
301
278
return branch1_tree
303
280
def test_diff_to_working_tree(self):
304
281
self.example_branch2()
305
self.build_tree_contents([('branch1/file1', b'new line')])
282
self.build_tree_contents([('branch1/file1', 'new line')])
306
283
output = self.run_bzr('diff -r 1.. branch1', retcode=1)
307
284
self.assertContainsRe(output[0], '\n\\-original line\n\\+new line\n')
309
286
def test_diff_to_working_tree_in_subdir(self):
310
287
self.example_branch2()
311
self.build_tree_contents([('branch1/file1', b'new line')])
288
self.build_tree_contents([('branch1/file1', 'new line')])
312
289
os.mkdir('branch1/dir1')
313
290
output = self.run_bzr('diff -r 1..', retcode=1,
314
291
working_dir='branch1/dir1')
336
313
def show_diff(self, specific_files, extra_trees=None):
337
314
self.to_file.write("BOO!\n")
338
315
return super(BooDiffTree, self).show_diff(specific_files,
341
318
diff_format_registry.register("boo", BooDiffTree, "Scary diff format")
342
319
self.addCleanup(diff_format_registry.remove, "boo")
343
320
self.make_example_branch()
344
self.build_tree_contents([('hello', b'hello world!\n')])
321
self.build_tree_contents([('hello', 'hello world!\n')])
345
322
output = self.run_bzr('diff --format=boo', retcode=1)
346
323
self.assertTrue("BOO!" in output[0])
347
324
output = self.run_bzr('diff -Fboo', retcode=1)
348
325
self.assertTrue("BOO!" in output[0])
350
def test_binary_diff_remove(self):
351
tree = self.make_branch_and_tree('.')
352
self.build_tree_contents([('a', b'\x00' * 20)])
354
tree.commit('add binary file')
356
output = self.run_bzr('diff', retcode=1)
358
"=== removed file 'a'\nBinary files old/a and new/a differ\n",
361
def test_moved_away(self):
363
tree = self.make_branch_and_tree('.')
364
self.build_tree_contents([('a', 'asdf\n')])
367
tree.rename_one('a', 'b')
368
self.build_tree_contents([('a', 'qwer\n')])
370
output, error = self.run_bzr('diff -p0', retcode=1)
371
self.assertEqualDiff("""\
373
--- a\tYYYY-MM-DD HH:MM:SS +ZZZZ
374
+++ a\tYYYY-MM-DD HH:MM:SS +ZZZZ
378
=== renamed file 'a' => 'b'
379
""", subst_dates(output))
382
328
class TestCheckoutDiff(TestDiff):
415
361
def test_diff_label_added(self):
416
362
tree = super(TestDiffLabels, self).make_example_branch()
417
self.build_tree_contents([('barbar', b'barbar')])
363
self.build_tree_contents([('barbar', 'barbar')])
418
364
tree.add('barbar')
419
365
diff = self.run_bzr('diff', retcode=1)
420
366
self.assertTrue("=== added file 'barbar'" in diff[0])
422
368
def test_diff_label_modified(self):
423
369
super(TestDiffLabels, self).make_example_branch()
424
self.build_tree_contents([('hello', b'barbar')])
370
self.build_tree_contents([('hello', 'barbar')])
425
371
diff = self.run_bzr('diff', retcode=1)
426
372
self.assertTrue("=== modified file 'hello'" in diff[0])
446
392
'diff -Oprogress_bar=none -r 1 --diff-options -ub',
447
393
universal_newlines=True,
449
if b'Diff is not installed on this machine' in err:
395
if 'Diff is not installed on this machine' in err:
450
396
raise tests.TestSkipped("No external 'diff' is available")
451
self.assertEqual(b'', err)
397
self.assertEqual('', err)
452
398
# We have to skip the stuff in the middle, because it depends
454
400
self.assertStartsWith(
456
b"=== added file 'goodbye'\n"
457
b"--- old/goodbye\t1970-01-01 00:00:00 +0000\n"
458
b"+++ new/goodbye\t")
459
self.assertEndsWith(out, b"\n@@ -0,0 +1 @@\n"
402
"=== added file 'goodbye'\n"
403
"--- old/goodbye\t1970-01-01 00:00:00 +0000\n"
405
self.assertEndsWith(out, "\n@@ -0,0 +1 @@\n"
462
408
def test_external_diff_options_and_using(self):
463
409
"""Test that the options are passed correctly to an external diff process"""
464
410
self.requireFeature(features.diff_feature)
465
411
self.make_example_branch()
466
self.build_tree_contents([('hello', b'Foo\n')])
412
self.build_tree_contents([('hello', 'Foo\n')])
467
413
out, err = self.run_bzr('diff --diff-options -i --using diff',
469
415
self.assertEqual("=== modified file 'hello'\n", out)
470
416
self.assertEqual('', err)
475
421
def test_diff_output(self):
476
422
# check that output doesn't mangle line-endings
477
423
self.make_example_branch()
478
self.build_tree_contents([('hello', b'hello world!\n')])
424
self.build_tree_contents([('hello', 'hello world!\n')])
479
425
output = self.run_bzr_subprocess('diff', retcode=1)[0]
480
self.assertTrue(b'\n+hello world!\n' in output)
426
self.assertTrue('\n+hello world!\n' in output)