~bzr-pqm/bzr/bzr.dev

1553.5.78 by Martin Pool
New bzr init --format option and test
1
# Copyright (C) 2006 by Canonical Ltd
2
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.
7
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.
12
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
16
17
18
"""Test "bzr init"""
19
1654.1.4 by Robert Collins
Teach `bzr init` how to init at the root of a repository.
20
import os
1662.1.19 by Martin Pool
Better error message when initting existing tree
21
import re
1553.5.78 by Martin Pool
New bzr init --format option and test
22
1654.1.4 by Robert Collins
Teach `bzr init` how to init at the root of a repository.
23
from bzrlib.bzrdir import BzrDirMetaFormat1
1553.5.78 by Martin Pool
New bzr init --format option and test
24
from bzrlib.tests.blackbox import ExternalBase
1654.1.4 by Robert Collins
Teach `bzr init` how to init at the root of a repository.
25
from bzrlib.workingtree import WorkingTree
1553.5.78 by Martin Pool
New bzr init --format option and test
26
27
28
class TestInit(ExternalBase):
29
30
    def test_init_with_format(self):
1666.1.3 by Robert Collins
Fix and test upgrades from bzrdir 6 over SFTP.
31
        # Verify bzr init --format constructs something plausible
1553.5.78 by Martin Pool
New bzr init --format option and test
32
        t = self.get_transport()
1694.2.6 by Martin Pool
[merge] bzr.dev
33
        self.runbzr('init --format default')
1553.5.78 by Martin Pool
New bzr init --format option and test
34
        self.assertIsDirectory('.bzr', t)
35
        self.assertIsDirectory('.bzr/checkout', t)
36
        self.assertIsDirectory('.bzr/checkout/lock', t)
1654.1.4 by Robert Collins
Teach `bzr init` how to init at the root of a repository.
37
1666.1.3 by Robert Collins
Fix and test upgrades from bzrdir 6 over SFTP.
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)
44
1654.1.4 by Robert Collins
Teach `bzr init` how to init at the root of a repository.
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()
49
        t.mkdir('repo')
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)
57
        newdir.open_branch()
58
        newdir.open_workingtree()
59
        
60
    def test_init_branch(self):
61
        out, err = self.run_bzr('init')
62
        self.assertEqual('', out)
63
        self.assertEqual('', err)
64
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')
70
        
71
        out, err = self.run_bzr('init', 'subdir2/nothere', retcode=3)
72
        self.assertEqual('', out)
1740.5.3 by Martin Pool
Cleanup more exception-formatting code
73
        self.assertContainsRe(err,
1740.5.6 by Martin Pool
Clean up many exception classes.
74
            r'^bzr: ERROR: .*'
1740.5.3 by Martin Pool
Cleanup more exception-formatting code
75
            '\[Errno 2\] No such file or directory: ')
1654.1.4 by Robert Collins
Teach `bzr init` how to init at the root of a repository.
76
        
77
        os.mkdir('subdir2')
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:'))
1662.1.19 by Martin Pool
Better error message when initting existing tree
85
86
    def test_init_existing_branch(self):
87
        self.run_bzr('init')
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))
92
93
    def test_init_existing_without_workingtree(self):
94
        # make a repository
95
        self.run_bzr('init-repo', '.')
96
        # make a branch; by default without a working tree
97
        self.run_bzr('init', 'subdir')
98
        # fail
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')
102
1765.1.1 by Robert Collins
Remove the default ignores list from bzr, lowering the minimum overhead in bzr add.
103
    def test_no_defaults(self):
104
        """Init creates no default ignore rules."""
105
        self.run_bzr('init')
106
        self.assertFalse(os.path.exists('.bzrignore'))