1
# Copyright (C) 2006, 2007 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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_at_repository_root(self):
53
# bzr init at the root of a repository should create a branch
54
# and working tree even when creation of working trees is disabled.
55
t = self.get_transport()
57
format = BzrDirMetaFormat1()
58
newdir = format.initialize(t.abspath('repo'))
59
repo = newdir.create_repository(shared=True)
60
repo.set_make_working_trees(False)
61
out, err = self.run_bzr('init repo')
62
self.assertEqual("""Created a repository tree (format: pack-0.92)
63
Using shared repository: %s
64
""" % urlutils.local_path_from_url(
65
repo.bzrdir.root_transport.external_url()), out)
66
self.assertEndsWith(out, "bzrlib.tests.blackbox.test_init.TestInit."
67
"test_init_at_repository_root/work/repo/\n")
68
self.assertEqual('', err)
70
newdir.open_workingtree()
72
def test_init_branch(self):
73
out, err = self.run_bzr('init')
74
self.assertEqual("""Created a standalone tree (format: pack-0.92)\n""",
76
self.assertEqual('', err)
78
# Can it handle subdirectories of branches too ?
79
out, err = self.run_bzr('init subdir1')
80
self.assertEqual("""Created a standalone tree (format: pack-0.92)\n""",
82
self.assertEqual('', err)
83
WorkingTree.open('subdir1')
85
self.run_bzr_error(['Parent directory of subdir2/nothere does not exist'],
86
'init subdir2/nothere')
87
out, err = self.run_bzr('init subdir2/nothere', retcode=3)
88
self.assertEqual('', out)
91
out, err = self.run_bzr('init subdir2')
92
self.assertEqual("""Created a standalone tree (format: pack-0.92)\n""",
94
self.assertEqual('', err)
95
# init an existing branch.
96
out, err = self.run_bzr('init subdir2', retcode=3)
97
self.assertEqual('', out)
98
self.failUnless(err.startswith('bzr: ERROR: Already a branch:'))
100
def test_init_branch_quiet(self):
101
out, err = self.run_bzr('init -q')
102
self.assertEqual('', out)
103
self.assertEqual('', err)
105
def test_init_existing_branch(self):
107
out, err = self.run_bzr('init', retcode=3)
108
self.assertContainsRe(err, 'Already a branch')
109
# don't suggest making a checkout, there's already a working tree
110
self.assertFalse(re.search(r'checkout', err))
112
def test_init_existing_without_workingtree(self):
114
repo = self.make_repository('.', shared=True)
115
repo.set_make_working_trees(False)
116
# make a branch; by default without a working tree
117
self.run_bzr('init subdir')
119
out, err = self.run_bzr('init subdir', retcode=3)
120
# suggests using checkout
121
self.assertContainsRe(err,
122
'ontains a branch.*but no working tree.*checkout')
124
def test_no_defaults(self):
125
"""Init creates no default ignore rules."""
127
self.assertFalse(os.path.exists('.bzrignore'))
129
def test_init_unicode(self):
130
# Make sure getcwd can handle unicode filenames
134
raise TestSkipped("Unable to create Unicode filename")
135
# try to init unicode dir
136
self.run_bzr(['init', '-q', u'mu-\xb5'])
138
def create_simple_tree(self):
139
tree = self.make_branch_and_tree('tree')
140
self.build_tree(['tree/a'])
141
tree.add(['a'], ['a-id'])
142
tree.commit('one', rev_id='r1')
145
def test_init_create_prefix(self):
146
"""'bzr init --create-prefix; will create leading directories."""
147
tree = self.create_simple_tree()
149
self.run_bzr_error(['Parent directory of ../new/tree does not exist'],
150
'init ../new/tree', working_dir='tree')
151
self.run_bzr('init ../new/tree --create-prefix', working_dir='tree')
152
self.failUnlessExists('new/tree/.bzr')
155
class TestSFTPInit(TestCaseWithSFTPServer):
158
# init on a remote url should succeed.
159
out, err = self.run_bzr(['init', self.get_url()])
160
self.assertEqual(out,
161
"""Created a standalone branch (format: pack-0.92)\n""")
162
self.assertEqual('', err)
164
def test_init_existing_branch(self):
165
# when there is already a branch present, make mention
166
self.make_branch('.')
168
# rely on SFTPServer get_url() pointing at '.'
169
out, err = self.run_bzr_error(['Already a branch'],
170
['init', self.get_url()])
172
# make sure using 'bzr checkout' is not suggested
173
# for remote locations missing a working tree
174
self.assertFalse(re.search(r'use bzr checkout', err))
176
def test_init_existing_branch_with_workingtree(self):
177
# don't distinguish between the branch having a working tree or not
178
# when the branch itself is remote.
179
self.make_branch_and_tree('.')
181
# rely on SFTPServer get_url() pointing at '.'
182
self.run_bzr_error(['Already a branch'], ['init', self.get_url()])
184
def test_init_append_revisions_only(self):
185
self.run_bzr('init --dirstate-tags normal_branch6')
186
branch = _mod_branch.Branch.open('normal_branch6')
187
self.assertEqual(False, branch._get_append_revisions_only())
188
self.run_bzr('init --append-revisions-only --dirstate-tags branch6')
189
branch = _mod_branch.Branch.open('branch6')
190
self.assertEqual(True, branch._get_append_revisions_only())
191
self.run_bzr_error(['cannot be set to append-revisions-only'],
192
'init --append-revisions-only --knit knit')