46
46
# fetch with a default limit (grab everything)
47
47
repo = self.make_repository('b')
48
48
if (tree_a.branch.repository.supports_rich_root() and not
49
repo.supports_rich_root()):
49
repo.supports_rich_root()):
50
50
raise TestSkipped('Cannot fetch from model2 to model1')
51
51
repo.fetch(tree_a.branch.repository,
100
100
tree_b = b_branch.create_checkout('b', lightweight=True)
101
101
except errors.NotLocalUrl:
102
102
raise TestSkipped("cannot make working tree with transport %r"
103
% b_bzrdir.transport)
103
% b_bzrdir.transport)
104
104
rev2 = tree_b.commit('no change')
105
105
rev2_tree = knit3_repo.revision_tree(rev2)
106
106
self.assertEqual(
108
108
rev2_tree.get_file_revision(u'', rev2_tree.get_root_id()))
110
110
def do_test_fetch_to_rich_root_sets_parents_correctly(self, result,
111
snapshots, root_id=ROOT_ID, allow_lefthand_ghost=False):
111
snapshots, root_id=ROOT_ID, allow_lefthand_ghost=False):
112
112
"""Assert that result is the parents of b'tip' after fetching snapshots.
114
114
This helper constructs a 1.9 format source, and a test-format target
125
125
repo = self.make_repository('target')
126
126
remote_format = isinstance(repo, remote.RemoteRepository)
127
127
if not repo._format.rich_root_data and not remote_format:
128
return # not relevant
128
return # not relevant
129
129
if not repo._format.supports_full_versioned_files:
130
130
raise TestNotApplicable(
131
131
'format does not support full versioned files')
133
133
builder.start_series()
134
134
for revision_id, parent_ids, actions in snapshots:
135
135
builder.build_snapshot(parent_ids, actions,
136
allow_leftmost_as_ghost=allow_lefthand_ghost,
137
revision_id=revision_id)
136
allow_leftmost_as_ghost=allow_lefthand_ghost,
137
revision_id=revision_id)
138
138
builder.finish_series()
139
139
source = builder.get_branch()
140
140
if remote_format and not repo._format.rich_root_data:
141
141
# use a manual rich root format to ensure the code path is tested.
142
142
repo = self.make_repository('remote-target',
143
format='1.9-rich-root')
143
format='1.9-rich-root')
144
144
repo.lock_write()
145
145
self.addCleanup(repo.unlock)
146
146
repo.fetch(source.repository)
147
147
graph = repo.get_file_graph()
148
148
self.assertEqual(result,
149
graph.get_parent_map([(root_id, b'tip')])[(root_id, b'tip')])
149
graph.get_parent_map([(root_id, b'tip')])[(root_id, b'tip')])
151
151
def test_fetch_to_rich_root_set_parent_no_parents(self):
152
152
# No parents rev -> No parents
153
153
self.do_test_fetch_to_rich_root_sets_parents_correctly((),
154
[(b'tip', None, [('add', ('', ROOT_ID, 'directory', ''))]),
154
[(b'tip', None, [('add', ('', ROOT_ID, 'directory', ''))]),
157
157
def test_fetch_to_rich_root_set_parent_1_parent(self):
158
158
# 1 parent rev -> 1 parent
160
160
((ROOT_ID, b'base'),),
161
161
[(b'base', None, [('add', ('', ROOT_ID, 'directory', ''))]),
162
162
(b'tip', None, []),
165
165
def test_fetch_to_rich_root_set_parent_1_ghost_parent(self):
166
166
# 1 ghost parent -> No parents
167
167
if not self.repository_format.supports_ghosts:
168
168
raise TestNotApplicable("repository format does not support "
170
170
self.do_test_fetch_to_rich_root_sets_parents_correctly((),
171
[(b'tip', [b'ghost'], [('add', ('', ROOT_ID, 'directory', ''))]),
172
], allow_lefthand_ghost=True)
171
[(b'tip', [b'ghost'], [('add', ('', ROOT_ID, 'directory', ''))]),
172
], allow_lefthand_ghost=True)
174
174
def test_fetch_to_rich_root_set_parent_2_head_parents(self):
175
175
# 2 parents both heads -> 2 parents
179
179
(b'left', None, []),
180
180
(b'right', [b'base'], []),
181
181
(b'tip', [b'left', b'right'], []),
184
184
def test_fetch_to_rich_root_set_parent_2_parents_1_head(self):
185
185
# 2 parents one head -> 1 parent
188
188
[(b'left', None, [('add', ('', ROOT_ID, 'directory', ''))]),
189
189
(b'right', None, []),
190
190
(b'tip', [b'left', b'right'], []),
193
193
def test_fetch_to_rich_root_set_parent_1_parent_different_id_gone(self):
194
194
# 1 parent different fileid, ours missing -> no parents
197
197
[(b'base', None, [('add', ('', ROOT_ID, 'directory', ''))]),
198
198
(b'tip', None, [('unversion', ''),
199
('add', ('', b'my-root', 'directory', '')),
201
], root_id=b'my-root')
199
('add', ('', b'my-root', 'directory', '')),
201
], root_id=b'my-root')
203
203
def test_fetch_to_rich_root_set_parent_1_parent_different_id_moved(self):
204
204
# 1 parent different fileid, ours moved -> 1 parent
206
206
self.do_test_fetch_to_rich_root_sets_parents_correctly(
207
207
((b'my-root', b'origin'),),
208
208
[(b'origin', None, [('add', ('', ROOT_ID, 'directory', '')),
209
('add', ('child', b'my-root', 'directory', ''))]),
209
('add', ('child', b'my-root', 'directory', ''))]),
210
210
(b'base', None, []),
211
211
(b'tip', None, [('unversion', 'child'),
214
('add', ('', b'my-root', 'directory', '')),
216
], root_id=b'my-root')
214
('add', ('', b'my-root', 'directory', '')),
216
], root_id=b'my-root')
218
218
def test_fetch_to_rich_root_set_parent_2_parent_1_different_id_gone(self):
219
219
# 2 parents, 1 different fileid, our second missing -> 1 parent
221
221
((b'my-root', b'right'),),
222
222
[(b'base', None, [('add', ('', ROOT_ID, 'directory', ''))]),
223
223
(b'right', None, [('unversion', ''),
224
('add', ('', b'my-root', 'directory', ''))]),
224
('add', ('', b'my-root', 'directory', ''))]),
225
225
(b'tip', [b'base', b'right'], [('unversion', ''),
226
('add', ('', b'my-root', 'directory', '')),
228
], root_id=b'my-root')
226
('add', ('', b'my-root', 'directory', '')),
228
], root_id=b'my-root')
230
230
def test_fetch_to_rich_root_set_parent_2_parent_2_different_id_moved(self):
231
231
# 2 parents, 1 different fileid, our second moved -> 2 parent
234
234
((b'my-root', b'right'),),
235
235
# b'my-root' at 'child'.
236
236
[(b'origin', None, [('add', ('', ROOT_ID, 'directory', '')),
237
('add', ('child', b'my-root', 'directory', ''))]),
237
('add', ('child', b'my-root', 'directory', ''))]),
238
238
(b'base', None, []),
240
240
(b'right', None, [('unversion', 'child'),
243
('add', ('', b'my-root', 'directory', ''))]),
243
('add', ('', b'my-root', 'directory', ''))]),
244
244
(b'tip', [b'base', b'right'], [('unversion', ''),
245
('unversion', 'child'),
247
('add', ('', b'my-root', 'directory', '')),
249
], root_id=b'my-root')
245
('unversion', 'child'),
247
('add', ('', b'my-root', 'directory', '')),
249
], root_id=b'my-root')
251
251
def test_fetch_all_from_self(self):
252
252
tree = self.make_branch_and_tree('.')
283
283
repo.sign_revision(rev1, gpg.LoopbackGPGStrategy(None))
284
284
except errors.UnsupportedOperation:
285
285
self.assertFalse(repo._format.supports_revision_signatures)
286
raise TestNotApplicable("repository format does not support signatures")
286
raise TestNotApplicable(
287
"repository format does not support signatures")
287
288
repo.commit_write_group()
289
290
return repo, rev1
323
324
def make_simple_branch_with_ghost(self):
324
325
if not self.repository_format.supports_ghosts:
325
326
raise TestNotApplicable("repository format does not support "
327
328
builder = self.make_branch_builder('source')
328
329
builder.start_series()
329
330
a_revid = builder.build_snapshot(None, [
360
361
# causes weird problems with 'lock_not_held' later on...
361
362
target.lock_read()
362
363
self.knownFailure('some repositories fail to fetch'
363
' via the smart server because of locking issues.')
364
' via the smart server because of locking issues.')
365
366
def test_fetch_from_smart_with_ghost(self):
366
367
trans = self.make_smart_server('source')