146
146
def example_branches(self):
147
147
branch1_tree = self.make_branch_and_tree('branch1')
148
148
self.build_tree(['branch1/file'], line_endings='binary')
149
self.build_tree(['branch1/file2'], line_endings='binary')
149
150
branch1_tree.add('file')
150
branch1_tree.commit(message='add file')
151
branch1_tree.add('file2')
152
branch1_tree.commit(message='add file and file2')
151
153
branch2_tree = branch1_tree.bzrdir.sprout('branch2').open_workingtree()
152
154
self.build_tree_contents([('branch2/file', 'new content\n')])
153
155
branch2_tree.commit(message='update file')
167
169
"+contents of branch1/file\n"
168
170
"\n", subst_dates(out))
169
out, err = self.run_bzr('diff branch2 branch1',
171
self.assertEquals('', err)
172
self.assertEqualDiff("=== modified file 'file'\n"
173
"--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
174
"+++ file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
177
"+contents of branch1/file\n"
171
# Compare two working trees
172
out, err = self.run_bzr('diff --old branch2 --new branch1',
174
self.assertEquals('', err)
175
self.assertEqualDiff("=== modified file 'file'\n"
176
"--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
177
"+++ file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
180
"+contents of branch1/file\n"
181
"\n", subst_dates(out))
182
# Test with a selected file that was changed
183
out, err = self.run_bzr('diff --old branch2 --new branch1 file',
185
self.assertEquals('', err)
186
self.assertEqualDiff("=== modified file 'file'\n"
187
"--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
188
"+++ file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
191
"+contents of branch1/file\n"
192
"\n", subst_dates(out))
193
# Test with a selected file that was not changed
194
out, err = self.run_bzr('diff --old branch2 --new branch1 file2',
196
self.assertEquals('', err)
197
self.assertEquals('', out)
199
def test_diff_branches_no_working_trees(self):
200
branch1_tree, branch2_tree = self.example_branches()
201
# Compare a working tree to a branch without a WT
202
dir1 = branch1_tree.bzrdir
203
dir1.destroy_workingtree()
204
self.assertFalse(dir1.has_workingtree())
205
out, err = self.run_bzr('diff --old branch2 --new branch1',
207
self.assertEquals('', err)
208
self.assertEqualDiff("=== modified file 'file'\n"
209
"--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
210
"+++ file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
213
"+contents of branch1/file\n"
214
"\n", subst_dates(out))
215
# Compare a branch without a WT to one with a WT
216
out, err = self.run_bzr('diff --old branch1 --new branch2',
218
self.assertEquals('', err)
219
self.assertEqualDiff("=== modified file 'file'\n"
220
"--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
221
"+++ file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
223
"-contents of branch1/file\n"
225
"\n", subst_dates(out))
226
# Compare a branch with a WT against another without a WT
227
dir2 = branch2_tree.bzrdir
228
dir2.destroy_workingtree()
229
self.assertFalse(dir2.has_workingtree())
230
out, err = self.run_bzr('diff --old branch1 --new branch2',
232
self.assertEquals('', err)
233
self.assertEqualDiff("=== modified file 'file'\n"
234
"--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
235
"+++ file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
237
"-contents of branch1/file\n"
178
239
"\n", subst_dates(out))
180
241
def test_diff_revno_branches(self):
221
282
self.run_bzr('diff hello1', retcode=1)
222
283
self.run_bzr('diff -r 0..1 hello1', retcode=1)
285
def test_diff_to_branch_no_working_tree(self):
286
branch1_tree = self.example_branch2()
287
dir1 = branch1_tree.bzrdir
288
dir1.destroy_workingtree()
289
self.assertFalse(dir1.has_workingtree())
290
output = self.run_bzr('diff -r 1.. branch1', retcode=1)
291
self.assertContainsRe(output[0], '\n\\-original line\n\\+repo line\n')
225
294
class TestCheckoutDiff(TestDiff):