~bzr-pqm/bzr/bzr.dev

2257.2.2 by Wouter van Heyst
Actually test that `bzr init-repo --{no,}-trees` still works
1
# Copyright (C) 2006, 2007 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
1553.5.78 by Martin Pool
New bzr init --format option and test
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
7
#
1553.5.78 by Martin Pool
New bzr init --format option and test
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
12
#
1553.5.78 by Martin Pool
New bzr init --format option and test
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
2230.3.42 by Aaron Bentley
add --append-revisions-only option to init
23
from bzrlib import (
24
    branch as _mod_branch,
25
    )
1654.1.4 by Robert Collins
Teach `bzr init` how to init at the root of a repository.
26
from bzrlib.bzrdir import BzrDirMetaFormat1
2294.2.1 by Alexander Belchenko
Bugfix #85599: ``bzr init`` works with unicode argument LOCATION
27
from bzrlib.tests import TestSkipped
1553.5.78 by Martin Pool
New bzr init --format option and test
28
from bzrlib.tests.blackbox import ExternalBase
1830.4.1 by Wouter van Heyst
Allow bzr init to create remote branches
29
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
1654.1.4 by Robert Collins
Teach `bzr init` how to init at the root of a repository.
30
from bzrlib.workingtree import WorkingTree
1553.5.78 by Martin Pool
New bzr init --format option and test
31
32
33
class TestInit(ExternalBase):
34
35
    def test_init_with_format(self):
1666.1.3 by Robert Collins
Fix and test upgrades from bzrdir 6 over SFTP.
36
        # Verify bzr init --format constructs something plausible
1553.5.78 by Martin Pool
New bzr init --format option and test
37
        t = self.get_transport()
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
38
        self.run_bzr('init --format default')
1553.5.78 by Martin Pool
New bzr init --format option and test
39
        self.assertIsDirectory('.bzr', t)
40
        self.assertIsDirectory('.bzr/checkout', t)
41
        self.assertIsDirectory('.bzr/checkout/lock', t)
1654.1.4 by Robert Collins
Teach `bzr init` how to init at the root of a repository.
42
1666.1.3 by Robert Collins
Fix and test upgrades from bzrdir 6 over SFTP.
43
    def test_init_weave(self):
1857.1.20 by Aaron Bentley
Strip out all the EnumOption stuff
44
        # --format=weave should be accepted to allow interoperation with
1666.1.3 by Robert Collins
Fix and test upgrades from bzrdir 6 over SFTP.
45
        # old releases when desired.
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
46
        out, err = self.run_bzr('init --format=weave')
3535.9.2 by Marius Kruger
make init and init-repo tests pass again
47
        self.assertEqual("""Standalone tree (format: weave)
48
Location:
49
  branch root: .
50
""", out)
1666.1.3 by Robert Collins
Fix and test upgrades from bzrdir 6 over SFTP.
51
        self.assertEqual('', err)
52
1654.1.4 by Robert Collins
Teach `bzr init` how to init at the root of a repository.
53
    def test_init_at_repository_root(self):
54
        # bzr init at the root of a repository should create a branch
55
        # and working tree even when creation of working trees is disabled.
56
        t = self.get_transport()
57
        t.mkdir('repo')
58
        format = BzrDirMetaFormat1()
59
        newdir = format.initialize(t.abspath('repo'))
60
        repo = newdir.create_repository(shared=True)
61
        repo.set_make_working_trees(False)
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
62
        out, err = self.run_bzr('init repo')
3535.9.2 by Marius Kruger
make init and init-repo tests pass again
63
        self.assertEqual(
64
"""Repository tree (format: pack-0.92)
65
Location:
66
  shared repository: repo
67
  repository branch: repo
68
""", out)
1654.1.4 by Robert Collins
Teach `bzr init` how to init at the root of a repository.
69
        self.assertEqual('', err)
70
        newdir.open_branch()
71
        newdir.open_workingtree()
72
        
73
    def test_init_branch(self):
74
        out, err = self.run_bzr('init')
