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