47
46
tree.add(['goodbye'])
48
47
tree.commit('setup')
51
class TestDiff(DiffBase):
53
49
def test_diff(self):
54
50
self.make_example_branch()
55
51
file('hello', 'wt').write('hello world!')
56
self.run_bzr('commit -m fixing hello')
57
output = self.run_bzr('diff -r 2..3', retcode=1)[0]
52
self.runbzr('commit -m fixing hello')
53
output = self.runbzr('diff -r 2..3', backtick=1, retcode=1)
58
54
self.assert_('\n+hello world!' in output)
59
output = self.run_bzr('diff -r last:3..last:1',
55
output = self.runbzr('diff -r last:3..last:1', backtick=1, retcode=1)
61
56
self.assert_('\n+baz' in output)
62
self.build_tree(['moo'])
63
self.run_bzr('add moo')
57
file('moo', 'wb').write('moo')
58
self.runbzr('add moo')
67
62
def test_diff_prefix(self):
68
63
"""diff --prefix appends to filenames in output"""
69
64
self.make_example_branch()
70
65
file('hello', 'wb').write('hello world!\n')
71
out, err = self.run_bzr('diff --prefix old/:new/', retcode=1)
66
out, err = self.runbzr('diff --prefix old/:new/', retcode=1)
72
67
self.assertEquals(err, '')
73
68
self.assertEqualDiff(subst_dates(out), '''\
74
69
=== modified file 'hello'
83
def test_diff_illegal_prefix_value(self):
84
# There was an error in error reporting for this option
85
out, err = self.run_bzr('diff --prefix old/', retcode=3)
86
self.assertContainsRe(err,
87
'--prefix expects two values separated by a colon')
89
78
def test_diff_p1(self):
90
79
"""diff -p1 produces lkml-style diffs"""
91
80
self.make_example_branch()
92
81
file('hello', 'wb').write('hello world!\n')
93
out, err = self.run_bzr('diff -p1', retcode=1)
82
out, err = self.runbzr('diff -p1', retcode=1)
94
83
self.assertEquals(err, '')
95
84
self.assertEqualDiff(subst_dates(out), '''\
96
85
=== modified file 'hello'
122
111
# Get an error from a file that does not exist at all
124
113
self.make_example_branch()
125
out, err = self.run_bzr('diff does-not-exist', retcode=3)
114
out, err = self.runbzr('diff does-not-exist', retcode=3)
126
115
self.assertContainsRe(err, 'not versioned.*does-not-exist')
128
def test_diff_illegal_revision_specifiers(self):
129
out, err = self.run_bzr('diff -r 1..23..123', retcode=3)
130
self.assertContainsRe(err, 'one or two revision specifiers')
132
117
def test_diff_unversioned(self):
133
118
# Get an error when diffing a non-versioned file.
135
120
self.make_example_branch()
136
121
self.build_tree(['unversioned-file'])
137
out, err = self.run_bzr('diff unversioned-file', retcode=3)
122
out, err = self.runbzr('diff unversioned-file', retcode=3)
138
123
self.assertContainsRe(err, 'not versioned.*unversioned-file')
140
125
# TODO: What should diff say for a file deleted in working tree?
142
127
def example_branches(self):
143
128
self.build_tree(['branch1/', 'branch1/file'], line_endings='binary')
144
self.run_bzr('init branch1')[0]
145
self.run_bzr('add branch1/file')[0]
146
self.run_bzr(['commit', '-m', 'add file', 'branch1'])
147
self.run_bzr('branch branch1 branch2')[0]
148
self.build_tree_contents([('branch2/file', 'new content\n')])
149
self.run_bzr(['commit', '-m', 'update file', 'branch2'])
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'])
151
136
def test_diff_branches(self):
152
137
self.example_branches()
153
138
# should open branch1 and diff against branch2,
154
out, err = self.run_bzr('diff -r branch:branch2 branch1',
139
out, err = self.run_bzr_captured(['diff', '-r', 'branch:branch2',
156
142
self.assertEquals('', err)
157
143
self.assertEquals("=== modified file 'file'\n"
158
144
"--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
175
161
def test_diff_revno_branches(self):
176
162
self.example_branches()
177
163
print >> open('branch2/file', 'wb'), 'even newer content'
178
self.run_bzr(['commit', '-m',
179
'update file once more', 'branch2'])
164
self.run_bzr_captured(['commit', '-m',
165
'update file once more', 'branch2'])
181
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'],
183
170
self.assertEquals('', err)
184
171
self.assertEquals('', out)
185
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'],
187
175
self.assertEquals('', err)
188
176
self.assertEqualDiff("=== modified file 'file'\n"
189
177
"--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
196
184
def example_branch2(self):
197
185
self.build_tree(['branch1/', 'branch1/file1'], line_endings='binary')
198
self.run_bzr('init branch1')[0]
199
self.run_bzr('add branch1/file1')[0]
186
self.capture('init branch1')
187
self.capture('add branch1/file1')
200
188
print >> open('branch1/file1', 'wb'), 'original line'
201
self.run_bzr(['commit', '-m', 'first commit', 'branch1'])
189
self.run_bzr_captured(['commit', '-m', 'first commit', 'branch1'])
203
191
print >> open('branch1/file1', 'wb'), 'repo line'
204
self.run_bzr(['commit', '-m', 'second commit', 'branch1'])
192
self.run_bzr_captured(['commit', '-m', 'second commit', 'branch1'])
206
194
def test_diff_to_working_tree(self):
207
195
self.example_branch2()
209
197
print >> open('branch1/file1', 'wb'), 'new line'
210
output = self.run_bzr('diff -r 1.. branch1',
198
output = self.run_bzr_captured(['diff', '-r', '1..', 'branch1'],
212
200
self.assertTrue('\n-original line\n+new line\n' in output[0])
214
202
def test_diff_across_rename(self):
215
203
"""The working tree path should always be considered for diffing"""
216
204
self.make_example_branch()
217
self.run_bzr('diff -r 0..1 hello', retcode=1)
205
self.run_bzr('diff', '-r', '0..1', 'hello', retcode=1)
218
206
wt = workingtree.WorkingTree.open_containing('.')[0]
219
207
wt.rename_one('hello', 'hello1')
220
self.run_bzr('diff hello1', retcode=1)
221
self.run_bzr('diff -r 0..1 hello1', retcode=1)
208
self.run_bzr('diff', 'hello1', retcode=1)
209
self.run_bzr('diff', '-r', '0..1', 'hello1', retcode=1)
224
212
class TestCheckoutDiff(TestDiff):
226
214
def make_example_branch(self):
227
215
super(TestCheckoutDiff, self).make_example_branch()
228
self.run_bzr('checkout . checkout')
216
self.runbzr('checkout . checkout')
229
217
os.chdir('checkout')
231
219
def example_branch2(self):
232
220
super(TestCheckoutDiff, self).example_branch2()
233
221
os.mkdir('checkouts')
234
self.run_bzr('checkout branch1 checkouts/branch1')
222
self.runbzr('checkout branch1 checkouts/branch1')
235
223
os.chdir('checkouts')
237
225
def example_branches(self):
238
226
super(TestCheckoutDiff, self).example_branches()
239
227
os.mkdir('checkouts')
240
self.run_bzr('checkout branch1 checkouts/branch1')
241
self.run_bzr('checkout branch2 checkouts/branch2')
228
self.runbzr('checkout branch1 checkouts/branch1')
229
self.runbzr('checkout branch2 checkouts/branch2')
242
230
os.chdir('checkouts')
245
class TestDiffLabels(DiffBase):
233
class TestDiffLabels(TestDiff):
247
235
def test_diff_label_removed(self):
248
236
super(TestDiffLabels, self).make_example_branch()
249
self.run_bzr('remove hello')
250
diff = self.run_bzr('diff', retcode=1)
237
self.runbzr('remove hello')
238
diff = self.run_bzr_captured(['diff'], retcode=1)
251
239
self.assertTrue("=== removed file 'hello'" in diff[0])
253
241
def test_diff_label_added(self):
254
242
super(TestDiffLabels, self).make_example_branch()
255
243
file('barbar', 'wt').write('barbar')
256
self.run_bzr('add barbar')
257
diff = self.run_bzr('diff', retcode=1)
244
self.runbzr('add barbar')
245
diff = self.run_bzr_captured(['diff'], retcode=1)
258
246
self.assertTrue("=== added file 'barbar'" in diff[0])
260
248
def test_diff_label_modified(self):
261
249
super(TestDiffLabels, self).make_example_branch()
262
250
file('hello', 'wt').write('barbar')
263
diff = self.run_bzr('diff', retcode=1)
251
diff = self.run_bzr_captured(['diff'], retcode=1)
264
252
self.assertTrue("=== modified file 'hello'" in diff[0])
266
254
def test_diff_label_renamed(self):
267
255
super(TestDiffLabels, self).make_example_branch()
268
self.run_bzr('rename hello gruezi')
269
diff = self.run_bzr('diff', retcode=1)
256
self.runbzr('rename hello gruezi')
257
diff = self.run_bzr_captured(['diff'], retcode=1)
270
258
self.assertTrue("=== renamed file 'hello' => 'gruezi'" in diff[0])
273
class TestExternalDiff(DiffBase):
261
class TestExternalDiff(TestDiff):
275
263
def test_external_diff(self):
276
264
"""Test that we can spawn an external diff process"""