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