1
# Copyright (C) 2006 by 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
22
from bzrlib.bzrdir import BzrDirMetaFormat1
23
from bzrlib.tests.blackbox import ExternalBase
24
from bzrlib.workingtree import WorkingTree
27
class TestInit(ExternalBase):
29
def test_init_with_format(self):
30
"""Verify bzr init --format constructs something plausible"""
31
t = self.get_transport()
32
self.runbzr('init --format metadir')
33
self.assertIsDirectory('.bzr', t)
34
self.assertIsDirectory('.bzr/checkout', t)
35
self.assertIsDirectory('.bzr/checkout/lock', t)
37
def test_init_at_repository_root(self):
38
# bzr init at the root of a repository should create a branch
39
# and working tree even when creation of working trees is disabled.
40
t = self.get_transport()
42
format = BzrDirMetaFormat1()
43
newdir = format.initialize(t.abspath('repo'))
44
repo = newdir.create_repository(shared=True)
45
repo.set_make_working_trees(False)
46
out, err = self.run_bzr('init', 'repo')
47
self.assertEqual('', out)
48
self.assertEqual('', err)
50
newdir.open_workingtree()
52
def test_init_branch(self):
53
out, err = self.run_bzr('init')
54
self.assertEqual('', out)
55
self.assertEqual('', err)
57
# Can it handle subdirectories of branches too ?
58
out, err = self.run_bzr('init', 'subdir1')
59
self.assertEqual('', out)
60
self.assertEqual('', err)
61
WorkingTree.open('subdir1')
63
out, err = self.run_bzr('init', 'subdir2/nothere', retcode=3)
64
self.assertEqual('', out)
65
self.failUnless(err.startswith(
66
'bzr: ERROR: exceptions.OSError: '
67
'[Errno 2] No such file or directory: '))
70
out, err = self.run_bzr('init', 'subdir2')
71
self.assertEqual('', out)
72
self.assertEqual('', err)
73
# init an existing branch.
74
out, err = self.run_bzr('init', 'subdir2', retcode=3)
75
self.assertEqual('', out)
76
self.failUnless(err.startswith('bzr: ERROR: Already a branch:'))