99
101
rev2_tree = knit3_repo.revision_tree('rev2')
100
102
self.assertEqual('rev1', rev2_tree.inventory.root.revision)
104
def do_test_fetch_to_rich_root_sets_parents_correctly(self, result,
105
snapshots, root_id=ROOT_ID, allow_lefthand_ghost=False):
106
"""Assert that result is the parents of 'tip' after fetching snapshots.
108
This helper constructs a 1.9 format source, and a test-format target
109
and fetches the result of building snapshots in the source, then
110
asserts that the parents of tip are result.
112
:param result: A parents list for the inventories.get_parent_map call.
113
:param snapshots: An iterable of snapshot parameters for
114
BranchBuilder.build_snapshot.
116
# This overlaps slightly with the tests for commit builder about graph
119
repo = self.make_repository('target')
120
remote_format = isinstance(repo, remote.RemoteRepository)
121
if not repo._format.rich_root_data and not remote_format:
122
return # not relevant
123
builder = self.make_branch_builder('source', format='1.9')
124
builder.start_series()
125
for revision_id, parent_ids, actions in snapshots:
126
builder.build_snapshot(revision_id, parent_ids, actions,
127
allow_leftmost_as_ghost=allow_lefthand_ghost)
128
builder.finish_series()
129
source = builder.get_branch()
130
if remote_format and not repo._format.rich_root_data:
131
# use a manual rich root format to ensure the code path is tested.
132
repo = self.make_repository('remote-target',
133
format='1.9-rich-root')
135
self.addCleanup(repo.unlock)
136
repo.fetch(source.repository)
137
self.assertEqual(result,
138
repo.texts.get_parent_map([(root_id, 'tip')])[(root_id, 'tip')])
140
def test_fetch_to_rich_root_set_parent_no_parents(self):
141
# No parents rev -> No parents
142
self.do_test_fetch_to_rich_root_sets_parents_correctly((),
143
[('tip', None, [('add', ('', ROOT_ID, 'directory', ''))]),
146
def test_fetch_to_rich_root_set_parent_1_parent(self):
147
# 1 parent rev -> 1 parent
148
self.do_test_fetch_to_rich_root_sets_parents_correctly(
149
((ROOT_ID, 'base'),),
150
[('base', None, [('add', ('', ROOT_ID, 'directory', ''))]),
154
def test_fetch_to_rich_root_set_parent_1_ghost_parent(self):
155
# 1 ghost parent -> No parents
156
self.do_test_fetch_to_rich_root_sets_parents_correctly((),
157
[('tip', ['ghost'], [('add', ('', ROOT_ID, 'directory', ''))]),
158
], allow_lefthand_ghost=True)
160
def test_fetch_to_rich_root_set_parent_2_head_parents(self):
161
# 2 parents both heads -> 2 parents
162
self.do_test_fetch_to_rich_root_sets_parents_correctly(
163
((ROOT_ID, 'left'), (ROOT_ID, 'right')),
164
[('base', None, [('add', ('', ROOT_ID, 'directory', ''))]),
166
('right', ['base'], []),
167
('tip', ['left', 'right'], []),
170
def test_fetch_to_rich_root_set_parent_2_parents_1_head(self):
171
# 2 parents one head -> 1 parent
172
self.do_test_fetch_to_rich_root_sets_parents_correctly(
173
((ROOT_ID, 'right'),),
174
[('left', None, [('add', ('', ROOT_ID, 'directory', ''))]),
176
('tip', ['left', 'right'], []),
179
def test_fetch_to_rich_root_set_parent_1_parent_different_id_gone(self):
180
# 1 parent different fileid, ours missing -> no parents
181
self.do_test_fetch_to_rich_root_sets_parents_correctly(
183
[('base', None, [('add', ('', ROOT_ID, 'directory', ''))]),
184
('tip', None, [('unversion', ROOT_ID),
185
('add', ('', 'my-root', 'directory', '')),
187
], root_id='my-root')
189
def test_fetch_to_rich_root_set_parent_1_parent_different_id_moved(self):
190
# 1 parent different fileid, ours moved -> 1 parent
191
# (and that parent honours the changing revid of the other location)
192
self.do_test_fetch_to_rich_root_sets_parents_correctly(
193
(('my-root', 'origin'),),
194
[('origin', None, [('add', ('', ROOT_ID, 'directory', '')),
195
('add', ('child', 'my-root', 'directory', ''))]),
197
('tip', None, [('unversion', 'my-root'),
198
('unversion', ROOT_ID),
199
('add', ('', 'my-root', 'directory', '')),
201
], root_id='my-root')
203
def test_fetch_to_rich_root_set_parent_2_parent_1_different_id_gone(self):
204
# 2 parents, 1 different fileid, our second missing -> 1 parent
205
self.do_test_fetch_to_rich_root_sets_parents_correctly(
206
(('my-root', 'right'),),
207
[('base', None, [('add', ('', ROOT_ID, 'directory', ''))]),
208
('right', None, [('unversion', ROOT_ID),
209
('add', ('', 'my-root', 'directory', ''))]),
210
('tip', ['base', 'right'], [('unversion', ROOT_ID),
211
('add', ('', 'my-root', 'directory', '')),
213
], root_id='my-root')
215
def test_fetch_to_rich_root_set_parent_2_parent_2_different_id_moved(self):
216
# 2 parents, 1 different fileid, our second moved -> 2 parent
217
# (and that parent honours the changing revid of the other location)
218
self.do_test_fetch_to_rich_root_sets_parents_correctly(
219
(('my-root', 'right'),),
220
# 'my-root' at 'child'.
221
[('origin', None, [('add', ('', ROOT_ID, 'directory', '')),
222
('add', ('child', 'my-root', 'directory', ''))]),
225
('right', None, [('unversion', 'my-root'),
226
('unversion', ROOT_ID),
227
('add', ('', 'my-root', 'directory', ''))]),
228
('tip', ['base', 'right'], [('unversion', 'my-root'),
229
('unversion', ROOT_ID),
230
('add', ('', 'my-root', 'directory', '')),
232
], root_id='my-root')
102
234
def test_fetch_all_from_self(self):
103
235
tree = self.make_branch_and_tree('.')
104
236
rev_id = tree.commit('one')