~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_init.py

  • Committer: Aaron Bentley
  • Date: 2006-06-21 14:30:57 UTC
  • mfrom: (1801.1.1 bzr.dev)
  • mto: This revision was merged to the branch mainline in revision 1803.
  • Revision ID: abentley@panoramicfeedback.com-20060621143057-776e4b8d707e430e
Install benchmarks. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007, 2009 Canonical Ltd
2
 
#
 
1
# Copyright (C) 2006 by Canonical Ltd
 
2
 
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
7
 
#
 
7
 
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
11
# GNU General Public License for more details.
12
 
#
 
12
 
13
13
# You should have received a copy of the GNU General Public License
14
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
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
18
18
"""Test "bzr init"""
20
20
import os
21
21
import re
22
22
 
23
 
from bzrlib import (
24
 
    branch as _mod_branch,
25
 
    urlutils,
26
 
    )
27
23
from bzrlib.bzrdir import BzrDirMetaFormat1
28
 
from bzrlib.tests import TestSkipped
29
24
from bzrlib.tests.blackbox import ExternalBase
30
 
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
31
25
from bzrlib.workingtree import WorkingTree
32
26
 
33
27
 
34
28
class TestInit(ExternalBase):
35
29
 
36
 
    def setUp(self):
37
 
        ExternalBase.setUp(self)
38
 
        self._default_label = '2a'
39
 
 
40
30
    def test_init_with_format(self):
41
31
        # Verify bzr init --format constructs something plausible
42
32
        t = self.get_transport()
43
 
        self.run_bzr('init --format default')
 
33
        self.runbzr('init --format default')
44
34
        self.assertIsDirectory('.bzr', t)
45
35
        self.assertIsDirectory('.bzr/checkout', t)
46
36
        self.assertIsDirectory('.bzr/checkout/lock', t)
48
38
    def test_init_weave(self):
49
39
        # --format=weave should be accepted to allow interoperation with
50
40
        # old releases when desired.
51
 
        out, err = self.run_bzr('init --format=weave')
52
 
        self.assertEqual("""Created a standalone tree (format: weave)\n""",
53
 
            out)
54
 
        self.assertEqual('', err)
55
 
 
56
 
    def test_init_format_2a(self):
57
 
        """Smoke test for constructing a format 2a repoistory."""
58
 
        out, err = self.run_bzr('init --format=2a')
59
 
        self.assertEqual("""Created a standalone tree (format: 2a)\n""",
60
 
            out)
 
41
        out, err = self.run_bzr('init', '--format=weave')
 
42
        self.assertEqual('', out)
61
43
        self.assertEqual('', err)
62
44
 
63
45
    def test_init_at_repository_root(self):
69
51
        newdir = format.initialize(t.abspath('repo'))
70
52
        repo = newdir.create_repository(shared=True)
71
53
        repo.set_make_working_trees(False)
72
 
        out, err = self.run_bzr('init repo')
73
 
        self.assertEqual("""Created a repository tree (format: %s)
74
 
Using shared repository: %s
75
 
""" % (self._default_label, urlutils.local_path_from_url(
76
 
            repo.bzrdir.root_transport.external_url())), out)
77
 
        self.assertEndsWith(out, "bzrlib.tests.blackbox.test_init.TestInit."
78
 
            "test_init_at_repository_root/work/repo/\n")
 
54
        out, err = self.run_bzr('init', 'repo')
 
55
        self.assertEqual('', out)
79
56
        self.assertEqual('', err)
80
57
        newdir.open_branch()
81
58
        newdir.open_workingtree()
82
 
 
 
59
        
83
60
    def test_init_branch(self):
84
61
        out, err = self.run_bzr('init')
85
 
        self.assertEqual("Created a standalone tree (format: %s)\n" % (
86
 
            self._default_label,), out)
 
62
        self.assertEqual('', out)
87
63
        self.assertEqual('', err)
88
64
 
89
65
        # Can it handle subdirectories of branches too ?
90
 
        out, err = self.run_bzr('init subdir1')
91
 
        self.assertEqual("Created a standalone tree (format: %s)\n" % (
92
 
            self._default_label,), out)
 
66
        out, err = self.run_bzr('init', 'subdir1')
 
67
        self.assertEqual('', out)
93
68
        self.assertEqual('', err)
94
69
        WorkingTree.open('subdir1')
95
 
 
96
 
        self.run_bzr_error(['Parent directory of subdir2/nothere does not exist'],
97
 
                            'init subdir2/nothere')
98
 
        out, err = self.run_bzr('init subdir2/nothere', retcode=3)
 
70
        
 
71
        out, err = self.run_bzr('init', 'subdir2/nothere', retcode=3)
99
72
        self.assertEqual('', out)
100
 
 
 
73
        self.assertContainsRe(err,
 
74
            r'^bzr: ERROR: .*'
 
75
            '\[Errno 2\] No such file or directory: ')
 
76
        
101
77
        os.mkdir('subdir2')
102
 
        out, err = self.run_bzr('init subdir2')
103
 
        self.assertEqual("Created a standalone tree (format: %s)\n" % (
104
 
            self._default_label,), out)
 
