119
114
def test_fetch_revisions(self):
120
115
"""Test fetch-revision operation."""
121
get_transport(self.get_url()).mkdir('b1')
122
get_transport(self.get_url()).mkdir('b2')
123
116
wt = self.make_branch_and_tree('b1')
125
b2 = self.make_branch('b2')
126
file('b1/foo', 'w').write('hello')
118
self.build_tree_contents([('b1/foo', 'hello')])
127
119
wt.add(['foo'], ['foo-id'])
128
120
wt.commit('lala!', rev_id='revision-1', allow_pointless=False)
130
mutter('start fetch')
122
b2 = self.make_branch('b2')
131
123
self.assertEqual((1, []), b2.fetch(b1))
133
125
rev = b2.repository.get_revision('revision-1')
153
145
def get_unbalanced_tree_pair(self):
154
146
"""Return two branches, a and b, with one file in a."""
155
get_transport(self.get_url()).mkdir('a')
156
147
tree_a = self.make_branch_and_tree('a')
157
file('a/b', 'wb').write('b')
148
self.build_tree_contents([('a/b', 'b')])
159
150
tree_a.commit("silly commit", rev_id='A')
161
get_transport(self.get_url()).mkdir('b')
162
152
tree_b = self.make_branch_and_tree('b')
163
153
return tree_a, tree_b
168
158
tree_b.branch.repository.fetch(tree_a.branch.repository)
169
159
return tree_a, tree_b
171
def test_clone_branch(self):
172
"""Copy the stores from one branch to another"""
173
tree_a, tree_b = self.get_balanced_branch_pair()
174
tree_b.commit("silly commit")
176
# this fails to test that the history from a was not used.
177
dir_c = tree_a.bzrdir.clone('c', basis=tree_b.bzrdir)
178
self.assertEqual(tree_a.branch.revision_history(),
179
dir_c.open_branch().revision_history())
181
161
def test_clone_partial(self):
182
162
"""Copy only part of the history of a branch."""
183
163
# TODO: RBC 20060208 test with a revision not on revision-history.
184
164
# what should that behaviour be ? Emailed the list.
165
# First, make a branch with two commits.
185
166
wt_a = self.make_branch_and_tree('a')
186
167
self.build_tree(['a/one'])
187
168
wt_a.add(['one'])
189
170
self.build_tree(['a/two'])
190
171
wt_a.add(['two'])
191
172
wt_a.commit('commit two', rev_id='2')
173
# Now make a copy of the repository.
192
174
repo_b = self.make_repository('b')
193
wt_a.bzrdir.open_repository().copy_content_into(repo_b)
194
br_b = wt_a.bzrdir.open_branch().clone(repo_b.bzrdir, revision_id='1')
175
wt_a.branch.repository.copy_content_into(repo_b)
176
# wt_a might be a lightweight checkout, so get a hold of the actual
177
# branch (because you can't do a partial clone of a lightweight
179
branch = wt_a.branch.bzrdir.open_branch()
180
# Then make a branch where the new repository is, but specify a revision
181
# ID. The new branch's history will stop at the specified revision.
182
br_b = branch.clone(repo_b.bzrdir, revision_id='1')
195
183
self.assertEqual('1', br_b.last_revision())
197
185
def test_sprout_partial(self):
205
193
wt_a.add(['two'])
206
194
wt_a.commit('commit two', rev_id='2')
207
195
repo_b = self.make_repository('b')
208
wt_a.bzrdir.open_repository().copy_content_into(repo_b)
209
br_b = wt_a.bzrdir.open_branch().sprout(repo_b.bzrdir, revision_id='1')
196
repo_a = wt_a.branch.repository
197
repo_a.copy_content_into(repo_b)
198
br_b = wt_a.branch.sprout(repo_b.bzrdir, revision_id='1')
210
199
self.assertEqual('1', br_b.last_revision())
212
201
def get_parented_branch(self):
240
229
branch_d = branch_b.clone(repo_d.bzrdir)
241
230
self.assertEqual(random_parent, branch_d.get_parent())
243
def test_copy_content_incomplete(self):
244
tree = self.make_branch_and_tree('commit_tree')
245
self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
247
tree.commit('revision 1', rev_id='1')
248
source = self.make_branch_and_tree('source')
249
# this gives us an incomplete repository
250
tree.bzrdir.open_repository().copy_content_into(
251
source.branch.repository)
252
tree.commit('revision 2', rev_id='2', allow_pointless=True)
253
tree.bzrdir.open_branch().copy_content_into(source.branch)
256
232
def test_sprout_branch_nickname(self):
257
233
# test the nick name is reset always
258
234
raise TestSkipped('XXX branch sprouting is not yet tested..')
347
323
def test_branch_keeps_signatures(self):
348
324
wt = self.make_branch_and_tree('source')
349
325
wt.commit('A', allow_pointless=True, rev_id='A')
350
wt.branch.repository.sign_revision('A',
351
gpg.LoopbackGPGStrategy(None))
326
repo = wt.branch.repository
327
repo.sign_revision('A', gpg.LoopbackGPGStrategy(None))
352
328
#FIXME: clone should work to urls,
353
329
# wt.clone should work to disks.
354
330
self.build_tree(['target/'])
355
d2 = wt.bzrdir.clone('target')
356
self.assertEqual(wt.branch.repository.get_signature_text('A'),
331
d2 = repo.bzrdir.clone(urlutils.local_path_to_url('target'))
332
self.assertEqual(repo.get_signature_text('A'),
357
333
d2.open_repository().get_signature_text('A'))
359
335
def test_nicks(self):
360
"""Branch nicknames"""
336
"""Test explicit and implicit branch nicknames.
338
Nicknames are implicitly the name of the branch's directory, unless an
339
explicit nickname is set. That is, an explicit nickname always
340
overrides the implicit one.
361
342
t = get_transport(self.get_url())
363
343
branch = self.make_branch('bzr.dev')
344
# The nick will be 'bzr.dev', because there is no explicit nick set.
364
345
self.assertEqual(branch.nick, 'bzr.dev')
346
# Move the branch to a different directory, 'bzr.ab'. Now that branch
347
# will report its nick as 'bzr.ab'.
365
348
t.move('bzr.dev', 'bzr.ab')
366
349
branch = Branch.open(self.get_url('bzr.ab'))
367
350
self.assertEqual(branch.nick, 'bzr.ab')
368
branch.nick = "Aaron's branch"
369
branch.nick = "Aaron's branch"
373
branch.control_files.controlfilename("branch.conf")
351
# Set the branch nick explicitly. This will ensure there's a branch
352
# config file in the branch.
353
branch.nick = "Aaron's branch"
354
branch.nick = "Aaron's branch"
356
controlfilename = branch.control_files.controlfilename
357
except AttributeError:
358
# remote branches don't have control_files
362
t.has(t.relpath(controlfilename("branch.conf"))))
363
# Because the nick has been set explicitly, the nick is now always
364
# "Aaron's branch", regardless of directory name.
377
365
self.assertEqual(branch.nick, "Aaron's branch")
378
366
t.move('bzr.ab', 'integration')
379
367
branch = Branch.open(self.get_url('integration'))
381
369
branch.nick = u"\u1234"
382
370
self.assertEqual(branch.nick, u"\u1234")
372
def test_commit_nicks(self):
373
"""Nicknames are committed to the revision"""
374
wt = self.make_branch_and_tree('bzr.dev')
376
branch.nick = "My happy branch"
377
wt.commit('My commit respect da nick.')
378
committed = branch.repository.get_revision(branch.last_revision())
379
self.assertEqual(committed.properties["branch-nick"],
384
382
def test_create_open_branch_uses_repository(self):
386
384
repo = self.make_repository('.', shared=True)
387
385
except errors.IncompatibleFormat:
389
repo.bzrdir.root_transport.mkdir('child')
390
child_dir = self.bzrdir_format.initialize('child')
387
child_transport = repo.bzrdir.root_transport.clone('child')
388
child_transport.mkdir('.')
389
child_dir = self.bzrdir_format.initialize_on_transport(child_transport)
392
391
child_branch = self.branch_format.initialize(child_dir)
393
392
except errors.UninitializableFormat:
457
456
"""A lightweight checkout from a readonly branch should succeed."""
458
457
tree_a = self.make_branch_and_tree('a')
459
458
rev_id = tree_a.commit('put some content in the branch')
460
source_branch = bzrlib.branch.Branch.open(
461
'readonly+' + tree_a.bzrdir.root_transport.base)
459
# open the branch via a readonly transport
460
source_branch = bzrlib.branch.Branch.open(self.get_readonly_url('a'))
462
461
# sanity check that the test will be valid
463
462
self.assertRaises((errors.LockError, errors.TransportNotPossible),
464
463
source_branch.lock_write)
469
468
"""A regular checkout from a readonly branch should succeed."""
470
469
tree_a = self.make_branch_and_tree('a')
471
470
rev_id = tree_a.commit('put some content in the branch')
472
source_branch = bzrlib.branch.Branch.open(
473
'readonly+' + tree_a.bzrdir.root_transport.base)
471
# open the branch via a readonly transport
472
source_branch = bzrlib.branch.Branch.open(self.get_readonly_url('a'))
474
473
# sanity check that the test will be valid
475
474
self.assertRaises((errors.LockError, errors.TransportNotPossible),
476
475
source_branch.lock_write)
477
476
checkout = source_branch.create_checkout('c')
478
477
self.assertEqual(rev_id, checkout.last_revision())
479
def test_set_revision_history(self):
480
tree = self.make_branch_and_tree('a')
481
tree.commit('a commit', rev_id='rev1')
483
br.set_revision_history(["rev1"])
484
self.assertEquals(br.revision_history(), ["rev1"])
485
br.set_revision_history([])
486
self.assertEquals(br.revision_history(), [])
481
489
class ChrootedTests(TestCaseWithBranch):
482
490
"""A support class that provides readonly urls outside the local namespace.