142
142
def example_branches(self):
143
143
self.build_tree(['branch1/', 'branch1/file'], line_endings='binary')
144
self.run_bzr('init branch1')[0]
145
self.run_bzr('add branch1/file')[0]
144
self.run_bzr(['init', 'branch1'])[0]
145
self.run_bzr(['add', 'branch1/file'])[0]
146
146
self.run_bzr(['commit', '-m', 'add file', 'branch1'])
147
self.run_bzr('branch branch1 branch2')[0]
147
self.run_bzr(['branch', 'branch1', 'branch2'])[0]
148
148
self.build_tree_contents([('branch2/file', 'new content\n')])
149
149
self.run_bzr(['commit', '-m', 'update file', 'branch2'])
151
151
def test_diff_branches(self):
152
152
self.example_branches()
153
153
# should open branch1 and diff against branch2,
154
out, err = self.run_bzr('diff -r branch:branch2 branch1',
154
out, err = self.run_bzr(['diff', '-r', 'branch:branch2',
156
157
self.assertEquals('', err)
157
158
self.assertEquals("=== modified file 'file'\n"
158
159
"--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
162
163
"+contents of branch1/file\n"
163
164
"\n", subst_dates(out))
164
out, err = self.run_bzr('diff branch2 branch1',
165
out, err = self.run_bzr(['diff', 'branch2', 'branch1'],
166
167
self.assertEquals('', err)
167
168
self.assertEqualDiff("=== modified file 'file'\n"
175
176
def test_diff_revno_branches(self):
176
177
self.example_branches()
177
178
print >> open('branch2/file', 'wb'), 'even newer content'
178
self.run_bzr(['commit', '-m',
179
'update file once more', 'branch2'])
179
self.run_bzr(['commit', '-m',
180
'update file once more', 'branch2'])
181
out, err = self.run_bzr('diff -r revno:1:branch2..revno:1:branch1',
182
out, err = self.run_bzr(['diff', '-r',
183
'revno:1:branch2..revno:1:branch1'],
183
185
self.assertEquals('', err)
184
186
self.assertEquals('', out)
185
out, err = self.run_bzr('diff -r revno:2:branch2..revno:1:branch1',
187
out, err = self.run_bzr(['diff', '-r',
188
'revno:2:branch2..revno:1:branch1'],
187
190
self.assertEquals('', err)
188
191
self.assertEqualDiff("=== modified file 'file'\n"
189
192
"--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
196
199
def example_branch2(self):
197
200
self.build_tree(['branch1/', 'branch1/file1'], line_endings='binary')
198
self.run_bzr('init branch1')[0]
199
self.run_bzr('add branch1/file1')[0]
201
self.run_bzr(['init', 'branch1'])[0]
202
self.run_bzr(['add', 'branch1/file1'])[0]
200
203
print >> open('branch1/file1', 'wb'), 'original line'
201
204
self.run_bzr(['commit', '-m', 'first commit', 'branch1'])
207
210
self.example_branch2()
209
212
print >> open('branch1/file1', 'wb'), 'new line'
210
output = self.run_bzr('diff -r 1.. branch1',
213
output = self.run_bzr(['diff', '-r', '1..', 'branch1'],
212
215
self.assertTrue('\n-original line\n+new line\n' in output[0])
214
217
def test_diff_across_rename(self):
215
218
"""The working tree path should always be considered for diffing"""
216
219
self.make_example_branch()
217
self.run_bzr('diff -r 0..1 hello', retcode=1)
220
self.run_bzr('diff', '-r', '0..1', 'hello', retcode=1)
218
221
wt = workingtree.WorkingTree.open_containing('.')[0]
219
222
wt.rename_one('hello', 'hello1')
220
self.run_bzr('diff hello1', retcode=1)
221
self.run_bzr('diff -r 0..1 hello1', retcode=1)
223
self.run_bzr('diff', 'hello1', retcode=1)
224
self.run_bzr('diff', '-r', '0..1', 'hello1', retcode=1)
224
227
class TestCheckoutDiff(TestDiff):
247
250
def test_diff_label_removed(self):
248
251
super(TestDiffLabels, self).make_example_branch()
249
252
self.run_bzr('remove hello')
250
diff = self.run_bzr('diff', retcode=1)
253
diff = self.run_bzr(['diff'], retcode=1)
251
254
self.assertTrue("=== removed file 'hello'" in diff[0])
253
256
def test_diff_label_added(self):
254
257
super(TestDiffLabels, self).make_example_branch()
255
258
file('barbar', 'wt').write('barbar')
256
259
self.run_bzr('add barbar')
257
diff = self.run_bzr('diff', retcode=1)
260
diff = self.run_bzr(['diff'], retcode=1)
258
261
self.assertTrue("=== added file 'barbar'" in diff[0])
260
263
def test_diff_label_modified(self):
261
264
super(TestDiffLabels, self).make_example_branch()
262
265
file('hello', 'wt').write('barbar')
263
diff = self.run_bzr('diff', retcode=1)
266
diff = self.run_bzr(['diff'], retcode=1)
264
267
self.assertTrue("=== modified file 'hello'" in diff[0])
266
269
def test_diff_label_renamed(self):
267
270
super(TestDiffLabels, self).make_example_branch()
268
271
self.run_bzr('rename hello gruezi')
269
diff = self.run_bzr('diff', retcode=1)
272
diff = self.run_bzr(['diff'], retcode=1)
270
273
self.assertTrue("=== renamed file 'hello' => 'gruezi'" in diff[0])