1
# Copyright (C) 2006-2010 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
"""Black-box tests for repositories with shared branches"""
21
from bzrlib import osutils
22
from bzrlib.bzrdir import BzrDir, BzrDirMetaFormat1
23
import bzrlib.errors as errors
24
from bzrlib.tests import TestCaseInTempDir
26
class TestSharedRepo(TestCaseInTempDir):
28
def test_make_repository(self):
29
out, err = self.run_bzr("init-repository a")
31
"""Shared repository with trees (format: 2a)
35
self.assertEqual(err, "")
36
dir = BzrDir.open('a')
37
self.assertIs(dir.open_repository().is_shared(), True)
38
self.assertRaises(errors.NotBranchError, dir.open_branch)
39
self.assertRaises(errors.NoWorkingTree, dir.open_workingtree)
41
def test_make_repository_quiet(self):
42
out, err = self.run_bzr("init-repository a -q")
43
self.assertEqual(out, "")
44
self.assertEqual(err, "")
45
dir = BzrDir.open('a')
46
self.assertIs(dir.open_repository().is_shared(), True)
47
self.assertRaises(errors.NotBranchError, dir.open_branch)
48
self.assertRaises(errors.NoWorkingTree, dir.open_workingtree)
50
def test_init_repo_existing_dir(self):
51
"""Make repo in existing directory.
55
out, err = self.run_bzr("init-repository .")
56
dir = BzrDir.open('.')
57
self.assertTrue(dir.open_repository())
60
self.run_bzr("init-repo a")
61
self.run_bzr("init --format=default a/b")
62
dir = BzrDir.open('a')
63
self.assertIs(dir.open_repository().is_shared(), True)
64
self.assertRaises(errors.NotBranchError, dir.open_branch)
65
self.assertRaises(errors.NoWorkingTree, dir.open_workingtree)
66
bdir = BzrDir.open('a/b')
68
self.assertRaises(errors.NoRepositoryPresent, bdir.open_repository)
69
wt = bdir.open_workingtree()
71
def test_branch(self):
72
self.run_bzr("init-repo a")
73
self.run_bzr("init --format=default a/b")
74
self.run_bzr('branch a/b a/c')
75
cdir = BzrDir.open('a/c')
77
self.assertRaises(errors.NoRepositoryPresent, cdir.open_repository)
78
cdir.open_workingtree()
80
def test_branch_tree(self):
81
self.run_bzr("init-repo --trees a")
82
self.run_bzr("init --format=default b")
83
file('b/hello', 'wt').write('bar')
84
self.run_bzr("add b/hello")
85
self.run_bzr("commit -m bar b/hello")
87
self.run_bzr('branch b a/c')
88
cdir = BzrDir.open('a/c')
90
self.assertRaises(errors.NoRepositoryPresent, cdir.open_repository)
91
self.failUnlessExists('a/c/hello')
92
cdir.open_workingtree()
94
def test_trees_default(self):
95
# 0.15 switched to trees by default
96
self.run_bzr("init-repo repo")
97
repo = BzrDir.open("repo").open_repository()
98
self.assertEqual(True, repo.make_working_trees())
100
def test_trees_argument(self):
101
# Supplying the --trees argument should be harmless,
102
# as it was previously non-default we need to get it right.
103
self.run_bzr("init-repo --trees trees")
104
repo = BzrDir.open("trees").open_repository()
105
self.assertEqual(True, repo.make_working_trees())
107
def test_no_trees_argument(self):
108
# --no-trees should make it so that there is no working tree
109
self.run_bzr("init-repo --no-trees notrees")
110
repo = BzrDir.open("notrees").open_repository()
111
self.assertEqual(False, repo.make_working_trees())
113
def test_init_repo_smart_acceptance(self):
114
# The amount of hpss calls made on init-repo to a smart server should
116
self.setup_smart_server_with_call_log()
117
self.run_bzr(['init-repo', self.get_url('repo')])
118
# This figure represent the amount of work to perform this use case. It
119
# is entirely ok to reduce this number if a test fails due to rpc_count
120
# being too low. If rpc_count increases, more network roundtrips have
121
# become necessary for this use case. Please do not adjust this number
122
# upwards without agreement from bzr's network support maintainers.
123
self.assertLength(15, self.hpss_calls)
125
def test_notification_on_branch_from_repository(self):
126
out, err = self.run_bzr("init-repository -q a")
127
self.assertEqual(out, "")
128
self.assertEqual(err, "")
129
dir = BzrDir.open('a')
130
dir.open_repository() # there is a repository there
131
e = self.assertRaises(errors.NotBranchError, dir.open_branch)
132
self.assertContainsRe(str(e), "location is a repository")
134
def test_notification_on_branch_from_nonrepository(self):
135
fmt = BzrDirMetaFormat1()
136
t = self.get_transport()
138
dir = fmt.initialize_on_transport(t.clone('a'))
139
self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
140
e = self.assertRaises(errors.NotBranchError, dir.open_branch)
141
self.assertNotContainsRe(str(e), "location is a repository")
143
def test_init_repo_with_post_repo_init_hook(self):
145
BzrDir.hooks.install_named_hook('post_repo_init', calls.append, None)
146
self.assertLength(0, calls)
147
self.run_bzr("init-repository a")
148
self.assertLength(1, calls)
150
def test_init_repo_without_username(self):
151
"""Ensure init-repo works if username is not set.
153
# bzr makes user specified whoami mandatory for operations
154
# like commit as whoami is recorded. init-repo however is not so final
155
# and uses whoami only in a lock file. Without whoami the login name
156
# is used. This test is to ensure that init-repo passes even when whoami
158
osutils.set_or_unset_env('EMAIL', None)
159
osutils.set_or_unset_env('BZR_EMAIL', None)
160
out, err = self.run_bzr(['init-repo', 'foo'])
161
self.assertEqual(err, '')
162
self.assertTrue(os.path.exists('foo'))