1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# Copyright (C) 2005, 2006 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""Black-box tests for bzr branch."""
import os
from bzrlib import branch, bzrdir
from bzrlib.repofmt.knitrepo import RepositoryFormatKnit1
from bzrlib.tests.blackbox import ExternalBase
from bzrlib.workingtree import WorkingTree
class TestBranch(ExternalBase):
def example_branch(test):
test.run_bzr('init')
file('hello', 'wt').write('foo')
test.run_bzr('add hello')
test.run_bzr('commit -m setup hello')
file('goodbye', 'wt').write('baz')
test.run_bzr('add goodbye')
test.run_bzr('commit -m setup goodbye')
def test_branch(self):
"""Branch from one branch to another."""
os.mkdir('a')
os.chdir('a')
self.example_branch()
os.chdir('..')
self.run_bzr('branch a b')
b = branch.Branch.open('b')
self.assertEqual('b\n', b.control_files.get_utf8('branch-name').read())
self.run_bzr('branch a c -r 1')
os.chdir('b')
self.run_bzr('commit -m foo --unchanged')
os.chdir('..')
def test_branch_only_copies_history(self):
# Knit branches should only push the history for the current revision.
format = bzrdir.BzrDirMetaFormat1()
format.repository_format = RepositoryFormatKnit1()
shared_repo = self.make_repository('repo', format=format, shared=True)
shared_repo.set_make_working_trees(True)
def make_shared_tree(path):
shared_repo.bzrdir.root_transport.mkdir(path)
shared_repo.bzrdir.create_branch_convenience('repo/' + path)
return WorkingTree.open('repo/' + path)
tree_a = make_shared_tree('a')
self.build_tree(['repo/a/file'])
tree_a.add('file')
tree_a.commit('commit a-1', rev_id='a-1')
f = open('repo/a/file', 'ab')
f.write('more stuff\n')
f.close()
tree_a.commit('commit a-2', rev_id='a-2')
tree_b = make_shared_tree('b')
self.build_tree(['repo/b/file'])
tree_b.add('file')
tree_b.commit('commit b-1', rev_id='b-1')
self.assertTrue(shared_repo.has_revision('a-1'))
self.assertTrue(shared_repo.has_revision('a-2'))
self.assertTrue(shared_repo.has_revision('b-1'))
# Now that we have a repository with shared files, make sure
# that things aren't copied out by a 'branch'
self.run_bzr('branch repo/b branch-b')
pushed_tree = WorkingTree.open('branch-b')
pushed_repo = pushed_tree.branch.repository
self.assertFalse(pushed_repo.has_revision('a-1'))
self.assertFalse(pushed_repo.has_revision('a-2'))
self.assertTrue(pushed_repo.has_revision('b-1'))
|