1
# Copyright (C) 2006, 2007, 2009 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
24
branch as _mod_branch,
27
from bzrlib.bzrdir import BzrDirMetaFormat1
28
from bzrlib.tests import TestSkipped
29
from bzrlib.tests.blackbox import ExternalBase
30
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
31
from bzrlib.workingtree import WorkingTree
34
class TestInit(ExternalBase):
37
ExternalBase.setUp(self)
38
self._default_label = '2a'
40
def test_init_with_format(self):
41
# Verify bzr init --format constructs something plausible
42
t = self.get_transport()
43
self.run_bzr('init --format default')
44
self.assertIsDirectory('.bzr', t)
45
self.assertIsDirectory('.bzr/checkout', t)
46
self.assertIsDirectory('.bzr/checkout/lock', t)
48
def test_init_weave(self):
49
# --format=weave should be accepted to allow interoperation with
50
# old releases when desired.
51
out, err = self.run_bzr('init --format=weave')
52
self.assertEqual("""Created a standalone tree (format: weave)\n""",
54
self.assertEqual('', err)
56
def test_init_format_2a(self):
57
"""Smoke test for constructing a format 2a repoistory."""
58
out, err = self.run_bzr('init --format=2a')
59
self.assertEqual("""Created a standalone tree (format: 2a)\n""",
61
self.assertEqual('', err)
63
def test_init_at_repository_root(self):
64
# bzr init at the root of a repository should create a branch
65
# and working tree even when creation of working trees is disabled.
66
t = self.get_transport()
68
format = BzrDirMetaFormat1()
69
newdir = format.initialize(t.abspath('repo'))
70
repo = newdir.create_repository(shared=True)
71
repo.set_make_working_trees(False)
72
out, err = self.run_bzr('init repo')
73
self.assertEqual("""Created a repository tree (format: %s)
74
Using shared repository: %s
75
""" % (self._default_label, urlutils.local_path_from_url(
76
repo.bzrdir.root_transport.external_url())), out)
77
self.assertEndsWith(out, "bzrlib.tests.blackbox.test_init.TestInit."
78
"test_init_at_repository_root/work/repo/\n")
79
self.assertEqual('', err)
81
newdir.open_workingtree()
83
def test_init_branch(self):
84
out, err = self.run_bzr('init')
85
self.assertEqual("Created a standalone tree (format: %s)\n" % (
86
self._default_label,), out)
87
self.assertEqual('', err)
89
# Can it handle subdirectories of branches too ?
90
out, err = self.run_bzr('init subdir1')
91
self.assertEqual("Created a standalone tree (format: %s)\n" % (
92
self._default_label,), out)
93
self.assertEqual('', err)
94
WorkingTree.open('subdir1')
96
self.run_bzr_error(['Parent directory of subdir2/nothere does not exist'],
97
'init subdir2/nothere')
98
out, err = self.run_bzr('init subdir2/nothere', retcode=3)
99
self.assertEqual('', out)
102
out, err = self.run_bzr('init subdir2')
103
self.assertEqual("Created a standalone tree (format: %s)\n" % (
104
self._default_label,), out)
105
self.assertEqual('', err)
106
# init an existing branch.
107
out, err = self.run_bzr('init subdir2', retcode=3)
108
self.assertEqual('', out)
109
self.failUnless(err.startswith('bzr: ERROR: Already a branch:'))
111
def test_init_branch_quiet(self):
112
out, err = self.run_bzr('init -q')
113
self.assertEqual('', out)
114
self.assertEqual('', err)
116
def test_init_existing_branch(self):
118
out, err = self.run_bzr('init', retcode=3)
119
self.assertContainsRe(err, 'Already a branch')
120
# don't suggest making a checkout, there's already a working tree
121
self.assertFalse(re.search(r'checkout', err))
123
def test_init_existing_without_workingtree(self):
125
repo = self.make_repository('.', shared=True)
126
repo.set_make_working_trees(False)
127
# make a branch; by default without a working tree
128
self.run_bzr('init subdir')
130
out, err = self.run_bzr('init subdir', retcode=3)
131
# suggests using checkout
132
self.assertContainsRe(err,
133
'ontains a branch.*but no working tree.*checkout')
135
def test_no_defaults(self):
136
"""Init creates no default ignore rules."""
138
self.assertFalse(os.path.exists('.bzrignore'))
140
def test_init_unicode(self):
141
# Make sure getcwd can handle unicode filenames
145
raise TestSkipped("Unable to create Unicode filename")
146
# try to init unicode dir
147
self.run_bzr(['init', '-q', u'mu-\xb5'])
149
def create_simple_tree(self):
150
tree = self.make_branch_and_tree('tree')
151
self.build_tree(['tree/a'])
152
tree.add(['a'], ['a-id'])
153
tree.commit('one', rev_id='r1')
156
def test_init_create_prefix(self):
157
"""'bzr init --create-prefix; will create leading directories."""
158
tree = self.create_simple_tree()
160
self.run_bzr_error(['Parent directory of ../new/tree does not exist'],
161
'init ../new/tree', working_dir='tree')
162
self.run_bzr('init ../new/tree --create-prefix', working_dir='tree')
163
self.failUnlessExists('new/tree/.bzr')
166
class TestSFTPInit(TestCaseWithSFTPServer):
169
# init on a remote url should succeed.
170
out, err = self.run_bzr(['init', '--pack-0.92', self.get_url()])
171
self.assertEqual(out,
172
"""Created a standalone branch (format: pack-0.92)\n""")
173
self.assertEqual('', err)
175
def test_init_existing_branch(self):
176
# when there is already a branch present, make mention
177
self.make_branch('.')
179
# rely on SFTPServer get_url() pointing at '.'
180
out, err = self.run_bzr_error(['Already a branch'],
181
['init', self.get_url()])
183
# make sure using 'bzr checkout' is not suggested
184
# for remote locations missing a working tree
185
self.assertFalse(re.search(r'use bzr checkout', err))
187
def test_init_existing_branch_with_workingtree(self):
188
# don't distinguish between the branch having a working tree or not
189
# when the branch itself is remote.
190
self.make_branch_and_tree('.')
192
# rely on SFTPServer get_url() pointing at '.'
193
self.run_bzr_error(['Already a branch'], ['init', self.get_url()])
195
def test_init_append_revisions_only(self):
196
self.run_bzr('init --dirstate-tags normal_branch6')
197
branch = _mod_branch.Branch.open('normal_branch6')
198
self.assertEqual(False, branch._get_append_revisions_only())
199
self.run_bzr('init --append-revisions-only --dirstate-tags branch6')
200
branch = _mod_branch.Branch.open('branch6')
201
self.assertEqual(True, branch._get_append_revisions_only())
202
self.run_bzr_error(['cannot be set to append-revisions-only'],
203
'init --append-revisions-only --knit knit')