1
# Copyright (C) 2006-2012 Canonical Ltd
1
# Copyright (C) 2006-2011 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
27
27
revision as _mod_revision,
30
29
from bzrlib.repofmt.knitrepo import RepositoryFormatKnit1
30
from bzrlib.tests import TestCaseWithTransport
31
31
from bzrlib.tests import (
43
43
from bzrlib.workingtree import WorkingTree
46
class TestBranch(tests.TestCaseWithTransport):
46
class TestBranch(TestCaseWithTransport):
48
48
def example_branch(self, path='.', format=None):
49
49
tree = self.make_branch_and_tree(path, format=format)
65
65
self.assertFalse(b._transport.has('branch-name'))
66
66
b.bzrdir.open_workingtree().commit(message='foo', allow_pointless=True)
68
def test_branch_no_to_location(self):
69
"""The to_location is derived from the source branch name."""
71
a = self.example_branch('something/a').branch
72
self.run_bzr('branch something/a')
73
b = branch.Branch.open('a')
74
self.assertEquals(b.last_revision_info(), a.last_revision_info())
76
68
def test_into_colocated(self):
77
69
"""Branch from a branch into a colocated branch."""
78
70
self.example_branch('a')
87
79
self.assertEqual('', out)
88
80
self.assertEqual('Branched 2 revisions.\n', err)
89
81
out, err = self.run_bzr('branches b')
90
self.assertEqual(" orig\n thiswasa\n", out)
82
self.assertEqual(" thiswasa\n orig\n", out)
91
83
self.assertEqual('', err)
92
84
out,err = self.run_bzr('branch a file:b,branch=orig', retcode=3)
93
85
self.assertEqual('', out)
95
'bzr: ERROR: Already a branch: "file:b,branch=orig".\n', err)
86
self.assertEqual('bzr: ERROR: Already a branch: "file:b,branch=orig".\n', err)
97
88
def test_from_colocated(self):
98
89
"""Branch from a colocated branch into a regular branch."""
124
115
f.write(corrupt) # make sure we corrupt something
125
self.run_bzr_error(['Corruption while decompressing repository file'],
116
self.run_bzr_error(['Corruption while decompressing repository file'],
126
117
'branch a b', retcode=3)
128
119
def test_branch_switch_no_branch(self):
155
146
# => new branch will be created, but switch fails and the current
156
147
# branch is unmodified
157
148
self.example_branch('a')
158
tree = self.make_branch_and_tree('current')
159
c1 = tree.commit('some diverged change')
149
self.make_branch_and_tree('current')
160
150
self.run_bzr_error(['Cannot switch a branch, only a checkout'],
161
151
'branch --switch ../a ../b', working_dir='current')
162
152
a = branch.Branch.open('a')
163
153
b = branch.Branch.open('b')
164
154
self.assertEqual(a.last_revision(), b.last_revision())
165
155
work = branch.Branch.open('current')
166
self.assertEqual(work.last_revision(), c1)
168
def test_branch_into_empty_dir(self):
169
t = self.example_branch('source')
170
self.make_bzrdir('target')
171
self.run_bzr("branch source target")
172
self.assertEquals(2, len(t.branch.repository.all_revision_ids()))
156
self.assertEqual(work.last_revision(), _mod_revision.NULL_REVISION)
174
158
def test_branch_switch_checkout(self):
175
159
# Checkout in the current directory:
176
160
# => new branch will be created and checkout bound to the new branch
177
161
self.example_branch('a')
178
162
self.run_bzr('checkout a current')
179
out, err = self.run_bzr('branch --switch ../a ../b',
180
working_dir='current')
163
out, err = self.run_bzr('branch --switch ../a ../b', working_dir='current')
181
164
a = branch.Branch.open('a')
182
165
b = branch.Branch.open('b')
183
166
self.assertEqual(a.last_revision(), b.last_revision())
192
175
self.example_branch('a')
193
176
self.run_bzr('checkout --lightweight a current')
194
out, err = self.run_bzr('branch --switch ../a ../b',
195
working_dir='current')
177
out, err = self.run_bzr('branch --switch ../a ../b', working_dir='current')
196
178
a = branch.Branch.open('a')
197
179
b = branch.Branch.open('b')
198
180
self.assertEqual(a.last_revision(), b.last_revision())
349
331
builder = self.make_branch_builder('source')
350
332
source = fixtures.build_branch_with_non_ancestral_rev(builder)
351
333
source.tags.set_tag('tag-a', 'rev-2')
352
source.get_config_stack().set('branch.fetch_tags', True)
334
source.get_config().set_user_option('branch.fetch_tags', 'True')
353
335
# Now source has a tag not in its ancestry. Make a branch from it.
354
336
self.run_bzr('branch source new-branch')
355
337
new_branch = branch.Branch.open('new-branch')
358
340
new_branch.repository.get_revision('rev-2')
361
class TestBranchStacked(tests.TestCaseWithTransport):
343
class TestBranchStacked(TestCaseWithTransport):
362
344
"""Tests for branch --stacked"""
364
346
def assertRevisionInRepository(self, repo_path, revid):
365
"""Check that a revision is in a repo, disregarding stacking."""
347
"""Check that a revision is in a repository, disregarding stacking."""
366
348
repo = bzrdir.BzrDir.open(repo_path).open_repository()
367
349
self.assertTrue(repo.has_revision(revid))
369
351
def assertRevisionNotInRepository(self, repo_path, revid):
370
"""Check that a revision is not in a repo, disregarding stacking."""
352
"""Check that a revision is not in a repository, disregarding stacking."""
371
353
repo = bzrdir.BzrDir.open(repo_path).open_repository()
372
354
self.assertFalse(repo.has_revision(revid))
445
427
trunk_tree.branch.base, err)
446
428
self.assertRevisionNotInRepository('newbranch', original_revid)
447
429
new_branch = branch.Branch.open('newbranch')
448
self.assertEqual(trunk_tree.branch.base,
449
new_branch.get_stacked_on_url())
430
self.assertEqual(trunk_tree.branch.base, new_branch.get_stacked_on_url())
451
432
def test_branch_stacked_from_smart_server(self):
452
433
# We can branch stacking on a smart server
490
class TestSmartServerBranching(tests.TestCaseWithTransport):
471
class TestSmartServerBranching(TestCaseWithTransport):
492
473
def test_branch_from_trivial_branch_to_same_server_branch_acceptance(self):
493
474
self.setup_smart_server_with_call_log()
502
483
# being too low. If rpc_count increases, more network roundtrips have
503
484
# become necessary for this use case. Please do not adjust this number
504
485
# upwards without agreement from bzr's network support maintainers.
505
self.assertLength(2, self.hpss_connections)
506
486
self.assertLength(33, self.hpss_calls)
507
487
self.expectFailure("branching to the same branch requires VFS access",
508
488
self.assertThat, self.hpss_calls, ContainsNoVfsCalls)
522
502
# upwards without agreement from bzr's network support maintainers.
523
503
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
524
504
self.assertLength(10, self.hpss_calls)
525
self.assertLength(1, self.hpss_connections)
527
506
def test_branch_from_trivial_stacked_branch_streaming_acceptance(self):
528
507
self.setup_smart_server_with_call_log()
543
522
# become necessary for this use case. Please do not adjust this number
544
523
# upwards without agreement from bzr's network support maintainers.
545
524
self.assertLength(15, self.hpss_calls)
546
self.assertLength(1, self.hpss_connections)
547
525
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
549
527
def test_branch_from_branch_with_tags(self):
550
528
self.setup_smart_server_with_call_log()
551
529
builder = self.make_branch_builder('source')
552
530
source = fixtures.build_branch_with_non_ancestral_rev(builder)
553
source.get_config_stack().set('branch.fetch_tags', True)
531
source.get_config().set_user_option('branch.fetch_tags', 'True')
554
532
source.tags.set_tag('tag-a', 'rev-2')
555
533
source.tags.set_tag('tag-missing', 'missing-rev')
556
534
# Now source has a tag not in its ancestry. Make a branch from it.
563
541
# upwards without agreement from bzr's network support maintainers.
564
542
self.assertLength(10, self.hpss_calls)
565
543
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
566
self.assertLength(1, self.hpss_connections)
568
545
def test_branch_to_stacked_from_trivial_branch_streaming_acceptance(self):
569
546
self.setup_smart_server_with_call_log()
582
559
readvs_of_rix_files = [
583
560
c for c in self.hpss_calls
584
561
if c.call.method == 'readv' and c.call.args[-1].endswith('.rix')]
585
self.assertLength(1, self.hpss_connections)
586
562
self.assertLength(0, readvs_of_rix_files)
587
563
self.expectFailure("branching to stacked requires VFS access",
588
564
self.assertThat, self.hpss_calls, ContainsNoVfsCalls)
612
588
self.assertFalse(t.has('remote/file'))
615
class TestDeprecatedAliases(tests.TestCaseWithTransport):
591
class TestDeprecatedAliases(TestCaseWithTransport):
617
593
def test_deprecated_aliases(self):
618
"""bzr branch can be called clone or get, but those names are
594
"""bzr branch can be called clone or get, but those names are deprecated.