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"""
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()
177
branch2_tree = branch1_tree.controldir.sprout('branch2').open_workingtree()
179
178
self.build_tree_contents([('branch2/file', b'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
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')
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")
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",
362
328
class TestCheckoutDiff(TestDiff):
426
392
'diff -Oprogress_bar=none -r 1 --diff-options -ub',
427
393
universal_newlines=True,
429
if b'Diff is not installed on this machine' in err:
395
if 'Diff is not installed on this machine' in err:
430
396
raise tests.TestSkipped("No external 'diff' is available")
431
self.assertEqual(b'', err)
397
self.assertEqual('', err)
432
398
# We have to skip the stuff in the middle, because it depends
434
400
self.assertStartsWith(
436
b"=== added file 'goodbye'\n"
437
b"--- old/goodbye\t1970-01-01 00:00:00 +0000\n"
438
b"+++ new/goodbye\t")
439
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"
442
408
def test_external_diff_options_and_using(self):
443
409
"""Test that the options are passed correctly to an external diff process"""
445
411
self.make_example_branch()
446
412
self.build_tree_contents([('hello', b'Foo\n')])
447
413
out, err = self.run_bzr('diff --diff-options -i --using diff',
449
415
self.assertEqual("=== modified file 'hello'\n", out)
450
416
self.assertEqual('', err)
457
423
self.make_example_branch()
458
424
self.build_tree_contents([('hello', b'hello world!\n')])
459
425
output = self.run_bzr_subprocess('diff', retcode=1)[0]
460
self.assertTrue(b'\n+hello world!\n' in output)
426
self.assertTrue('\n+hello world!\n' in output)