78
        out, err = self.run_bzr('init', 'subdir2')
 
79
        self.assertEqual('', out)
105
80
        self.assertEqual('', err)
106
81
        # init an existing branch.
107
 
        out, err = self.run_bzr('init subdir2', retcode=3)
 
82
        out, err = self.run_bzr('init', 'subdir2', retcode=3)
108
83
        self.assertEqual('', out)
109
84
        self.failUnless(err.startswith('bzr: ERROR: Already a branch:'))
110
85
 
111
 
    def test_init_branch_quiet(self):
112
 
        out, err = self.run_bzr('init -q')
113
 
        self.assertEqual('', out)
114
 
        self.assertEqual('', err)
115
 
 
116
86
    def test_init_existing_branch(self):
117
87
        self.run_bzr('init')
118
88
        out, err = self.run_bzr('init', retcode=3)
122
92
 
123
93
    def test_init_existing_without_workingtree(self):
124
94
        # make a repository
125
 
        repo = self.make_repository('.', shared=True)
126
 
        repo.set_make_working_trees(False)
 
95
        self.run_bzr('init-repo', '.')
127
96
        # make a branch; by default without a working tree
128
 
        self.run_bzr('init subdir')
 
97
        self.run_bzr('init', 'subdir')
129
98
        # fail
130
 
        out, err = self.run_bzr('init subdir', retcode=3)
 
99
        out, err = self.run_bzr('init', 'subdir', retcode=3)
131
100
        # suggests using checkout
132
 
        self.assertContainsRe(err,
133
 
                              'ontains a branch.*but no working tree.*checkout')
134
 
 
135
 
    def test_no_defaults(self):
136
 
        """Init creates no default ignore rules."""
137
 
        self.run_bzr('init')
138
 
        self.assertFalse(os.path.exists('.bzrignore'))
139
 
 
140
 
    def test_init_unicode(self):
141
 
        # Make sure getcwd can handle unicode filenames
142
 
        try:
143
 
            os.mkdir(u'mu-\xb5')
144
 
        except UnicodeError:
145
 
            raise TestSkipped("Unable to create Unicode filename")
146
 
        # try to init unicode dir
147
 
        self.run_bzr(['init', '-q', u'mu-\xb5'])
148
 
 
149
 
    def create_simple_tree(self):
150
 
        tree = self.make_branch_and_tree('tree')
151
 
        self.build_tree(['tree/a'])
152
 
        tree.add(['a'], ['a-id'])
153
 
        tree.commit('one', rev_id='r1')
154
 
        return tree
155
 
 
156
 
    def test_init_create_prefix(self):
157
 
        """'bzr init --create-prefix; will create leading directories."""
158
 
        tree = self.create_simple_tree()
159
 
 
160
 
        self.run_bzr_error(['Parent directory of ../new/tree does not exist'],
161
 
                            'init ../new/tree', working_dir='tree')
162
 
        self.run_bzr('init ../new/tree --create-prefix', working_dir='tree')
163
 
        self.failUnlessExists('new/tree/.bzr')
164
 
 
165
 
 
166
 
class TestSFTPInit(TestCaseWithSFTPServer):
167
 
 
168
 
    def test_init(self):
169
 
        # init on a remote url should succeed.
170
 
        out, err = self.run_bzr(['init', '--pack-0.92', self.get_url()])
171
 
        self.assertEqual(out,
172
 
            """Created a standalone branch (format: pack-0.92)\n""")
173
 
        self.assertEqual('', err)
174
 
 
175
 
    def test_init_existing_branch(self):
176
 
        # when there is already a branch present, make mention
177
 
        self.make_branch('.')
178
 
 
179
 
        # rely on SFTPServer get_url() pointing at '.'
180
 
        out, err = self.run_bzr_error(['Already a branch'],
181
 
                                      ['init', self.get_url()])
182
 
 
183
 
        # make sure using 'bzr checkout' is not suggested
184
 
        # for remote locations missing a working tree
185
 
        self.assertFalse(re.search(r'use bzr checkout', err))
186
 
 
187
 
    def test_init_existing_branch_with_workingtree(self):
188
 
        # don't distinguish between the branch having a working tree or not
189
 
        # when the branch itself is remote.
190
 
        self.make_branch_and_tree('.')
191
 
 
192
 
        # rely on SFTPServer get_url() pointing at '.'
193
 
        self.run_bzr_error(['Already a branch'], ['init', self.get_url()])
194
 
 
195
 
    def test_init_append_revisions_only(self):
196
 
        self.run_bzr('init --dirstate-tags normal_branch6')
197
 
        branch = _mod_branch.Branch.open('normal_branch6')
198
 
        self.assertEqual(False, branch._get_append_revisions_only())
199
 
        self.run_bzr('init --append-revisions-only --dirstate-tags branch6')
200
 
        branch = _mod_branch.Branch.open('branch6')
201
 
        self.assertEqual(True, branch._get_append_revisions_only())
202
 
        self.run_bzr_error(['cannot be set to append-revisions-only'],
203
 
                           'init --append-revisions-only --knit knit')
 
101
        self.assertContainsRe(err, 'ontains a branch.*but no working tree.*checkout')
 
102