3535.9.2 by Marius Kruger
make init and init-repo tests pass again
75
        self.assertEqual(
76
"""Standalone tree (format: pack-0.92)
77
Location:
78
  branch root: .
79
""", out)
1654.1.4 by Robert Collins
Teach `bzr init` how to init at the root of a repository.
80
        self.assertEqual('', err)
81
82
        # Can it handle subdirectories of branches too ?
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
83
        out, err = self.run_bzr('init subdir1')
3535.9.2 by Marius Kruger
make init and init-repo tests pass again
84
        self.assertEqual(
85
"""Standalone tree (format: pack-0.92)
86
Location:
87
  branch root: subdir1
88
""", out)
1654.1.4 by Robert Collins
Teach `bzr init` how to init at the root of a repository.
89
        self.assertEqual('', err)
90
        WorkingTree.open('subdir1')
91
        
2524.1.1 by Aaron Bentley
Revert broken changes
92
        self.run_bzr_error(['Parent directory of subdir2/nothere does not exist'],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
93
                            'init subdir2/nothere')
94
        out, err = self.run_bzr('init subdir2/nothere', retcode=3)
1654.1.4 by Robert Collins
Teach `bzr init` how to init at the root of a repository.
95
        self.assertEqual('', out)
96
        
97
        os.mkdir('subdir2')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
98
        out, err = self.run_bzr('init subdir2')
3535.9.2 by Marius Kruger
make init and init-repo tests pass again
99
        self.assertEqual("""Standalone tree (format: pack-0.92)
100
Location:
101
  branch root: subdir2
102
""", out)
1654.1.4 by Robert Collins
Teach `bzr init` how to init at the root of a repository.
103
        self.assertEqual('', err)
104
        # init an existing branch.
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
105
        out, err = self.run_bzr('init subdir2', retcode=3)
1654.1.4 by Robert Collins
Teach `bzr init` how to init at the root of a repository.
106
        self.assertEqual('', out)
107
        self.failUnless(err.startswith('bzr: ERROR: Already a branch:'))
1662.1.19 by Martin Pool
Better error message when initting existing tree
108
3535.9.6 by Marius Kruger
add explicit blackbox tests for 'init -q' and 'init-repo -q'
109
    def test_init_branch_quiet(self):
110
        out, err = self.run_bzr('init -q')
111
        self.assertEqual('', out)
112
        self.assertEqual('', err)
113
1662.1.19 by Martin Pool
Better error message when initting existing tree
114
    def test_init_existing_branch(self):
115
        self.run_bzr('init')
116
        out, err = self.run_bzr('init', retcode=3)
117
        self.assertContainsRe(err, 'Already a branch')
118
        # don't suggest making a checkout, there's already a working tree
119
        self.assertFalse(re.search(r'checkout', err))
120
121
    def test_init_existing_without_workingtree(self):
122
        # make a repository
2257.2.1 by Wouter van Heyst
Change the ui level default for init-repo to --trees.
123
        repo = self.make_repository('.', shared=True)
124
        repo.set_make_working_trees(False)
1662.1.19 by Martin Pool
Better error message when initting existing tree
125
        # make a branch; by default without a working tree
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
126
        self.run_bzr('init subdir')
1662.1.19 by Martin Pool
Better error message when initting existing tree
127
        # fail
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
128
        out, err = self.run_bzr('init subdir', retcode=3)
1662.1.19 by Martin Pool
Better error message when initting existing tree
129
        # suggests using checkout
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
130
        self.assertContainsRe(err,
131
                              'ontains a branch.*but no working tree.*checkout')
1662.1.19 by Martin Pool
Better error message when initting existing tree
132
1765.1.1 by Robert Collins
Remove the default ignores list from bzr, lowering the minimum overhead in bzr add.
133
    def test_no_defaults(self):
134
        """Init creates no default ignore rules."""
135
        self.run_bzr('init')
136
        self.assertFalse(os.path.exists('.bzrignore'))
1830.4.1 by Wouter van Heyst
Allow bzr init to create remote branches
137
2294.2.1 by Alexander Belchenko
Bugfix #85599: ``bzr init`` works with unicode argument LOCATION
138
    def test_init_unicode(self):
139
        # Make sure getcwd can handle unicode filenames
140
        try:
141
            os.mkdir(u'mu-\xb5')
142
        except UnicodeError:
