1
# Copyright (C) 2006 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Whitebox tests for annotate functionality."""
19
from cStringIO import StringIO
31
return [tuple(l.split(' ', 1)) for l in text.splitlines(True)]
34
parent_1 = annotation("""\
43
parent_2 = annotation("""\
53
expected_2_1 = annotation("""\
62
# a: in both, same value, kept
64
# c: in both, same value, kept
65
# d: in both, same value, kept
66
# e: 1 and 2 disagree, so it goes to blahblah
67
# f: in 2, but not in new, so ignored
68
# g: not in 1 or 2, so it goes to blahblah
69
# h: only in parent 2, so 2 gets it
70
expected_1_2_2 = annotation("""\
101
class TestAnnotate(tests.TestCaseWithTransport):
103
def create_merged_trees(self):
104
tree1 = self.make_branch_and_tree('tree1')
105
self.build_tree_contents([('tree1/a', 'first\n')])
106
tree1.add(['a'], ['a-id'])
107
tree1.commit('a', rev_id='rev-1',
108
committer="joe@foo.com",
109
timestamp=1166046000.00, timezone=0)
111
tree2 = tree1.bzrdir.clone('tree2').open_workingtree()
113
self.build_tree_contents([('tree1/a', 'first\nsecond\n')])
114
tree1.commit('b', rev_id='rev-2',
115
committer='joe@foo.com',
116
timestamp=1166046001.00, timezone=0)
118
self.build_tree_contents([('tree2/a', 'first\nthird\n')])
119
tree2.commit('c', rev_id='rev-1_1_1',
120
committer="barry@foo.com",
121
timestamp=1166046002.00, timezone=0)
123
num_conflicts = tree1.merge_from_branch(tree2.branch)
124
self.assertEqual(1, num_conflicts)
126
self.build_tree_contents([('tree1/a',
127
'first\nsecond\nthird\n')])
128
tree1.set_conflicts(conflicts.ConflictList())
129
tree1.commit('merge 2', rev_id='rev-3',
130
committer='sal@foo.com',
131
timestamp=1166046003.00, timezone=0)
134
def create_deeply_merged_trees(self):
135
tree1, tree2 = self.create_merged_trees()
137
tree3 = tree2.bzrdir.clone('tree3').open_workingtree()
139
tree2.commit('noop', rev_id='rev-1.1.2')
140
self.assertEqual(0, tree1.merge_from_branch(tree2.branch))
141
tree1.commit('noop merge', rev_id='rev-4')
143
self.build_tree_contents([('tree3/a', 'first\nthird\nfourth\n')])
144
tree3.commit('four', rev_id='rev-1_1_1_1_1',
145
committer='jerry@foo.com',
146
timestamp=1166046003.00, timezone=0)
148
tree4 = tree3.bzrdir.clone('tree4').open_workingtree()
150
tree3.commit('noop', rev_id='rev-1.1.1.1.2',
151
committer='jerry@foo.com',
152
timestamp=1166046004.00, timezone=0)
153
self.assertEqual(0, tree1.merge_from_branch(tree3.branch))
154
tree1.commit('merge four', rev_id='rev-5')
156
self.build_tree_contents([('tree4/a',
157
'first\nthird\nfourth\nfifth\nsixth\n')])
158
tree4.commit('five and six', rev_id='rev-1_1_1_1_1_1_1',
159
committer='george@foo.com',
160
timestamp=1166046005.00, timezone=0)
161
self.assertEqual(0, tree1.merge_from_branch(tree4.branch))
162
tree1.commit('merge five and six', rev_id='rev-6')
165
def test_annotate_shows_dotted_revnos(self):
166
tree1, tree2 = self.create_merged_trees()
169
annotate.annotate_file(tree1.branch, 'rev-3', 'a-id',
171
self.assertEqualDiff('1 joe@foo | first\n'
172
'2 joe@foo | second\n'
173
'1.1.1 barry@f | third\n',
176
def test_annotate_limits_dotted_revnos(self):
177
"""Annotate should limit dotted revnos to a depth of 12"""
178
tree1 = self.create_deeply_merged_trees()
181
annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
182
to_file=sio, verbose=False, full=False)
183
self.assertEqualDiff('1 joe@foo | first\n'
184
'2 joe@foo | second\n'
185
'1.1.1 barry@f | third\n'
186
'1.1.1.1.1 jerry@f | fourth\n'
187
'1.1.1.1.1.1> george@ | fifth\n'
192
annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
193
to_file=sio, verbose=False, full=True)
194
self.assertEqualDiff('1 joe@foo | first\n'
195
'2 joe@foo | second\n'
196
'1.1.1 barry@f | third\n'
197
'1.1.1.1.1 jerry@f | fourth\n'
198
'1.1.1.1.1.1> george@ | fifth\n'
199
'1.1.1.1.1.1> george@ | sixth\n',
202
# verbose=True shows everything, the full revno, user id, and date
204
annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
205
to_file=sio, verbose=True, full=False)
206
self.assertEqualDiff('1 joe@foo.com 20061213 | first\n'
207
'2 joe@foo.com 20061213 | second\n'
208
'1.1.1 barry@foo.com 20061213 | third\n'
209
'1.1.1.1.1 jerry@foo.com 20061213 | fourth\n'
210
'1.1.1.1.1.1.1 george@foo.com 20061213 | fifth\n'
215
annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
216
to_file=sio, verbose=True, full=True)
217
self.assertEqualDiff('1 joe@foo.com 20061213 | first\n'
218
'2 joe@foo.com 20061213 | second\n'
219
'1.1.1 barry@foo.com 20061213 | third\n'
220
'1.1.1.1.1 jerry@foo.com 20061213 | fourth\n'
221
'1.1.1.1.1.1.1 george@foo.com 20061213 | fifth\n'
222
'1.1.1.1.1.1.1 george@foo.com 20061213 | sixth\n',
225
def test_annotate_show_ids(self):
226
tree1 = self.create_deeply_merged_trees()
229
annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
230
to_file=sio, show_ids=True, full=False)
232
# It looks better with real revision ids :)
233
self.assertEqualDiff(' rev-1 | first\n'
235
' rev-1_1_1 | third\n'
236
' rev-1_1_1_1_1 | fourth\n'
237
'rev-1_1_1_1_1_1_1 | fifth\n'
242
annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
243
to_file=sio, show_ids=True, full=True)
245
self.assertEqualDiff(' rev-1 | first\n'
247
' rev-1_1_1 | third\n'
248
' rev-1_1_1_1_1 | fourth\n'
249
'rev-1_1_1_1_1_1_1 | fifth\n'
250
'rev-1_1_1_1_1_1_1 | sixth\n',
254
class TestReannotate(tests.TestCase):
256
def annotateEqual(self, expected, parents, newlines, revision_id):
257
annotate_list = list(annotate.reannotate(parents, newlines,
259
self.assertEqual(len(expected), len(annotate_list))
260
for e, a in zip(expected, annotate_list):
261
self.assertEqual(e, a)
263
def test_reannotate(self):
264
self.annotateEqual(parent_1, [parent_1], new_1, 'blahblah')
265
self.annotateEqual(expected_2_1, [parent_2], new_1, 'blahblah')
266
self.annotateEqual(expected_1_2_2, [parent_1, parent_2], new_2,