34
34
'YYYY-MM-DD HH:MM:SS +ZZZZ', string)
37
class TestDiff(ExternalBase):
37
class DiffBase(ExternalBase):
38
"""Base class with common setup method"""
39
40
def make_example_branch(self):
40
# FIXME: copied from test_too_much -- share elsewhere?
41
41
tree = self.make_branch_and_tree('.')
42
open('hello', 'wb').write('foo\n')
42
self.build_tree_contents([
44
('goodbye', 'baz\n')])
43
45
tree.add(['hello'])
44
46
tree.commit('setup')
45
open('goodbye', 'wb').write('baz\n')
46
47
tree.add(['goodbye'])
47
48
tree.commit('setup')
52
class TestDiff(DiffBase):
49
54
def test_diff(self):
50
self.make_example_branch()
51
file('hello', 'wt').write('hello world!')
52
self.runbzr('commit -m fixing hello')
53
output = self.runbzr('diff -r 2..3', backtick=1, retcode=1)
54
self.assert_('\n+hello world!' in output)
55
output = self.runbzr('diff -r last:3..last:1', backtick=1, retcode=1)
56
self.assert_('\n+baz' in output)
57
file('moo', 'wb').write('moo')
58
self.runbzr('add moo')
55
tree = self.make_example_branch()
56
self.build_tree_contents([('hello', 'hello world!')])
57
tree.commit(message='fixing hello')
58
output = self.run_bzr('diff -r 2..3', retcode=1)[0]
59
self.assert_('\n+hello world!' in output)
60
output = self.run_bzr('diff -c 3', retcode=1)[0]
61
self.assert_('\n+hello world!' in output)
62
output = self.run_bzr('diff -r last:3..last:1', retcode=1)[0]
63
self.assert_('\n+baz' in output)
64
output = self.run_bzr('diff -c last:2', retcode=1)[0]
65
self.assert_('\n+baz' in output)
66
self.build_tree(['moo'])
62
71
def test_diff_prefix(self):
63
72
"""diff --prefix appends to filenames in output"""
64
73
self.make_example_branch()
65
file('hello', 'wb').write('hello world!\n')
66
out, err = self.runbzr('diff --prefix old/:new/', retcode=1)
74
self.build_tree_contents([('hello', 'hello world!\n')])
75
out, err = self.run_bzr('diff --prefix old/:new/', retcode=1)
67
76
self.assertEquals(err, '')
68
77
self.assertEqualDiff(subst_dates(out), '''\
69
78
=== modified file 'hello'
111
126
# Get an error from a file that does not exist at all
113
128
self.make_example_branch()
114
out, err = self.runbzr('diff does-not-exist', retcode=3)
129
out, err = self.run_bzr('diff does-not-exist', retcode=3)
115
130
self.assertContainsRe(err, 'not versioned.*does-not-exist')
132
def test_diff_illegal_revision_specifiers(self):
133
out, err = self.run_bzr('diff -r 1..23..123', retcode=3)
134
self.assertContainsRe(err, 'one or two revision specifiers')
117
136
def test_diff_unversioned(self):
118
137
# Get an error when diffing a non-versioned file.
120
139
self.make_example_branch()
121
140
self.build_tree(['unversioned-file'])
122
out, err = self.runbzr('diff unversioned-file', retcode=3)
141
out, err = self.run_bzr('diff unversioned-file', retcode=3)
123
142
self.assertContainsRe(err, 'not versioned.*unversioned-file')
125
144
# TODO: What should diff say for a file deleted in working tree?
127
146
def example_branches(self):
128
self.build_tree(['branch1/', 'branch1/file'], line_endings='binary')
129
self.capture('init branch1')
130
self.capture('add branch1/file')
131
self.run_bzr_captured(['commit', '-m', 'add file', 'branch1'])
132
self.capture('branch branch1 branch2')
133
print >> open('branch2/file', 'wb'), 'new content'
134
self.run_bzr_captured(['commit', '-m', 'update file', 'branch2'])
147
branch1_tree = self.make_branch_and_tree('branch1')
148
self.build_tree(['branch1/file'], line_endings='binary')
149
branch1_tree.add('file')
150
branch1_tree.commit(message='add file')
151
branch2_tree = branch1_tree.bzrdir.sprout('branch2').open_workingtree()
152
self.build_tree_contents([('branch2/file', 'new content\n')])
153
branch2_tree.commit(message='update file')
154
return branch1_tree, branch2_tree
136
156
def test_diff_branches(self):
137
157
self.example_branches()
138
158
# should open branch1 and diff against branch2,
139
out, err = self.run_bzr_captured(['diff', '-r', 'branch:branch2',
159
out, err = self.run_bzr('diff -r branch:branch2 branch1',
142
161
self.assertEquals('', err)
143
162
self.assertEquals("=== modified file 'file'\n"
144
163
"--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
161
180
def test_diff_revno_branches(self):
162
181
self.example_branches()
163
print >> open('branch2/file', 'wb'), 'even newer content'
164
self.run_bzr_captured(['commit', '-m',
165
'update file once more', 'branch2'])
182
branch2_tree = workingtree.WorkingTree.open_containing('branch2')[0]
183
self.build_tree_contents([('branch2/file', 'even newer content')])
184
branch2_tree.commit(message='update file once more')
167
out, err = self.run_bzr_captured(['diff', '-r',
168
'revno:1:branch2..revno:1:branch1'],
186
out, err = self.run_bzr('diff -r revno:1:branch2..revno:1:branch1',
170
188
self.assertEquals('', err)
171
189
self.assertEquals('', out)
172
out, err = self.run_bzr_captured(['diff', '-r',
173
'revno:2:branch2..revno:1:branch1'],
190
out, err = self.run_bzr('diff -r revno:2:branch2..revno:1:branch1',
175
192
self.assertEquals('', err)
176
193
self.assertEqualDiff("=== modified file 'file'\n"
177
194
"--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
182
199
"\n", subst_dates(out))
184
201
def example_branch2(self):
185
self.build_tree(['branch1/', 'branch1/file1'], line_endings='binary')
186
self.capture('init branch1')
187
self.capture('add branch1/file1')
188
print >> open('branch1/file1', 'wb'), 'original line'
189
self.run_bzr_captured(['commit', '-m', 'first commit', 'branch1'])
191
print >> open('branch1/file1', 'wb'), 'repo line'
192
self.run_bzr_captured(['commit', '-m', 'second commit', 'branch1'])
202
branch1_tree = self.make_branch_and_tree('branch1')
203
self.build_tree_contents([('branch1/file1', 'original line\n')])
204
branch1_tree.add('file1')
205
branch1_tree.commit(message='first commit')
206
self.build_tree_contents([('branch1/file1', 'repo line\n')])
207
branch1_tree.commit(message='second commit')
194
210
def test_diff_to_working_tree(self):
195
211
self.example_branch2()
197
print >> open('branch1/file1', 'wb'), 'new line'
198
output = self.run_bzr_captured(['diff', '-r', '1..', 'branch1'],
200
self.assertTrue('\n-original line\n+new line\n' in output[0])
212
self.build_tree_contents([('branch1/file1', 'new line')])
213
output = self.run_bzr('diff -r 1.. branch1', retcode=1)
214
self.assertContainsRe(output[0], '\n\\-original line\n\\+new line\n')
202
216
def test_diff_across_rename(self):
203
217
"""The working tree path should always be considered for diffing"""
204
self.make_example_branch()
205
self.run_bzr('diff', '-r', '0..1', 'hello', retcode=1)
206
wt = workingtree.WorkingTree.open_containing('.')[0]
207
wt.rename_one('hello', 'hello1')
208
self.run_bzr('diff', 'hello1', retcode=1)
209
self.run_bzr('diff', '-r', '0..1', 'hello1', retcode=1)
218
tree = self.make_example_branch()
219
self.run_bzr('diff -r 0..1 hello', retcode=1)
220
tree.rename_one('hello', 'hello1')
221
self.run_bzr('diff hello1', retcode=1)
222
self.run_bzr('diff -r 0..1 hello1', retcode=1)
212
225
class TestCheckoutDiff(TestDiff):
214
227
def make_example_branch(self):
215
super(TestCheckoutDiff, self).make_example_branch()
216
self.runbzr('checkout . checkout')
228
tree = super(TestCheckoutDiff, self).make_example_branch()
229
tree = tree.branch.create_checkout('checkout')
217
230
os.chdir('checkout')
219
233
def example_branch2(self):
220
super(TestCheckoutDiff, self).example_branch2()
234
tree = super(TestCheckoutDiff, self).example_branch2()
221
235
os.mkdir('checkouts')
222
self.runbzr('checkout branch1 checkouts/branch1')
236
tree = tree.branch.create_checkout('checkouts/branch1')
223
237
os.chdir('checkouts')
225
240
def example_branches(self):
226
super(TestCheckoutDiff, self).example_branches()
241
branch1_tree, branch2_tree = super(TestCheckoutDiff, self).example_branches()
227
242
os.mkdir('checkouts')
228
self.runbzr('checkout branch1 checkouts/branch1')
229
self.runbzr('checkout branch2 checkouts/branch2')
243
branch1_tree = branch1_tree.branch.create_checkout('checkouts/branch1')
244
branch2_tree = branch2_tree.branch.create_checkout('checkouts/branch2')
230
245
os.chdir('checkouts')
233
class TestDiffLabels(TestDiff):
246
return branch1_tree, branch2_tree
249
class TestDiffLabels(DiffBase):
235
251
def test_diff_label_removed(self):
236
super(TestDiffLabels, self).make_example_branch()
237
self.runbzr('remove hello')
238
diff = self.run_bzr_captured(['diff'], retcode=1)
252
tree = super(TestDiffLabels, self).make_example_branch()
253
tree.remove('hello', keep_files=False)
254
diff = self.run_bzr('diff', retcode=1)
239
255
self.assertTrue("=== removed file 'hello'" in diff[0])
241
257
def test_diff_label_added(self):
242
super(TestDiffLabels, self).make_example_branch()
243
file('barbar', 'wt').write('barbar')
244
self.runbzr('add barbar')
245
diff = self.run_bzr_captured(['diff'], retcode=1)
258
tree = super(TestDiffLabels, self).make_example_branch()
259
self.build_tree_contents([('barbar', 'barbar')])
261
diff = self.run_bzr('diff', retcode=1)
246
262
self.assertTrue("=== added file 'barbar'" in diff[0])
248
264
def test_diff_label_modified(self):
249
265
super(TestDiffLabels, self).make_example_branch()
250
file('hello', 'wt').write('barbar')
251
diff = self.run_bzr_captured(['diff'], retcode=1)
266
self.build_tree_contents([('hello', 'barbar')])
267
diff = self.run_bzr('diff', retcode=1)
252
268
self.assertTrue("=== modified file 'hello'" in diff[0])
254
270
def test_diff_label_renamed(self):
255
super(TestDiffLabels, self).make_example_branch()
256
self.runbzr('rename hello gruezi')
257
diff = self.run_bzr_captured(['diff'], retcode=1)
271
tree = super(TestDiffLabels, self).make_example_branch()
272
tree.rename_one('hello', 'gruezi')
273
diff = self.run_bzr('diff', retcode=1)
258
274
self.assertTrue("=== renamed file 'hello' => 'gruezi'" in diff[0])
261
class TestExternalDiff(TestDiff):
277
class TestExternalDiff(DiffBase):
263
279
def test_external_diff(self):
264
280
"""Test that we can spawn an external diff process"""