141
137
out, err = self.run_bzr('annotate hello.txt -r 10',
143
139
self.assertEqual('', out)
144
self.assertContainsRe(err, "Requested revision: '10' does not exist")
140
self.assertContainsRe(err, 'Requested revision: \'10\' does not exist')
146
142
def test_annotate_cmd_two_revisions(self):
147
143
out, err = self.run_bzr('annotate hello.txt -r1..2',
149
145
self.assertEqual('', out)
150
146
self.assertEqual('bzr: ERROR: bzr annotate --revision takes'
151
' exactly one revision identifier\n',
147
' exactly 1 argument\n',
155
class TestSimpleAnnotate(tests.TestCaseWithTransport):
156
"""Annotate tests with no complex setup."""
158
def _setup_edited_file(self, relpath='.'):
159
"""Create a tree with a locally edited file."""
160
tree = self.make_branch_and_tree(relpath)
161
file_relpath = joinpath(relpath, 'file')
162
self.build_tree_contents([(file_relpath, 'foo\ngam\n')])
164
tree.commit('add file', committer="test@host", rev_id="rev1")
165
self.build_tree_contents([(file_relpath, 'foo\nbar\ngam\n')])
168
def test_annotate_cmd_revspec_branch(self):
169
tree = self._setup_edited_file('trunk')
170
tree.branch.create_checkout(self.get_url('work'), lightweight=True)
171
out, err = self.run_bzr(['annotate', 'file', '-r', 'branch:../trunk'],
173
self.assertEqual('', err)
179
def test_annotate_edited_file(self):
180
tree = self._setup_edited_file()
181
self.overrideEnv('BZR_EMAIL', 'current@host2')
182
out, err = self.run_bzr('annotate file')
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')
204
def test_annotate_edited_file_show_ids(self):
205
tree = self._setup_edited_file()
206
self.overrideEnv('BZR_EMAIL', 'current@host2')
207
out, err = self.run_bzr('annotate file --show-ids')
214
def _create_merged_file(self):
215
"""Create a file with a pending merge and local edit."""
216
tree = self.make_branch_and_tree('.')
217
self.build_tree_contents([('file', 'foo\ngam\n')])
219
tree.commit('add file', rev_id="rev1", committer="test@host")
221
self.build_tree_contents([('file', 'foo\nbar\ngam\n')])
222
tree.commit("right", rev_id="rev1.1.1", committer="test@host")
223
tree.pull(tree.branch, True, "rev1")
225
self.build_tree_contents([('file', 'foo\nbaz\ngam\n')])
226
tree.commit("left", rev_id="rev2", committer="test@host")
228
tree.merge_from_branch(tree.branch, "rev1.1.1")
229
# edit the file to be 'resolved' and have a further local edit
230
self.build_tree_contents([('file', 'local\nfoo\nbar\nbaz\ngam\n')])
233
def test_annotated_edited_merged_file_revnos(self):
234
wt = self._create_merged_file()
235
out, err = self.run_bzr(['annotate', 'file'])
236
email = config.extract_email_address(
237
wt.branch.get_config_stack().get('email'))
241
'1.1.1 test@ho | bar\n'
243
'1 test@ho | gam\n' % email[:7],
246
def test_annotated_edited_merged_file_ids(self):
247
self._create_merged_file()
248
out, err = self.run_bzr(['annotate', 'file', '--show-ids'])
257
150
def test_annotate_empty_file(self):
258
tree = self.make_branch_and_tree('.')
259
self.build_tree_contents([('empty', '')])
261
tree.commit('add empty file')
262
out, err = self.run_bzr(['annotate', 'empty'])
263
self.assertEqual('', out)
265
def test_annotate_removed_file(self):
266
tree = self.make_branch_and_tree('.')
267
self.build_tree_contents([('empty', '')])
269
tree.commit('add empty file')
272
tree.commit('remove empty file')
273
out, err = self.run_bzr(['annotate', '-r1', 'empty'])
274
self.assertEqual('', out)
276
def test_annotate_empty_file_show_ids(self):
277
tree = self.make_branch_and_tree('.')
278
self.build_tree_contents([('empty', '')])
280
tree.commit('add empty file')
281
out, err = self.run_bzr(['annotate', '--show-ids', 'empty'])
151
tree = self.make_branch_and_tree('tree')
152
self.build_tree_contents([('tree/empty', '')])
154
tree.commit('add empty file')
157
out, err = self.run_bzr('annotate empty')
282
158
self.assertEqual('', out)
284
160
def test_annotate_nonexistant_file(self):
285
tree = self.make_branch_and_tree('.')
286
self.build_tree(['file'])
161
tree = self.make_branch_and_tree('tree')
162
self.build_tree(['tree/file'])
287
163
tree.add(['file'])
288
164
tree.commit('add a file')
289
out, err = self.run_bzr(['annotate', 'doesnotexist'], retcode=3)
167
out, err = self.run_bzr("annotate doesnotexist", retcode=3)
290
168
self.assertEqual('', out)
291
169
self.assertEqual("bzr: ERROR: doesnotexist is not versioned.\n", err)
293
171
def test_annotate_without_workingtree(self):
294
tree = self.make_branch_and_tree('.')
295
self.build_tree_contents([('empty', '')])
172
tree = self.make_branch_and_tree('branch')
173
self.build_tree_contents([('branch/empty', '')])
296
174
tree.add('empty')
297
175
tree.commit('add empty file')
298
176
bzrdir = tree.branch.bzrdir
299
177
bzrdir.destroy_workingtree()
300
178
self.assertFalse(bzrdir.has_workingtree())
301
out, err = self.run_bzr(['annotate', 'empty'])
181
out, err = self.run_bzr('annotate empty')
302
182
self.assertEqual('', out)
304
def test_annotate_directory(self):
305
"""Test --directory option"""
306
wt = self.make_branch_and_tree('a')
307
self.build_tree_contents([('a/hello.txt', 'my helicopter\n')])
308
wt.add(['hello.txt'])
309
wt.commit('commit', committer='test@user')
310
out, err = self.run_bzr(['annotate', '-d', 'a', 'hello.txt'])
311
self.assertEqualDiff('1 test@us | my helicopter\n', out)
314
class TestSmartServerAnnotate(tests.TestCaseWithTransport):
316
def test_simple_annotate(self):
317
self.setup_smart_server_with_call_log()
318
wt = self.make_branch_and_tree('branch')
319
self.build_tree_contents([('branch/hello.txt', 'my helicopter\n')])
320
wt.add(['hello.txt'])
321
wt.commit('commit', committer='test@user')
322
self.reset_smart_call_log()
323
out, err = self.run_bzr(['annotate', "-d", self.get_url('branch'),
325
# This figure represent the amount of work to perform this use case. It
326
# is entirely ok to reduce this number if a test fails due to rpc_count
327
# being too low. If rpc_count increases, more network roundtrips have
328
# become necessary for this use case. Please do not adjust this number
329
# upwards without agreement from bzr's network support maintainers.
330
self.assertLength(16, self.hpss_calls)
331
self.assertLength(1, self.hpss_connections)
332
self.expectFailure("annotate accesses inventories, which require VFS access",
333
self.assertThat, self.hpss_calls, ContainsNoVfsCalls)