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,
86
86
knit3_repo = b_bzrdir.open_repository()
87
87
rev1_tree = knit3_repo.revision_tree(rev1)
90
lines = rev1_tree.get_file_lines(u'', rev1_tree.get_root_id())
88
with rev1_tree.lock_read():
89
lines = rev1_tree.get_file_lines(u'')
93
90
self.assertEqual([], lines)
94
91
b_branch = b_bzrdir.create_branch()
95
92
b_branch.pull(tree_a.branch)
100
97
tree_b = b_branch.create_checkout('b', lightweight=True)
101
98
except errors.NotLocalUrl:
102
99
raise TestSkipped("cannot make working tree with transport %r"
103
% b_bzrdir.transport)
100
% b_bzrdir.transport)
104
101
rev2 = tree_b.commit('no change')
105
102
rev2_tree = knit3_repo.revision_tree(rev2)
108
rev2_tree.get_file_revision(u'', rev2_tree.get_root_id()))
103
self.assertEqual(rev1, rev2_tree.get_file_revision(u''))
110
105
def do_test_fetch_to_rich_root_sets_parents_correctly(self, result,
111
snapshots, root_id=ROOT_ID, allow_lefthand_ghost=False):
106
snapshots, root_id=ROOT_ID, allow_lefthand_ghost=False):
112
107
"""Assert that result is the parents of b'tip' after fetching snapshots.
114
109
This helper constructs a 1.9 format source, and a test-format target
125
120
repo = self.make_repository('target')
126
121
remote_format = isinstance(repo, remote.RemoteRepository)
127
122
if not repo._format.rich_root_data and not remote_format:
128
return # not relevant
123
return # not relevant
129
124
if not repo._format.supports_full_versioned_files:
130
125
raise TestNotApplicable(
131
126
'format does not support full versioned files')
133
128
builder.start_series()
134
129
for revision_id, parent_ids, actions in snapshots:
135
130
builder.build_snapshot(parent_ids, actions,
136
allow_leftmost_as_ghost=allow_lefthand_ghost,
137
revision_id=revision_id)
131
allow_leftmost_as_ghost=allow_lefthand_ghost,
132
revision_id=revision_id)
138
133
builder.finish_series()
139
134
source = builder.get_branch()
140
135
if remote_format and not repo._format.rich_root_data:
141
136
# use a manual rich root format to ensure the code path is tested.
142
137
repo = self.make_repository('remote-target',
143
format='1.9-rich-root')
138
format='1.9-rich-root')
144
139
repo.lock_write()
145
140
self.addCleanup(repo.unlock)
146
141
repo.fetch(source.repository)
147
142
graph = repo.get_file_graph()
148
143
self.assertEqual(result,
149
graph.get_parent_map([(root_id, b'tip')])[(root_id, b'tip')])
144
graph.get_parent_map([(root_id, b'tip')])[(root_id, b'tip')])
151
146
def test_fetch_to_rich_root_set_parent_no_parents(self):
152
147
# No parents rev -> No parents
153
148
self.do_test_fetch_to_rich_root_sets_parents_correctly((),
154
[(b'tip', None, [('add', ('', ROOT_ID, 'directory', ''))]),
149
[(b'tip', None, [('add', ('', ROOT_ID, 'directory', ''))]),
157
152
def test_fetch_to_rich_root_set_parent_1_parent(self):
158
153
# 1 parent rev -> 1 parent
160
155
((ROOT_ID, b'base'),),
161
156
[(b'base', None, [('add', ('', ROOT_ID, 'directory', ''))]),
162
157
(b'tip', None, []),
165
160
def test_fetch_to_rich_root_set_parent_1_ghost_parent(self):
166
161
# 1 ghost parent -> No parents
167
162
if not self.repository_format.supports_ghosts:
168
163
raise TestNotApplicable("repository format does not support "
170
165
self.do_test_fetch_to_rich_root_sets_parents_correctly((),
171
[(b'tip', [b'ghost'], [('add', ('', ROOT_ID, 'directory', ''))]),
172
], allow_lefthand_ghost=True)
166
[(b'tip', [b'ghost'], [('add', ('', ROOT_ID, 'directory', ''))]),
167
], allow_lefthand_ghost=True)
174
169
def test_fetch_to_rich_root_set_parent_2_head_parents(self):
175
170
# 2 parents both heads -> 2 parents
179
174
(b'left', None, []),
180
175
(b'right', [b'base'], []),
181
176
(b'tip', [b'left', b'right'], []),
184
179
def test_fetch_to_rich_root_set_parent_2_parents_1_head(self):
185
180
# 2 parents one head -> 1 parent
188
183
[(b'left', None, [('add', ('', ROOT_ID, 'directory', ''))]),
189
184
(b'right', None, []),
190
185
(b'tip', [b'left', b'right'], []),
193
188
def test_fetch_to_rich_root_set_parent_1_parent_different_id_gone(self):
194
189
# 1 parent different fileid, ours missing -> no parents
197
192
[(b'base', None, [('add', ('', ROOT_ID, 'directory', ''))]),
198
193
(b'tip', None, [('unversion', ''),
199
('add', ('', b'my-root', 'directory', '')),
201
], root_id=b'my-root')
194
('add', ('', b'my-root', 'directory', '')),
196
], root_id=b'my-root')
203
198
def test_fetch_to_rich_root_set_parent_1_parent_different_id_moved(self):
204
199
# 1 parent different fileid, ours moved -> 1 parent
206
201
self.do_test_fetch_to_rich_root_sets_parents_correctly(
207
202
((b'my-root', b'origin'),),
208
203
[(b'origin', None, [('add', ('', ROOT_ID, 'directory', '')),
209
('add', ('child', b'my-root', 'directory', ''))]),
204
('add', ('child', b'my-root', 'directory', ''))]),
210
205
(b'base', None, []),
211
206
(b'tip', None, [('unversion', 'child'),
214
('add', ('', b'my-root', 'directory', '')),
216
], root_id=b'my-root')
209
('add', ('', b'my-root', 'directory', '')),
211
], root_id=b'my-root')
218
213
def test_fetch_to_rich_root_set_parent_2_parent_1_different_id_gone(self):
219
214
# 2 parents, 1 different fileid, our second missing -> 1 parent
221
216
((b'my-root', b'right'),),
222
217
[(b'base', None, [('add', ('', ROOT_ID, 'directory', ''))]),
223
218
(b'right', None, [('unversion', ''),
224
('add', ('', b'my-root', 'directory', ''))]),
219
('add', ('', b'my-root', 'directory', ''))]),
225
220
(b'tip', [b'base', b'right'], [('unversion', ''),
226
('add', ('', b'my-root', 'directory', '')),
228
], root_id=b'my-root')
221
('add', ('', b'my-root', 'directory', '')),
223
], root_id=b'my-root')
230
225
def test_fetch_to_rich_root_set_parent_2_parent_2_different_id_moved(self):
231
226
# 2 parents, 1 different fileid, our second moved -> 2 parent
234
229
((b'my-root', b'right'),),
235
230
# b'my-root' at 'child'.
236
231
[(b'origin', None, [('add', ('', ROOT_ID, 'directory', '')),
237
('add', ('child', b'my-root', 'directory', ''))]),
232
('add', ('child', b'my-root', 'directory', ''))]),
238
233
(b'base', None, []),
240
235
(b'right', None, [('unversion', 'child'),
243
('add', ('', b'my-root', 'directory', ''))]),
238
('add', ('', b'my-root', 'directory', ''))]),
244
239
(b'tip', [b'base', b'right'], [('unversion', ''),
245
('unversion', 'child'),
247
('add', ('', b'my-root', 'directory', '')),
249
], root_id=b'my-root')
240
('unversion', 'child'),
242
('add', ('', b'my-root', 'directory', '')),
244
], root_id=b'my-root')
251
246
def test_fetch_all_from_self(self):
252
247
tree = self.make_branch_and_tree('.')
283
278
repo.sign_revision(rev1, gpg.LoopbackGPGStrategy(None))
284
279
except errors.UnsupportedOperation:
285
280
self.assertFalse(repo._format.supports_revision_signatures)
286
raise TestNotApplicable("repository format does not support signatures")
281
raise TestNotApplicable(
282
"repository format does not support signatures")
287
283
repo.commit_write_group()
289
285
return repo, rev1
323
319
def make_simple_branch_with_ghost(self):
324
320
if not self.repository_format.supports_ghosts:
325
321
raise TestNotApplicable("repository format does not support "
327
323
builder = self.make_branch_builder('source')
328
324
builder.start_series()
329
325
a_revid = builder.build_snapshot(None, [
360
356
# causes weird problems with 'lock_not_held' later on...
361
357
target.lock_read()
362
358
self.knownFailure('some repositories fail to fetch'
363
' via the smart server because of locking issues.')
359
' via the smart server because of locking issues.')
365
361
def test_fetch_from_smart_with_ghost(self):
366
362
trans = self.make_smart_server('source')