163
164
tree.commit('add file', committer="test@host", rev_id="rev1")
164
165
self.build_tree_contents([(file_relpath, 'foo\nbar\ngam\n')])
165
tree.branch.get_config().set_user_option('email', 'current@host2')
168
168
def test_annotate_cmd_revspec_branch(self):
169
169
tree = self._setup_edited_file('trunk')
170
170
tree.branch.create_checkout(self.get_url('work'), lightweight=True)
172
out, err = self.run_bzr('annotate file -r branch:../trunk')
171
out, err = self.run_bzr(['annotate', 'file', '-r', 'branch:../trunk'],
173
173
self.assertEqual('', err)
174
174
self.assertEqual(
175
175
'1 test@ho | foo\n'
185
186
'1 test@ho | gam\n',
189
def test_annotate_edited_file_no_default(self):
190
# Ensure that when no username is available annotate still works.
191
self.overrideEnv('EMAIL', None)
192
self.overrideEnv('BZR_EMAIL', None)
193
# Also, make sure that it's not inferred from mailname.
194
self.overrideAttr(config, '_auto_user_id',
195
lambda: (None, None))
196
tree = self._setup_edited_file()
197
out, err = self.run_bzr('annotate file')
188
204
def test_annotate_edited_file_show_ids(self):
189
205
tree = self._setup_edited_file()
206
tree.branch.get_config().set_user_option('email', 'current@host2')
190
207
out, err = self.run_bzr('annotate file --show-ids')
191
208
self.assertEqual(
211
228
tree.merge_from_branch(tree.branch, "rev1.1.1")
212
229
# edit the file to be 'resolved' and have a further local edit
213
230
self.build_tree_contents([('file', 'local\nfoo\nbar\nbaz\ngam\n')])
215
233
def test_annotated_edited_merged_file_revnos(self):
216
self._create_merged_file()
217
out, err = self.run_bzr('annotate file')
218
email = extract_email_address(Branch.open('.').get_config().username())
234
wt = self._create_merged_file()
235
out, err = self.run_bzr(['annotate', 'file'])
236
email = config.extract_email_address(wt.branch.get_config().username())
219
237
self.assertEqual(
220
238
'3? %-7s | local\n'
221
239
'1 test@ho | foo\n'
238
256
def test_annotate_empty_file(self):
239
tree = self.make_branch_and_tree('tree')
240
self.build_tree_contents([('tree/empty', '')])
257
tree = self.make_branch_and_tree('.')
258
self.build_tree_contents([('empty', '')])
241
259
tree.add('empty')
242
260
tree.commit('add empty file')
261
out, err = self.run_bzr(['annotate', 'empty'])
262
self.assertEqual('', out)
245
out, err = self.run_bzr('annotate empty')
264
def test_annotate_removed_file(self):
265
tree = self.make_branch_and_tree('.')
266
self.build_tree_contents([('empty', '')])
268
tree.commit('add empty file')
271
tree.commit('remove empty file')
272
out, err = self.run_bzr(['annotate', '-r1', 'empty'])
246
273
self.assertEqual('', out)
248
275
def test_annotate_empty_file_show_ids(self):
249
tree = self.make_branch_and_tree('tree')
250
self.build_tree_contents([('tree/empty', '')])
276
tree = self.make_branch_and_tree('.')
277
self.build_tree_contents([('empty', '')])
251
278
tree.add('empty')
252
279
tree.commit('add empty file')
255
280
out, err = self.run_bzr(['annotate', '--show-ids', 'empty'])
256
281
self.assertEqual('', out)
258
283
def test_annotate_nonexistant_file(self):
259
tree = self.make_branch_and_tree('tree')
260
self.build_tree(['tree/file'])
284
tree = self.make_branch_and_tree('.')
285
self.build_tree(['file'])
261
286
tree.add(['file'])
262
287
tree.commit('add a file')
265
out, err = self.run_bzr("annotate doesnotexist", retcode=3)
288
out, err = self.run_bzr(['annotate', 'doesnotexist'], retcode=3)
266
289
self.assertEqual('', out)
267
290
self.assertEqual("bzr: ERROR: doesnotexist is not versioned.\n", err)
269
292
def test_annotate_without_workingtree(self):
270
tree = self.make_branch_and_tree('branch')
271
self.build_tree_contents([('branch/empty', '')])
293
tree = self.make_branch_and_tree('.')
294
self.build_tree_contents([('empty', '')])
272
295
tree.add('empty')
273
296
tree.commit('add empty file')
274
297
bzrdir = tree.branch.bzrdir
275
298
bzrdir.destroy_workingtree()
276
299
self.assertFalse(bzrdir.has_workingtree())
279
out, err = self.run_bzr('annotate empty')
300
out, err = self.run_bzr(['annotate', 'empty'])
280
301
self.assertEqual('', out)
282
303
def test_annotate_directory(self):
285
306
self.build_tree_contents([('a/hello.txt', 'my helicopter\n')])
286
307
wt.add(['hello.txt'])
287
308
wt.commit('commit', committer='test@user')
288
out, err = self.run_bzr('annotate -d a hello.txt')
309
out, err = self.run_bzr(['annotate', '-d', 'a', 'hello.txt'])
289
310
self.assertEqualDiff('1 test@us | my helicopter\n', out)
313
class TestSmartServerAnnotate(tests.TestCaseWithTransport):
315
def test_simple_annotate(self):
316
self.setup_smart_server_with_call_log()
317
wt = self.make_branch_and_tree('branch')
318
self.build_tree_contents([('branch/hello.txt', 'my helicopter\n')])
319
wt.add(['hello.txt'])
320
wt.commit('commit', committer='test@user')
321
self.reset_smart_call_log()
322
out, err = self.run_bzr(['annotate', "-d", self.get_url('branch'),
324
# This figure represent the amount of work to perform this use case. It
325
# is entirely ok to reduce this number if a test fails due to rpc_count
326
# being too low. If rpc_count increases, more network roundtrips have
327
# become necessary for this use case. Please do not adjust this number
328
# upwards without agreement from bzr's network support maintainers.
329
self.assertLength(19, self.hpss_calls)
330
self.expectFailure("annotate accesses inventories, which require VFS access",
331
self.assertThat, self.hpss_calls, ContainsNoVfsCalls)