4454.3.68
by John Arbash Meinel
Add some tests that we can handle doing annotations even when |
1 |
# Copyright (C) 2009 Canonical Ltd
|
2 |
#
|
|
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.
|
|
7 |
#
|
|
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.
|
|
12 |
#
|
|
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
16 |
||
17 |
"""Tests for interface conformance of 'WorkingTree.annotate_iter'"""
|
|
18 |
||
4523.1.4
by Martin Pool
Rename remaining *_implementations tests |
19 |
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree |
4454.3.68
by John Arbash Meinel
Add some tests that we can handle doing annotations even when |
20 |
|
21 |
||
22 |
class TestAnnotateIter(TestCaseWithWorkingTree): |
|
23 |
||
24 |
def make_single_rev_tree(self): |
|
25 |
builder = self.make_branch_builder('branch') |
|
26 |
builder.build_snapshot('rev-1', None, [ |
|
27 |
('add', ('', 'TREE_ROOT', 'directory', None)), |
|
28 |
('add', ('file', 'file-id', 'file', 'initial content\n')), |
|
29 |
])
|
|
30 |
b = builder.get_branch() |
|
31 |
tree = b.create_checkout('tree', lightweight=True) |
|
32 |
tree.lock_read() |
|
33 |
self.addCleanup(tree.unlock) |
|
34 |
return tree |
|
35 |
||
36 |
def test_annotate_same_as_parent(self): |
|
37 |
tree = self.make_single_rev_tree() |
|
38 |
annotations = tree.annotate_iter('file-id') |
|
39 |
self.assertEqual([('rev-1', 'initial content\n')], |
|
40 |
annotations) |
|
41 |
||
42 |
def test_annotate_mod_from_parent(self): |
|
43 |
tree = self.make_single_rev_tree() |
|
44 |
self.build_tree_contents([('tree/file', |
|
45 |
'initial content\nnew content\n')]) |
|
46 |
annotations = tree.annotate_iter('file-id') |
|
47 |
self.assertEqual([('rev-1', 'initial content\n'), |
|
48 |
('current:', 'new content\n'), |
|
49 |
], annotations) |
|
50 |
||
51 |
def test_annotate_merge_parents(self): |
|
52 |
builder = self.make_branch_builder('branch') |
|
53 |
builder.start_series() |
|
54 |
builder.build_snapshot('rev-1', None, [ |
|
55 |
('add', ('', 'TREE_ROOT', 'directory', None)), |
|
56 |
('add', ('file', 'file-id', 'file', 'initial content\n')), |
|
57 |
])
|
|
58 |
builder.build_snapshot('rev-2', ['rev-1'], [ |
|
59 |
('modify', ('file-id', 'initial content\ncontent in 2\n')), |
|
60 |
])
|
|
61 |
builder.build_snapshot('rev-3', ['rev-1'], [ |
|
62 |
('modify', ('file-id', 'initial content\ncontent in 3\n')), |
|
63 |
])
|
|
64 |
builder.finish_series() |
|
65 |
b = builder.get_branch() |
|
66 |
tree = b.create_checkout('tree', revision_id='rev-2', lightweight=True) |
|
67 |
tree.lock_write() |
|
68 |
self.addCleanup(tree.unlock) |
|
69 |
tree.set_parent_ids(['rev-2', 'rev-3']) |
|
70 |
self.build_tree_contents([('tree/file', |
|
71 |
'initial content\ncontent in 2\n' |
|
72 |
'content in 3\nnew content\n')]) |
|
73 |
annotations = tree.annotate_iter('file-id') |
|
74 |
self.assertEqual([('rev-1', 'initial content\n'), |
|
75 |
('rev-2', 'content in 2\n'), |
|
76 |
('rev-3', 'content in 3\n'), |
|
77 |
('current:', 'new content\n'), |
|
78 |
], annotations) |
|
79 |
||
80 |
def test_annotate_merge_parent_no_file(self): |
|
81 |
builder = self.make_branch_builder('branch') |
|
82 |
builder.start_series() |
|
83 |
builder.build_snapshot('rev-1', None, [ |
|
84 |
('add', ('', 'TREE_ROOT', 'directory', None)), |
|
85 |
])
|
|
86 |
builder.build_snapshot('rev-2', ['rev-1'], [ |
|
87 |
('add', ('file', 'file-id', 'file', 'initial content\n')), |
|
88 |
])
|
|
89 |
builder.build_snapshot('rev-3', ['rev-1'], []) |
|
90 |
builder.finish_series() |
|
91 |
b = builder.get_branch() |
|
92 |
tree = b.create_checkout('tree', revision_id='rev-2', lightweight=True) |
|
93 |
tree.lock_write() |
|
94 |
self.addCleanup(tree.unlock) |
|
95 |
tree.set_parent_ids(['rev-2', 'rev-3']) |
|
96 |
self.build_tree_contents([('tree/file', |
|
97 |
'initial content\nnew content\n')]) |
|
98 |
annotations = tree.annotate_iter('file-id') |
|
99 |
self.assertEqual([('rev-2', 'initial content\n'), |
|
100 |
('current:', 'new content\n'), |
|
101 |
], annotations) |
|
102 |
||
103 |
def test_annotate_merge_parent_was_directory(self): |
|
104 |
builder = self.make_branch_builder('branch') |
|
105 |
builder.start_series() |
|
106 |
builder.build_snapshot('rev-1', None, [ |
|
107 |
('add', ('', 'TREE_ROOT', 'directory', None)), |
|
108 |
])
|
|
109 |
builder.build_snapshot('rev-2', ['rev-1'], [ |
|
110 |
('add', ('file', 'file-id', 'file', 'initial content\n')), |
|
111 |
])
|
|
112 |
builder.build_snapshot('rev-3', ['rev-1'], [ |
|
113 |
('add', ('a_dir', 'file-id', 'directory', None)), |
|
114 |
])
|
|
115 |
builder.finish_series() |
|
116 |
b = builder.get_branch() |
|
117 |
tree = b.create_checkout('tree', revision_id='rev-2', lightweight=True) |
|
118 |
tree.lock_write() |
|
119 |
self.addCleanup(tree.unlock) |
|
120 |
tree.set_parent_ids(['rev-2', 'rev-3']) |
|
121 |
self.build_tree_contents([('tree/file', |
|
122 |
'initial content\nnew content\n')]) |
|
123 |
annotations = tree.annotate_iter('file-id') |
|
124 |
self.assertEqual([('rev-2', 'initial content\n'), |
|
125 |
('current:', 'new content\n'), |
|
126 |
], annotations) |
|
4454.3.69
by John Arbash Meinel
Add a couple more annotate-after-merge tests for WT. |
127 |
|
128 |
def test_annotate_same_as_merge_parent(self): |
|
129 |
builder = self.make_branch_builder('branch') |
|
130 |
builder.start_series() |
|
131 |
builder.build_snapshot('rev-1', None, [ |
|
132 |
('add', ('', 'TREE_ROOT', 'directory', None)), |
|
133 |
('add', ('file', 'file-id', 'file', 'initial content\n')), |
|
134 |
])
|
|
135 |
builder.build_snapshot('rev-2', ['rev-1'], [ |
|
136 |
])
|
|
137 |
builder.build_snapshot('rev-3', ['rev-1'], [ |
|
138 |
('modify', ('file-id', 'initial content\ncontent in 3\n')), |
|
139 |
])
|
|
140 |
builder.finish_series() |
|
141 |
b = builder.get_branch() |
|
142 |
tree = b.create_checkout('tree', revision_id='rev-2', lightweight=True) |
|
143 |
tree.lock_write() |
|
144 |
self.addCleanup(tree.unlock) |
|
145 |
tree.set_parent_ids(['rev-2', 'rev-3']) |
|
146 |
self.build_tree_contents([('tree/file', |
|
147 |
'initial content\ncontent in 3\n')]) |
|
148 |
annotations = tree.annotate_iter('file-id') |
|
149 |
self.assertEqual([('rev-1', 'initial content\n'), |
|
150 |
('rev-3', 'content in 3\n'), |
|
151 |
], annotations) |
|
152 |
||
153 |
def test_annotate_same_as_merge_parent_supersedes(self): |
|
154 |
builder = self.make_branch_builder('branch') |
|
155 |
builder.start_series() |
|
156 |
builder.build_snapshot('rev-1', None, [ |
|
157 |
('add', ('', 'TREE_ROOT', 'directory', None)), |
|
158 |
('add', ('file', 'file-id', 'file', 'initial content\n')), |
|
159 |
])
|
|
160 |
builder.build_snapshot('rev-2', ['rev-1'], [ |
|
161 |
('modify', ('file-id', 'initial content\nnew content\n')), |
|
162 |
])
|
|
163 |
builder.build_snapshot('rev-3', ['rev-2'], [ |
|
164 |
('modify', ('file-id', 'initial content\ncontent in 3\n')), |
|
165 |
])
|
|
166 |
builder.build_snapshot('rev-4', ['rev-3'], [ |
|
167 |
('modify', ('file-id', 'initial content\nnew content\n')), |
|
168 |
])
|
|
169 |
# In this case, the content locally is the same as content in basis
|
|
170 |
# tree, but the merge revision states that *it* should win
|
|
171 |
builder.finish_series() |
|
172 |
b = builder.get_branch() |
|
173 |
tree = b.create_checkout('tree', revision_id='rev-2', lightweight=True) |
|
174 |
tree.lock_write() |
|
175 |
self.addCleanup(tree.unlock) |
|
176 |
tree.set_parent_ids(['rev-2', 'rev-4']) |
|
177 |
annotations = tree.annotate_iter('file-id') |
|
178 |
self.assertEqual([('rev-1', 'initial content\n'), |
|
179 |
('rev-4', 'new content\n'), |
|
180 |
], annotations) |
|
181 |