143
            raise TestSkipped("Unable to create Unicode filename")
144
        # try to init unicode dir
3697.5.4 by John Arbash Meinel
Merge vila's init[-repo] changes and add a NEWS entry.
145
        self.run_bzr(['init', '-q', u'mu-\xb5'])
2294.2.1 by Alexander Belchenko
Bugfix #85599: ``bzr init`` works with unicode argument LOCATION
146
2524.1.1 by Aaron Bentley
Revert broken changes
147
    def create_simple_tree(self):
148
        tree = self.make_branch_and_tree('tree')
149
        self.build_tree(['tree/a'])
150
        tree.add(['a'], ['a-id'])
151
        tree.commit('one', rev_id='r1')
152
        return tree
153
154
    def test_init_create_prefix(self):
155
        """'bzr init --create-prefix; will create leading directories."""
156
        tree = self.create_simple_tree()
157
158
        self.run_bzr_error(['Parent directory of ../new/tree does not exist'],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
159
                            'init ../new/tree', working_dir='tree')
160
        self.run_bzr('init ../new/tree --create-prefix', working_dir='tree')
2524.1.1 by Aaron Bentley
Revert broken changes
161
        self.failUnlessExists('new/tree/.bzr')
162
1830.4.7 by Wouter van Heyst
review fixes, rename transport variable to to_transport
163
1830.4.1 by Wouter van Heyst
Allow bzr init to create remote branches
164
class TestSFTPInit(TestCaseWithSFTPServer):
165
166
    def test_init(self):
1830.4.3 by Wouter van Heyst
more review comments
167
        # init on a remote url should succeed.
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
168
        out, err = self.run_bzr(['init', self.get_url()])
3535.9.2 by Marius Kruger
make init and init-repo tests pass again
169
        self.assertStartsWith(out, """Standalone branch (format: pack-0.92)
170
Location:
171
  branch root: """)
1830.4.1 by Wouter van Heyst
Allow bzr init to create remote branches
172
        self.assertEqual('', err)
1830.4.3 by Wouter van Heyst
more review comments
173
    
174
    def test_init_existing_branch(self):
175
        # when there is already a branch present, make mention
1830.4.4 by Wouter van Heyst
more review comments
176
        self.make_branch('.')
177
178
        # rely on SFTPServer get_url() pointing at '.'
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
179
        out, err = self.run_bzr_error(['Already a branch'],
180
                                      ['init', self.get_url()])
1830.4.5 by Wouter van Heyst
cleanup
181
182
        # make sure using 'bzr checkout' is not suggested
183
        # for remote locations missing a working tree
2264.1.1 by Martin Pool
make TestSFTPInit.test_init_existing_branch less fragile (jamesw)
184
        self.assertFalse(re.search(r'use bzr checkout', err))
1830.4.1 by Wouter van Heyst
Allow bzr init to create remote branches
185
1830.4.4 by Wouter van Heyst
more review comments
186
    def test_init_existing_branch_with_workingtree(self):
1830.4.3 by Wouter van Heyst
more review comments
187
        # don't distinguish between the branch having a working tree or not
188
        # when the branch itself is remote.
189
        self.make_branch_and_tree('.')
190
191
        # rely on SFTPServer get_url() pointing at '.'
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
192
        self.run_bzr_error(['Already a branch'], ['init', self.get_url()])
2230.3.42 by Aaron Bentley
add --append-revisions-only option to init
193
194
    def test_init_append_revisions_only(self):
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
195
        self.run_bzr('init --dirstate-tags normal_branch6')
2230.3.42 by Aaron Bentley
add --append-revisions-only option to init
196
        branch = _mod_branch.Branch.open('normal_branch6')
197
        self.assertEqual(False, branch._get_append_revisions_only())
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
198
        self.run_bzr('init --append-revisions-only --dirstate-tags branch6')
2230.3.42 by Aaron Bentley
add --append-revisions-only option to init
199
        branch = _mod_branch.Branch.open('branch6')
200
        self.assertEqual(True, branch._get_append_revisions_only())
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
201
        self.run_bzr_error(['cannot be set to append-revisions-only'],
202
                           'init --append-revisions-only --knit knit')