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
23
from bzrlib.bzrdir import BzrDirMetaFormat1
24
from bzrlib.tests.blackbox import ExternalBase
25
from bzrlib.workingtree import WorkingTree
28
class TestInit(ExternalBase):
30
def test_init_with_format(self):
31
# Verify bzr init --format constructs something plausible
32
t = self.get_transport()
33
self.runbzr('init --format default')
34
self.assertIsDirectory('.bzr', t)
35
self.assertIsDirectory('.bzr/checkout', t)
36
self.assertIsDirectory('.bzr/checkout/lock', t)
38
def test_init_weave(self):
39
# --format=weave should be accepted to allow interoperation with
40
# old releases when desired.
41
out, err = self.run_bzr('init', '--format=weave')
42
self.assertEqual('', out)
43
self.assertEqual('', err)
45
def test_init_at_repository_root(self):
46
# bzr init at the root of a repository should create a branch
47
# and working tree even when creation of working trees is disabled.
48
t = self.get_transport()
50
format = BzrDirMetaFormat1()
51
newdir = format.initialize(t.abspath('repo'))
52
repo = newdir.create_repository(shared=True)
53
repo.set_make_working_trees(False)
54
out, err = self.run_bzr('init', 'repo')
55
self.assertEqual('', out)
56
self.assertEqual('', err)
58
newdir.open_workingtree()
60
def test_init_branch(self):
61
out, err = self.run_bzr('init')
62
self.assertEqual('', out)
63
self.assertEqual('', err)
65
# Can it handle subdirectories of branches too ?
66
out, err = self.run_bzr('init', 'subdir1')
67
self.assertEqual('', out)
68
self.assertEqual('', err)
69
WorkingTree.open('subdir1')
71
out, err = self.run_bzr('init', 'subdir2/nothere', retcode=3)
72
self.assertEqual('', out)
73
self.assertContainsRe(err,
75
'\[Errno 2\] No such file or directory: ')
78
out, err = self.run_bzr('init', 'subdir2')
79
self.assertEqual('', out)
80
self.assertEqual('', err)
81
# init an existing branch.
82
out, err = self.run_bzr('init', 'subdir2', retcode=3)
83
self.assertEqual('', out)
84
self.failUnless(err.startswith('bzr: ERROR: Already a branch:'))
86
def test_init_existing_branch(self):
88
out, err = self.run_bzr('init', retcode=3)
89
self.assertContainsRe(err, 'Already a branch')
90
# don't suggest making a checkout, there's already a working tree
91
self.assertFalse(re.search(r'checkout', err))
93
def test_init_existing_without_workingtree(self):
95
self.run_bzr('init-repo', '.')
96
# make a branch; by default without a working tree
97
self.run_bzr('init', 'subdir')
99
out, err = self.run_bzr('init', 'subdir', retcode=3)
100
# suggests using checkout
101
self.assertContainsRe(err, 'ontains a branch.*but no working tree.*checkout')