140
137
out, err = self.run_bzr('annotate hello.txt -r 10',
142
139
self.assertEqual('', out)
143
self.assertContainsRe(err, "Requested revision: '10' does not exist")
140
self.assertContainsRe(err, 'Requested revision: \'10\' does not exist')
145
142
def test_annotate_cmd_two_revisions(self):
146
143
out, err = self.run_bzr('annotate hello.txt -r1..2',
148
145
self.assertEqual('', out)
149
146
self.assertEqual('bzr: ERROR: bzr annotate --revision takes'
150
' exactly one revision identifier\n',
147
' exactly 1 argument\n',
154
class TestSimpleAnnotate(tests.TestCaseWithTransport):
155
"""Annotate tests with no complex setup."""
157
def _setup_edited_file(self, relpath='.'):
158
"""Create a tree with a locally edited file."""
159
tree = self.make_branch_and_tree(relpath)
160
file_relpath = joinpath(relpath, 'file')
161
self.build_tree_contents([(file_relpath, 'foo\ngam\n')])
163
tree.commit('add file', committer="test@host", rev_id="rev1")
164
self.build_tree_contents([(file_relpath, 'foo\nbar\ngam\n')])
167
def test_annotate_cmd_revspec_branch(self):
168
tree = self._setup_edited_file('trunk')
169
tree.branch.create_checkout(self.get_url('work'), lightweight=True)
170
out, err = self.run_bzr(['annotate', 'file', '-r', 'branch:../trunk'],
172
self.assertEqual('', err)
178
def test_annotate_edited_file(self):
179
tree = self._setup_edited_file()
180
tree.branch.get_config().set_user_option('email', 'current@host2')
181
out, err = self.run_bzr('annotate file')
188
def test_annotate_edited_file_no_default(self):
189
# Ensure that when no username is available annotate still works.
190
self.overrideEnv('EMAIL', None)
191
self.overrideEnv('BZR_EMAIL', None)
192
# Also, make sure that it's not inferred from mailname.
193
self.overrideAttr(config, '_auto_user_id',
194
lambda: (None, None))
195
tree = self._setup_edited_file()
196
out, err = self.run_bzr('annotate file')
203
def test_annotate_edited_file_show_ids(self):
204
tree = self._setup_edited_file()
205
tree.branch.get_config().set_user_option('email', 'current@host2')
206
out, err = self.run_bzr('annotate file --show-ids')
213
def _create_merged_file(self):
214
"""Create a file with a pending merge and local edit."""
215
tree = self.make_branch_and_tree('.')
216
self.build_tree_contents([('file', 'foo\ngam\n')])
218
tree.commit('add file', rev_id="rev1", committer="test@host")
220
self.build_tree_contents([('file', 'foo\nbar\ngam\n')])
221
tree.commit("right", rev_id="rev1.1.1", committer="test@host")
222
tree.pull(tree.branch, True, "rev1")
224
self.build_tree_contents([('file', 'foo\nbaz\ngam\n')])
225
tree.commit("left", rev_id="rev2", committer="test@host")
227
tree.merge_from_branch(tree.branch, "rev1.1.1")
228
# edit the file to be 'resolved' and have a further local edit
229
self.build_tree_contents([('file', 'local\nfoo\nbar\nbaz\ngam\n')])
232
def test_annotated_edited_merged_file_revnos(self):
233
wt = self._create_merged_file()
234
out, err = self.run_bzr(['annotate', 'file'])
235
email = config.extract_email_address(wt.branch.get_config().username())
239
'1.1.1 test@ho | bar\n'
241
'1 test@ho | gam\n' % email[:7],
244
def test_annotated_edited_merged_file_ids(self):
245
self._create_merged_file()
246
out, err = self.run_bzr(['annotate', 'file', '--show-ids'])
255
150
def test_annotate_empty_file(self):
256
tree = self.make_branch_and_tree('.')
257
self.build_tree_contents([('empty', '')])
259
tree.commit('add empty file')
260
out, err = self.run_bzr(['annotate', 'empty'])
261
self.assertEqual('', out)
263
def test_annotate_removed_file(self):
264
tree = self.make_branch_and_tree('.')
265
self.build_tree_contents([('empty', '')])
267
tree.commit('add empty file')
270
tree.commit('remove empty file')
271
out, err = self.run_bzr(['annotate', '-r1', 'empty'])
272
self.assertEqual('', out)
274
def test_annotate_empty_file_show_ids(self):
275
tree = self.make_branch_and_tree('.')
276
self.build_tree_contents([('empty', '')])
278
tree.commit('add empty file')
279
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')
280
158
self.assertEqual('', out)
282
160
def test_annotate_nonexistant_file(self):
283
tree = self.make_branch_and_tree('.')
284
self.build_tree(['file'])
161
tree = self.make_branch_and_tree('tree')
162
self.build_tree(['tree/file'])
285
163
tree.add(['file'])
286
164
tree.commit('add a file')
287
out, err = self.run_bzr(['annotate', 'doesnotexist'], retcode=3)
167
out, err = self.run_bzr("annotate doesnotexist", retcode=3)
288
168
self.assertEqual('', out)
289
169
self.assertEqual("bzr: ERROR: doesnotexist is not versioned.\n", err)
291
171
def test_annotate_without_workingtree(self):
292
tree = self.make_branch_and_tree('.')
293
self.build_tree_contents([('empty', '')])
172
tree = self.make_branch_and_tree('branch')
173
self.build_tree_contents([('branch/empty', '')])
294
174
tree.add('empty')
295
175
tree.commit('add empty file')
296
176
bzrdir = tree.branch.bzrdir
297
177
bzrdir.destroy_workingtree()
298
178
self.assertFalse(bzrdir.has_workingtree())
299
out, err = self.run_bzr(['annotate', 'empty'])
181
out, err = self.run_bzr('annotate empty')
300
182
self.assertEqual('', out)
302
def test_annotate_directory(self):
303
"""Test --directory option"""
304
wt = self.make_branch_and_tree('a')
305
self.build_tree_contents([('a/hello.txt', 'my helicopter\n')])
306
wt.add(['hello.txt'])
307
wt.commit('commit', committer='test@user')
308
out, err = self.run_bzr(['annotate', '-d', 'a', 'hello.txt'])
309
self.assertEqualDiff('1 test@us | my helicopter\n', out)