1
# Copyright (C) 2006-2012, 2016 Canonical Ltd
1
# Copyright (C) 2006-2012 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
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
"""Black-box tests for brz branch."""
18
"""Black-box tests for bzr branch."""
26
27
revision as _mod_revision,
29
from breezy.bzr import (
32
from breezy.bzr.knitrepo import RepositoryFormatKnit1
33
from breezy.tests import (
30
from bzrlib.repofmt.knitrepo import RepositoryFormatKnit1
31
from bzrlib.tests import (
37
from breezy.tests.features import (
35
from bzrlib.tests.features import (
40
from breezy.tests.blackbox import test_switch
41
from breezy.tests.matchers import ContainsNoVfsCalls
42
from breezy.tests.test_sftp_transport import TestCaseWithSFTPServer
43
from breezy.tests.script import run_script
44
from breezy.urlutils import local_path_to_url, strip_trailing_slash
45
from breezy.workingtree import WorkingTree
38
from bzrlib.tests.blackbox import test_switch
39
from bzrlib.tests.matchers import ContainsNoVfsCalls
40
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
41
from bzrlib.tests.script import run_script
42
from bzrlib.urlutils import local_path_to_url, strip_trailing_slash
43
from bzrlib.workingtree import WorkingTree
48
46
class TestBranch(tests.TestCaseWithTransport):
50
48
def example_branch(self, path='.', format=None):
51
49
tree = self.make_branch_and_tree(path, format=format)
52
self.build_tree_contents([(path + '/hello', b'foo')])
50
self.build_tree_contents([(path + '/hello', 'foo')])
54
52
tree.commit(message='setup')
55
self.build_tree_contents([(path + '/goodbye', b'baz')])
53
self.build_tree_contents([(path + '/goodbye', 'baz')])
56
54
tree.add('goodbye')
57
55
tree.commit(message='setup')
65
63
self.run_bzr('branch a c -r 1')
66
64
# previously was erroneously created by branching
67
65
self.assertFalse(b._transport.has('branch-name'))
68
b.controldir.open_workingtree().commit(message='foo', allow_pointless=True)
66
b.bzrdir.open_workingtree().commit(message='foo', allow_pointless=True)
70
68
def test_branch_no_to_location(self):
71
69
"""The to_location is derived from the source branch name."""
73
71
a = self.example_branch('something/a').branch
74
72
self.run_bzr('branch something/a')
75
73
b = branch.Branch.open('a')
76
self.assertEqual(b.last_revision_info(), a.last_revision_info())
74
self.assertEquals(b.last_revision_info(), a.last_revision_info())
78
76
def test_into_colocated(self):
79
77
"""Branch from a branch into a colocated branch."""
81
79
out, err = self.run_bzr(
82
80
'init --format=development-colo file:b,branch=orig')
84
"""Created a standalone tree (format: development-colo)\n""",
82
"""Created a lightweight checkout (format: development-colo)\n""",
86
84
self.assertEqual('', err)
87
85
out, err = self.run_bzr(
91
89
out, err = self.run_bzr('branches b')
92
90
self.assertEqual(" orig\n thiswasa\n", out)
93
91
self.assertEqual('', err)
94
out, err = self.run_bzr('branch a file:b,branch=orig', retcode=3)
92
out,err = self.run_bzr('branch a file:b,branch=orig', retcode=3)
95
93
self.assertEqual('', out)
97
'brz: ERROR: Already a branch: "file:b,branch=orig".\n', err)
95
'bzr: ERROR: Already a branch: "file:b,branch=orig".\n', err)
99
97
def test_from_colocated(self):
100
98
"""Branch from a colocated branch into a regular branch."""
101
99
tree = self.example_branch('a', format='development-colo')
102
tree.controldir.create_branch(name='somecolo')
100
tree.bzrdir.create_branch(name='somecolo')
103
101
out, err = self.run_bzr('branch %s,branch=somecolo' %
104
102
local_path_to_url('a'))
105
103
self.assertEqual('', out)
170
168
def test_branch_into_empty_dir(self):
171
169
t = self.example_branch('source')
172
self.make_controldir('target')
170
self.make_bzrdir('target')
173
171
self.run_bzr("branch source target")
174
self.assertEqual(2, len(t.branch.repository.all_revision_ids()))
172
self.assertEquals(2, len(t.branch.repository.all_revision_ids()))
176
174
def test_branch_switch_checkout(self):
177
175
# Checkout in the current directory:
210
208
shared_repo.set_make_working_trees(True)
212
210
def make_shared_tree(path):
213
shared_repo.controldir.root_transport.mkdir(path)
211
shared_repo.bzrdir.root_transport.mkdir(path)
214
212
controldir.ControlDir.create_branch_convenience('repo/' + path)
215
213
return WorkingTree.open('repo/' + path)
216
214
tree_a = make_shared_tree('a')
217
215
self.build_tree(['repo/a/file'])
218
216
tree_a.add('file')
219
tree_a.commit('commit a-1', rev_id=b'a-1')
217
tree_a.commit('commit a-1', rev_id='a-1')
220
218
f = open('repo/a/file', 'ab')
221
219
f.write('more stuff\n')
223
tree_a.commit('commit a-2', rev_id=b'a-2')
221
tree_a.commit('commit a-2', rev_id='a-2')
225
223
tree_b = make_shared_tree('b')
226
224
self.build_tree(['repo/b/file'])
227
225
tree_b.add('file')
228
tree_b.commit('commit b-1', rev_id=b'b-1')
226
tree_b.commit('commit b-1', rev_id='b-1')
230
228
self.assertTrue(shared_repo.has_revision('a-1'))
231
229
self.assertTrue(shared_repo.has_revision('a-2'))
265
263
self.build_tree(['source/file1'])
266
264
source.add('file1')
267
265
source.commit('added file')
268
source.controldir.sprout('second')
266
source.bzrdir.sprout('second')
269
267
out, err = self.run_bzr('branch source target --files-from second'
271
269
source_stat = os.stat('source/file1')
292
290
def test_branch_into_existing_dir(self):
293
291
self.example_branch('a')
294
# existing dir with similar files but no .brz dir
292
# existing dir with similar files but no .bzr dir
295
293
self.build_tree_contents([('b/',)])
296
self.build_tree_contents([('b/hello', b'bar')]) # different content
297
self.build_tree_contents([('b/goodbye', b'baz')])# same content
294
self.build_tree_contents([('b/hello', 'bar')]) # different content
295
self.build_tree_contents([('b/goodbye', 'baz')])# same content
298
296
# fails without --use-existing-dir
299
out, err = self.run_bzr('branch a b', retcode=3)
297
out,err = self.run_bzr('branch a b', retcode=3)
300
298
self.assertEqual('', out)
301
self.assertEqual('brz: ERROR: Target directory "b" already exists.\n',
299
self.assertEqual('bzr: ERROR: Target directory "b" already exists.\n',
303
301
# force operation
304
302
self.run_bzr('branch a b --use-existing-dir')
306
304
self.assertPathExists('b/hello.moved')
307
305
self.assertPathDoesNotExist('b/godbye.moved')
308
306
# we can't branch into branch
309
out, err = self.run_bzr('branch a b --use-existing-dir', retcode=3)
307
out,err = self.run_bzr('branch a b --use-existing-dir', retcode=3)
310
308
self.assertEqual('', out)
311
self.assertEqual('brz: ERROR: Already a branch: "b".\n', err)
309
self.assertEqual('bzr: ERROR: Already a branch: "b".\n', err)
313
311
def test_branch_bind(self):
314
312
self.example_branch('a')
350
348
def test_branch_fetches_all_tags(self):
351
349
builder = self.make_branch_builder('source')
352
source, rev1, rev2 = fixtures.build_branch_with_non_ancestral_rev(builder)
353
source.tags.set_tag('tag-a', rev2)
350
source = fixtures.build_branch_with_non_ancestral_rev(builder)
351
source.tags.set_tag('tag-a', 'rev-2')
354
352
source.get_config_stack().set('branch.fetch_tags', True)
355
353
# Now source has a tag not in its ancestry. Make a branch from it.
356
354
self.run_bzr('branch source new-branch')
357
355
new_branch = branch.Branch.open('new-branch')
358
356
# The tag is present, and so is its revision.
359
self.assertEqual(rev2, new_branch.tags.lookup_tag('tag-a'))
360
new_branch.repository.get_revision(rev2)
357
self.assertEqual('rev-2', new_branch.tags.lookup_tag('tag-a'))
358
new_branch.repository.get_revision('rev-2')
363
361
class TestBranchStacked(tests.TestCaseWithTransport):
390
388
branch_tree.branch.set_stacked_on_url(trunk_tree.branch.base)
391
389
# with some work on it
392
work_tree = trunk_tree.branch.controldir.sprout('local').open_workingtree()
390
work_tree = trunk_tree.branch.bzrdir.sprout('local').open_workingtree()
393
391
work_tree.commit('moar work plz')
394
392
work_tree.branch.push(branch_tree.branch)
395
393
# branching our local branch gives us a new stacked branch pointing at
416
414
branch_tree.branch.set_stacked_on_url(trunk_tree.branch.base)
417
415
# with some work on it
418
work_tree = trunk_tree.branch.controldir.sprout('local').open_workingtree()
416
work_tree = trunk_tree.branch.bzrdir.sprout('local').open_workingtree()
419
417
branch_revid = work_tree.commit('moar work plz')
420
418
work_tree.branch.push(branch_tree.branch)
421
419
# you can chain branches on from there
531
529
t = self.make_branch_and_tree('trunk')
532
530
for count in range(8):
533
531
t.commit(message='commit %d' % count)
534
tree2 = t.branch.controldir.sprout('feature', stacked=True
532
tree2 = t.branch.bzrdir.sprout('feature', stacked=True
535
533
).open_workingtree()
536
local_tree = t.branch.controldir.sprout('local-working').open_workingtree()
534
local_tree = t.branch.bzrdir.sprout('local-working').open_workingtree()
537
535
local_tree.commit('feature change')
538
536
local_tree.branch.push(tree2.branch)
539
537
self.reset_smart_call_log()
551
549
def test_branch_from_branch_with_tags(self):
552
550
self.setup_smart_server_with_call_log()
553
551
builder = self.make_branch_builder('source')
554
source, rev1, rev2 = fixtures.build_branch_with_non_ancestral_rev(builder)
552
source = fixtures.build_branch_with_non_ancestral_rev(builder)
555
553
source.get_config_stack().set('branch.fetch_tags', True)
556
source.tags.set_tag('tag-a', rev2)
554
source.tags.set_tag('tag-a', 'rev-2')
557
555
source.tags.set_tag('tag-missing', 'missing-rev')
558
556
# Now source has a tag not in its ancestry. Make a branch from it.
559
557
self.reset_smart_call_log()
596
594
super(TestRemoteBranch, self).setUp()
597
595
tree = self.make_branch_and_tree('branch')
598
self.build_tree_contents([('branch/file', b'file content\n')])
596
self.build_tree_contents([('branch/file', 'file content\n')])
600
598
tree.commit('file created')
614
612
self.assertFalse(t.has('remote/file'))
615
class TestDeprecatedAliases(tests.TestCaseWithTransport):
617
def test_deprecated_aliases(self):
618
"""bzr branch can be called clone or get, but those names are
623
for command in ['clone', 'get']:
625
$ bzr %(command)s A B
626
2>The command 'bzr %(command)s' has been deprecated in bzr 2.4. Please use 'bzr branch' instead.
627
2>bzr: ERROR: Not a branch...
617
631
class TestBranchParentLocation(test_switch.TestSwitchParentLocationBase):
619
633
def _checkout_and_branch(self, option=''):
620
634
self.script_runner.run_script(self, '''
621
$ brz checkout %(option)s repo/trunk checkout
635
$ bzr checkout %(option)s repo/trunk checkout
623
$ brz branch --switch ../repo/trunk ../repo/branched
637
$ bzr branch --switch ../repo/trunk ../repo/branched
624
638
2>Branched 0 revisions.
625
639
2>Tree is up to date at revision 0.
626
640
2>Switched to branch:...branched...
631
645
return (bound_branch, master_branch)
633
647
def test_branch_switch_parent_lightweight(self):
634
"""Lightweight checkout using brz branch --switch."""
648
"""Lightweight checkout using bzr branch --switch."""
635
649
bb, mb = self._checkout_and_branch(option='--lightweight')
636
650
self.assertParent('repo/trunk', bb)
637
651
self.assertParent('repo/trunk', mb)
639
653
def test_branch_switch_parent_heavyweight(self):
640
"""Heavyweight checkout using brz branch --switch."""
654
"""Heavyweight checkout using bzr branch --switch."""
641
655
bb, mb = self._checkout_and_branch()
642
656
self.assertParent('repo/trunk', bb)
643
657
self.assertParent('repo/trunk', mb)