41
45
self.build_tree_contents([('hello.txt', 'my helicopter\n'),
42
46
('nomail.txt', 'nomail\n')])
43
47
wt.add(['hello.txt'])
44
self.revision_id_1 = wt.commit('add hello',
45
committer='test@user',
46
timestamp=1165960000.00, timezone=0)
48
wt.commit('add hello', committer='test@user')
47
49
wt.add(['nomail.txt'])
48
self.revision_id_2 = wt.commit('add nomail',
50
timestamp=1165970000.00, timezone=0)
51
self.build_tree_contents([('hello.txt', 'my helicopter\n'
52
'your helicopter\n')])
53
self.revision_id_3 = wt.commit('mod hello',
54
committer='user@test',
55
timestamp=1166040000.00, timezone=0)
56
self.build_tree_contents([('hello.txt', 'my helicopter\n'
61
self.revision_id_4 = wt.commit('mod hello',
62
committer='user@test',
63
timestamp=1166050000.00, timezone=0)
50
wt.commit('add nomail', committer='no mail')
51
file('hello.txt', 'ab').write('your helicopter')
52
wt.commit('mod hello', committer='user@test')
65
54
def test_help_annotate(self):
66
55
"""Annotate command exists"""
67
out, err = self.run_bzr('--no-plugins annotate --help')
56
out, err = self.run_bzr_captured(['--no-plugins', 'annotate', '--help'])
69
58
def test_annotate_cmd(self):
70
out, err = self.run_bzr('annotate hello.txt')
71
self.assertEqual('', err)
72
self.assertEqualDiff('''\
73
1 test@us | my helicopter
74
3 user@te | your helicopter
79
def test_annotate_cmd_full(self):
80
out, err = self.run_bzr('annotate hello.txt --all')
81
self.assertEqual('', err)
82
self.assertEqualDiff('''\
83
1 test@us | my helicopter
84
3 user@te | your helicopter
86
4 user@te | our helicopters
89
def test_annotate_cmd_long(self):
90
out, err = self.run_bzr('annotate hello.txt --long')
91
self.assertEqual('', err)
92
self.assertEqualDiff('''\
93
1 test@user 20061212 | my helicopter
94
3 user@test 20061213 | your helicopter
95
4 user@test 20061213 | all of
99
def test_annotate_cmd_show_ids(self):
100
out, err = self.run_bzr('annotate hello.txt --show-ids')
101
max_len = max([len(self.revision_id_1),
102
len(self.revision_id_3),
103
len(self.revision_id_4)])
104
self.assertEqual('', err)
105
self.assertEqualDiff('''\
107
%*s | your helicopter
109
%*s | our helicopters
110
''' % (max_len, self.revision_id_1,
111
max_len, self.revision_id_3,
112
max_len, self.revision_id_4,
59
out, err = self.run_bzr_captured(['annotate', 'hello.txt'])
60
self.assertEquals(err, '')
61
self.assertEqualDiff(out, '''\
62
1 test@us | my helicopter
63
3 user@te | your helicopter
117
66
def test_no_mail(self):
118
out, err = self.run_bzr('annotate nomail.txt')
119
self.assertEqual('', err)
120
self.assertEqualDiff('''\
67
out, err = self.run_bzr_captured(['annotate', 'nomail.txt'])
68
self.assertEquals(err, '')
69
self.assertEqualDiff(out, '''\
124
73
def test_annotate_cmd_revision(self):
125
out, err = self.run_bzr('annotate hello.txt -r1')
126
self.assertEqual('', err)
127
self.assertEqualDiff('''\
128
1 test@us | my helicopter
74
out, err = self.run_bzr_captured(['annotate', 'hello.txt', '-r 1'])
75
self.assertEquals(err, '')
76
self.assertEqualDiff(out, '''\
77
1 test@us | my helicopter
131
80
def test_annotate_cmd_revision3(self):
132
out, err = self.run_bzr('annotate hello.txt -r3')
133
self.assertEqual('', err)
134
self.assertEqualDiff('''\
135
1 test@us | my helicopter
136
3 user@te | your helicopter
81
out, err = self.run_bzr_captured(['annotate', 'hello.txt', '-r 3'])
82
self.assertEquals(err, '')
83
self.assertEqualDiff(out, '''\
84
1 test@us | my helicopter
85
3 user@te | your helicopter
139
88
def test_annotate_cmd_unknown_revision(self):
140
out, err = self.run_bzr('annotate hello.txt -r 10',
142
self.assertEqual('', out)
143
self.assertContainsRe(err, 'Requested revision: \'10\' does not exist')
89
out, err = self.run_bzr_captured(['annotate', 'hello.txt', '-r 10'],
91
self.assertEquals(out, '')
92
self.assertContainsRe(err, 'has no revision 10')
145
94
def test_annotate_cmd_two_revisions(self):
146
out, err = self.run_bzr('annotate hello.txt -r1..2',
148
self.assertEqual('', out)
149
self.assertEqual('bzr: ERROR: bzr annotate --revision takes'
150
' exactly one revision identifier\n',
154
class TestSimpleAnnotate(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')])
165
tree.branch.get_config().set_user_option('email', 'current@host2')
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)
172
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
out, err = self.run_bzr('annotate file')
188
def test_annotate_edited_file_show_ids(self):
189
tree = self._setup_edited_file()
190
out, err = self.run_bzr('annotate file --show-ids')
197
def _create_merged_file(self):
198
"""Create a file with a pending merge and local edit."""
199
tree = self.make_branch_and_tree('.')
200
self.build_tree_contents([('file', 'foo\ngam\n')])
202
tree.commit('add file', rev_id="rev1", committer="test@host")
204
self.build_tree_contents([('file', 'foo\nbar\ngam\n')])
205
tree.commit("right", rev_id="rev1.1.1", committer="test@host")
206
tree.pull(tree.branch, True, "rev1")
208
self.build_tree_contents([('file', 'foo\nbaz\ngam\n')])
209
tree.commit("left", rev_id="rev2", committer="test@host")
211
tree.merge_from_branch(tree.branch, "rev1.1.1")
212
# edit the file to be 'resolved' and have a further local edit
213
self.build_tree_contents([('file', 'local\nfoo\nbar\nbaz\ngam\n')])
215
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())
222
'1.1.1 test@ho | bar\n'
224
'1 test@ho | gam\n' % email[:7],
227
def test_annotated_edited_merged_file_ids(self):
228
self._create_merged_file()
229
out, err = self.run_bzr('annotate file --show-ids')
238
def test_annotate_empty_file(self):
239
tree = self.make_branch_and_tree('tree')
240
self.build_tree_contents([('tree/empty', '')])
242
tree.commit('add empty file')
245
out, err = self.run_bzr('annotate empty')
246
self.assertEqual('', out)
248
def test_annotate_empty_file_show_ids(self):
249
tree = self.make_branch_and_tree('tree')
250
self.build_tree_contents([('tree/empty', '')])
252
tree.commit('add empty file')
255
out, err = self.run_bzr(['annotate', '--show-ids', 'empty'])
256
self.assertEqual('', out)
258
def test_annotate_nonexistant_file(self):
259
tree = self.make_branch_and_tree('tree')
260
self.build_tree(['tree/file'])
262
tree.commit('add a file')
265
out, err = self.run_bzr("annotate doesnotexist", retcode=3)
266
self.assertEqual('', out)
267
self.assertEqual("bzr: ERROR: doesnotexist is not versioned.\n", err)
269
def test_annotate_without_workingtree(self):
270
tree = self.make_branch_and_tree('branch')
271
self.build_tree_contents([('branch/empty', '')])
273
tree.commit('add empty file')
274
bzrdir = tree.branch.bzrdir
275
bzrdir.destroy_workingtree()
276
self.assertFalse(bzrdir.has_workingtree())
279
out, err = self.run_bzr('annotate empty')
280
self.assertEqual('', out)
95
out, err = self.run_bzr_captured(['annotate', 'hello.txt', '-r 1..2'],
97
self.assertEquals(out, '')
98
self.assertEquals(err, 'bzr: ERROR: bzr annotate --revision takes'
99
' exactly 1 argument\n')