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):
36
def test_init_with_format(self):
37
# Verify bzr init --format constructs something plausible
38
t = self.get_transport()
39
self.run_bzr('init --format default')
40
self.assertIsDirectory('.bzr', t)
41
self.assertIsDirectory('.bzr/checkout', t)
42
self.assertIsDirectory('.bzr/checkout/lock', t)
44
def test_init_weave(self):
45
# --format=weave should be accepted to allow interoperation with
46
# old releases when desired.
47
out, err = self.run_bzr('init --format=weave')
48
self.assertEqual("""Created a standalone tree (format: weave)\n""",
50
self.assertEqual('', err)
52
def test_init_format_2a(self):
53
"""Smoke test for constructing a format 2a repoistory."""
54
out, err = self.run_bzr('init --format=2a')
55
self.assertEqual("""Created a standalone tree (format: 2a)\n""",
57
self.assertEqual('', err)
59
def test_init_at_repository_root(self):
60
# bzr init at the root of a repository should create a branch
61
# and working tree even when creation of working trees is disabled.
62
t = self.get_transport()
64
format = BzrDirMetaFormat1()
65
newdir = format.initialize(t.abspath('repo'))
66
repo = newdir.create_repository(shared=True)
67
repo.set_make_working_trees(False)
68
out, err = self.run_bzr('init repo')
69
self.assertEqual("""Created a repository tree (format: pack-0.92)
70
Using shared repository: %s
71
""" % urlutils.local_path_from_url(
72
repo.bzrdir.root_transport.external_url()), out)
73
self.assertEndsWith(out, "bzrlib.tests.blackbox.test_init.TestInit."
74
"test_init_at_repository_root/work/repo/\n")
75
self.assertEqual('', err)
77
newdir.open_workingtree()
79
def test_init_branch(self):
80
out, err = self.run_bzr('init')
81
self.assertEqual("""Created a standalone tree (format: pack-0.92)\n""",
83
self.assertEqual('', err)
85
# Can it handle subdirectories of branches too ?
86
out, err = self.run_bzr('init subdir1')
87
self.assertEqual("""Created a standalone tree (format: pack-0.92)\n""",
89
self.assertEqual('', err)
90
WorkingTree.open('subdir1')
92
self.run_bzr_error(['Parent directory of subdir2/nothere does not exist'],
93
'init subdir2/nothere')
94
out, err = self.run_bzr('init subdir2/nothere', retcode=3)
95
self.assertEqual('', out)
98
out, err = self.run_bzr('init subdir2')
99
self.assertEqual("""Created a standalone tree (format: pack-0.92)\n""",
101
self.assertEqual('', err)
102
# init an existing branch.
103
out, err = self.run_bzr('init subdir2', retcode=3)
104
self.assertEqual('', out)
105
self.failUnless(err.startswith('bzr: ERROR: Already a branch:'))
107
def test_init_branch_quiet(self):
108
out, err = self.run_bzr('init -q')
109
self.assertEqual('', out)
110
self.assertEqual('', err)
112
def test_init_existing_branch(self):
114
out, err = self.run_bzr('init', retcode=3)
115
self.assertContainsRe(err, 'Already a branch')
116
# don't suggest making a checkout, there's already a working tree
117
self.assertFalse(re.search(r'checkout', err))
119
def test_init_existing_without_workingtree(self):
121
repo = self.make_repository('.', shared=True)
122
repo.set_make_working_trees(False)
123
# make a branch; by default without a working tree
124
self.run_bzr('init subdir')
126
out, err = self.run_bzr('init subdir', retcode=3)
127
# suggests using checkout
128
self.assertContainsRe(err,
129
'ontains a branch.*but no working tree.*checkout')
131
def test_no_defaults(self):
132
"""Init creates no default ignore rules."""
134
self.assertFalse(os.path.exists('.bzrignore'))
136
def test_init_unicode(self):
137
# Make sure getcwd can handle unicode filenames
141
raise TestSkipped("Unable to create Unicode filename")
142
# try to init unicode dir
143
self.run_bzr(['init', '-q', u'mu-\xb5'])
145
def create_simple_tree(self):
146
tree = self.make_branch_and_tree('tree')
147
self.build_tree(['tree/a'])
148
tree.add(['a'], ['a-id'])
149
tree.commit('one', rev_id='r1')
152
def test_init_create_prefix(self):
153
"""'bzr init --create-prefix; will create leading directories."""
154
tree = self.create_simple_tree()
156
self.run_bzr_error(['Parent directory of ../new/tree does not exist'],
157
'init ../new/tree', working_dir='tree')
158
self.run_bzr('init ../new/tree --create-prefix', working_dir='tree')
159
self.failUnlessExists('new/tree/.bzr')
162
class TestSFTPInit(TestCaseWithSFTPServer):
165
# init on a remote url should succeed.
166
out, err = self.run_bzr(['init', self.get_url()])
167
self.assertEqual(out,
168
"""Created a standalone branch (format: pack-0.92)\n""")
169
self.assertEqual('', err)
171
def test_init_existing_branch(self):
172
# when there is already a branch present, make mention
173
self.make_branch('.')
175
# rely on SFTPServer get_url() pointing at '.'
176
out, err = self.run_bzr_error(['Already a branch'],
177
['init', self.get_url()])
179
# make sure using 'bzr checkout' is not suggested
180
# for remote locations missing a working tree
181
self.assertFalse(re.search(r'use bzr checkout', err))
183
def test_init_existing_branch_with_workingtree(self):
184
# don't distinguish between the branch having a working tree or not
185
# when the branch itself is remote.
186
self.make_branch_and_tree('.')
188
# rely on SFTPServer get_url() pointing at '.'
189
self.run_bzr_error(['Already a branch'], ['init', self.get_url()])
191
def test_init_append_revisions_only(self):
192
self.run_bzr('init --dirstate-tags normal_branch6')
193
branch = _mod_branch.Branch.open('normal_branch6')
194
self.assertEqual(False, branch._get_append_revisions_only())
195
self.run_bzr('init --append-revisions-only --dirstate-tags branch6')
196
branch = _mod_branch.Branch.open('branch6')
197
self.assertEqual(True, branch._get_append_revisions_only())
198
self.run_bzr_error(['cannot be set to append-revisions-only'],
199
'init --append-revisions-only --knit knit')