/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5557.1.7 by John Arbash Meinel
Merge in the bzr.dev 5582
1
# Copyright (C) 2006-2011 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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1553.5.78 by Martin Pool
New bzr init --format option and test
16
17
6622.1.29 by Jelmer Vernooij
Fix some more tests.
18
"""Test 'brz init'"""
1553.5.78 by Martin Pool
New bzr init --format option and test
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
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
23
from breezy import (
2230.3.42 by Aaron Bentley
add --append-revisions-only option to init
24
    branch as _mod_branch,
5448.4.2 by Neil Martinsen-Burrell
blackbox test
25
    config as _mod_config,
4789.8.1 by John Arbash Meinel
Don't make explicit assumptions about testing current working dir.
26
    osutils,
3922.2.1 by Marius Kruger
make `bzr init` less verbose, and update tests
27
    urlutils,
2230.3.42 by Aaron Bentley
add --append-revisions-only option to init
28
    )
6670.4.3 by Jelmer Vernooij
Fix more imports.
29
from breezy.bzr.bzrdir import BzrDirMetaFormat1
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
30
from breezy.tests import TestSkipped
31
from breezy.tests import TestCaseWithTransport
32
from breezy.tests.test_sftp_transport import TestCaseWithSFTPServer
33
from breezy.workingtree import WorkingTree
1553.5.78 by Martin Pool
New bzr init --format option and test
34
35
5283.4.5 by Martin Pool
Update remaining subclasses of ExternalBase
36
class TestInit(TestCaseWithTransport):
1553.5.78 by Martin Pool
New bzr init --format option and test
37
4599.1.1 by Robert Collins
Make blackbox init tests able to be trivially changed to 2a.
38
    def setUp(self):
6552.1.4 by Vincent Ladeuil
Remaining tests matching setup(self) that can be rewritten with super().
39
        super(TestInit, self).setUp()
4599.4.5 by Robert Collins
Blackbox init tests 2a ready.
40
        self._default_label = '2a'
4599.1.1 by Robert Collins
Make blackbox init tests able to be trivially changed to 2a.
41
1553.5.78 by Martin Pool
New bzr init --format option and test
42
    def test_init_with_format(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
43
        # Verify brz init --format constructs something plausible
1553.5.78 by Martin Pool
New bzr init --format option and test
44
        t = self.get_transport()
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
45
        self.run_bzr('init --format default')
1553.5.78 by Martin Pool
New bzr init --format option and test
46
        self.assertIsDirectory('.bzr', t)
47
        self.assertIsDirectory('.bzr/checkout', t)
48
        self.assertIsDirectory('.bzr/checkout/lock', t)
1654.1.4 by Robert Collins
Teach `bzr init` how to init at the root of a repository.
49
4428.2.1 by Martin Pool
Add 2a format
50
    def test_init_format_2a(self):
6083.2.4 by Jelmer Vernooij
Add test for creating a colocated branch.
51
        """Smoke test for constructing a format 2a repository."""
4428.2.1 by Martin Pool
Add 2a format
52
        out, err = self.run_bzr('init --format=2a')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
53
        self.assertEqual("""Created a standalone tree (format: 2a)\n""",
4428.2.1 by Martin Pool
Add 2a format
54
            out)
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
55
        self.assertEqual('', err)
4428.2.1 by Martin Pool
Add 2a format
56
6929.7.1 by Jelmer Vernooij
Add a 'bzr' format alias.
57
    def test_init_format_bzr(self):
58
        """Smoke test for constructing a format with the 'bzr' alias."""
59
        out, err = self.run_bzr('init --format=bzr')
60
        self.assertEqual(
61
            "Created a standalone tree (format: %s)\n" % self._default_label,
62
            out)
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
63
        self.assertEqual('', err)
6929.7.1 by Jelmer Vernooij
Add a 'bzr' format alias.
64
6083.2.4 by Jelmer Vernooij
Add test for creating a colocated branch.
65
    def test_init_colocated(self):
66
        """Smoke test for constructing a colocated branch."""
6083.2.11 by Jelmer Vernooij
Add development-colo format.
67
        out, err = self.run_bzr('init --format=development-colo file:,branch=abranch')
6874.1.3 by Jelmer Vernooij
Fix format names.
68
        self.assertEqual("""Created a standalone tree (format: development-colo)\n""",
6083.2.4 by Jelmer Vernooij
Add test for creating a colocated branch.
69
            out)
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
70
        self.assertEqual('', err)
6083.2.4 by Jelmer Vernooij
Add test for creating a colocated branch.
71
        out, err = self.run_bzr('branches')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
72
        self.assertEqual("  abranch\n", out)
73
        self.assertEqual('', err)
6083.2.4 by Jelmer Vernooij
Add test for creating a colocated branch.
74
1654.1.4 by Robert Collins
Teach `bzr init` how to init at the root of a repository.
75
    def test_init_at_repository_root(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
76
        # brz init at the root of a repository should create a branch
1654.1.4 by Robert Collins
Teach `bzr init` how to init at the root of a repository.
77
        # and working tree even when creation of working trees is disabled.
78
        t = self.get_transport()
79
        t.mkdir('repo')
80
        format = BzrDirMetaFormat1()
81
        newdir = format.initialize(t.abspath('repo'))
82
        repo = newdir.create_repository(shared=True)
83
        repo.set_make_working_trees(False)
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
84
        out, err = self.run_bzr('init repo')
4599.1.1 by Robert Collins
Make blackbox init tests able to be trivially changed to 2a.
85
        self.assertEqual("""Created a repository tree (format: %s)
3922.2.1 by Marius Kruger
make `bzr init` less verbose, and update tests
86
Using shared repository: %s
4599.1.1 by Robert Collins
Make blackbox init tests able to be trivially changed to 2a.
87
""" % (self._default_label, urlutils.local_path_from_url(
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
88
            repo.controldir.root_transport.external_url())), out)
4789.8.1 by John Arbash Meinel
Don't make explicit assumptions about testing current working dir.
89
        cwd = osutils.getcwd()
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
90
        self.assertEndsWith(out, cwd + '/repo/\n')
91
        self.assertEqual('', err)
1654.1.4 by Robert Collins
Teach `bzr init` how to init at the root of a repository.
92
        newdir.open_branch()
93
        newdir.open_workingtree()
3922.2.1 by Marius Kruger
make `bzr init` less verbose, and update tests
94
1654.1.4 by Robert Collins
Teach `bzr init` how to init at the root of a repository.
95
    def test_init_branch(self):
96
        out, err = self.run_bzr('init')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
97
        self.assertEqual("Created a standalone tree (format: %s)\n" % (
4599.1.1 by Robert Collins
Make blackbox init tests able to be trivially changed to 2a.
98
            self._default_label,), out)
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
99
        self.assertEqual('', err)
1654.1.4 by Robert Collins
Teach `bzr init` how to init at the root of a repository.
100
101
        # Can it handle subdirectories of branches too ?
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
102
        out, err = self.run_bzr('init subdir1')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
103
        self.assertEqual("Created a standalone tree (format: %s)\n" % (
4599.1.1 by Robert Collins
Make blackbox init tests able to be trivially changed to 2a.
104
            self._default_label,), out)
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
105
        self.assertEqual('', err)
1654.1.4 by Robert Collins
Teach `bzr init` how to init at the root of a repository.
106
        WorkingTree.open('subdir1')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
107
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
108
        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.
109
                            'init subdir2/nothere')
110
        out, err = self.run_bzr('init subdir2/nothere', retcode=3)
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
111
        self.assertEqual('', out)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
112
1654.1.4 by Robert Collins
Teach `bzr init` how to init at the root of a repository.
113
        os.mkdir('subdir2')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
114
        out, err = self.run_bzr('init subdir2')
4599.1.1 by Robert Collins
Make blackbox init tests able to be trivially changed to 2a.
115
        self.assertEqual("Created a standalone tree (format: %s)\n" % (
116
            self._default_label,), out)
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
117
        self.assertEqual('', err)
1654.1.4 by Robert Collins
Teach `bzr init` how to init at the root of a repository.
118
        # init an existing branch.
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
119
        out, err = self.run_bzr('init subdir2', retcode=3)
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
120
        self.assertEqual('', out)
7027.10.1 by Jelmer Vernooij
Various blackbox test fixes.
121
        self.assertTrue(err.startswith('brz: ERROR: Already a branch:'))
1662.1.19 by Martin Pool
Better error message when initting existing tree
122
3535.9.6 by Marius Kruger
add explicit blackbox tests for 'init -q' and 'init-repo -q'
123
    def test_init_branch_quiet(self):
124
        out, err = self.run_bzr('init -q')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
125
        self.assertEqual('', out)
126
        self.assertEqual('', err)
3535.9.6 by Marius Kruger
add explicit blackbox tests for 'init -q' and 'init-repo -q'
127
1662.1.19 by Martin Pool
Better error message when initting existing tree
128
    def test_init_existing_branch(self):
129
        self.run_bzr('init')
130
        out, err = self.run_bzr('init', retcode=3)
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
131
        self.assertContainsRe(err, 'Already a branch')
1662.1.19 by Martin Pool
Better error message when initting existing tree
132
        # don't suggest making a checkout, there's already a working tree
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
133
        self.assertFalse(re.search(r'checkout', err))
1662.1.19 by Martin Pool
Better error message when initting existing tree
134
135
    def test_init_existing_without_workingtree(self):
136
        # make a repository
2257.2.1 by Wouter van Heyst
Change the ui level default for init-repo to --trees.
137
        repo = self.make_repository('.', shared=True)
138
        repo.set_make_working_trees(False)
1662.1.19 by Martin Pool
Better error message when initting existing tree
139
        # make a branch; by default without a working tree
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
140
        self.run_bzr('init subdir')
1662.1.19 by Martin Pool
Better error message when initting existing tree
141
        # fail
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
142
        out, err = self.run_bzr('init subdir', retcode=3)
1662.1.19 by Martin Pool
Better error message when initting existing tree
143
        # suggests using checkout
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
144
        self.assertContainsRe(err,
7027.10.1 by Jelmer Vernooij
Various blackbox test fixes.
145
                              'ontains a branch.*but no working tree.*checkout')
1662.1.19 by Martin Pool
Better error message when initting existing tree
146
1765.1.1 by Robert Collins
Remove the default ignores list from bzr, lowering the minimum overhead in bzr add.
147
    def test_no_defaults(self):
148
        """Init creates no default ignore rules."""
149
        self.run_bzr('init')
150
        self.assertFalse(os.path.exists('.bzrignore'))
1830.4.1 by Wouter van Heyst
Allow bzr init to create remote branches
151
2294.2.1 by Alexander Belchenko
Bugfix #85599: ``bzr init`` works with unicode argument LOCATION
152
    def test_init_unicode(self):
153
        # Make sure getcwd can handle unicode filenames
154
        try:
155
            os.mkdir(u'mu-\xb5')
156
        except UnicodeError:
157
            raise TestSkipped("Unable to create Unicode filename")
158
        # try to init unicode dir
3697.5.4 by John Arbash Meinel
Merge vila's init[-repo] changes and add a NEWS entry.
159
        self.run_bzr(['init', '-q', u'mu-\xb5'])
2294.2.1 by Alexander Belchenko
Bugfix #85599: ``bzr init`` works with unicode argument LOCATION
160
2524.1.1 by Aaron Bentley
Revert broken changes
161
    def create_simple_tree(self):
162
        tree = self.make_branch_and_tree('tree')
163
        self.build_tree(['tree/a'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
164
        tree.add(['a'], [b'a-id'])
165
        tree.commit('one', rev_id=b'r1')
2524.1.1 by Aaron Bentley
Revert broken changes
166
        return tree
167
168
    def test_init_create_prefix(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
169
        """'brz init --create-prefix; will create leading directories."""
2524.1.1 by Aaron Bentley
Revert broken changes
170
        tree = self.create_simple_tree()
171
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
172
        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.
173
                            'init ../new/tree', working_dir='tree')
174
        self.run_bzr('init ../new/tree --create-prefix', working_dir='tree')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
175
        self.assertPathExists('new/tree/.bzr')
2524.1.1 by Aaron Bentley
Revert broken changes
176
5448.4.2 by Neil Martinsen-Burrell
blackbox test
177
    def test_init_default_format_option(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
178
        """brz init should read default format from option default_format"""
6499.3.8 by Vincent Ladeuil
Update some forgotten uses of GlobalConfig to GlobalStack.
179
        g_store = _mod_config.GlobalStore()
6973.10.4 by Jelmer Vernooij
Update python3.passing.
180
        g_store._load_from_string(b'''
5448.4.2 by Neil Martinsen-Burrell
blackbox test
181
[DEFAULT]
182
default_format = 1.9
6499.3.8 by Vincent Ladeuil
Update some forgotten uses of GlobalConfig to GlobalStack.
183
''')
184
        g_store.save()
5448.4.3 by Neil Martinsen-Burrell
use option along with controldir.set_default to control the default format
185
        out, err = self.run_bzr_subprocess('init')
7045.2.4 by Jelmer Vernooij
Fix some more.
186
        self.assertContainsRe(out, b'1.9')
5448.4.2 by Neil Martinsen-Burrell
blackbox test
187
5448.6.6 by Matthew Gordon
Added test for 'bzr init --no-tree'
188
    def test_init_no_tree(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
189
        """'brz init --no-tree' creates a branch with no working tree."""
5448.6.6 by Matthew Gordon
Added test for 'bzr init --no-tree'
190
        out, err = self.run_bzr('init --no-tree')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
191
        self.assertStartsWith(out, 'Created a standalone branch')
5448.6.6 by Matthew Gordon
Added test for 'bzr init --no-tree'
192
1830.4.7 by Wouter van Heyst
review fixes, rename transport variable to to_transport
193
1830.4.1 by Wouter van Heyst
Allow bzr init to create remote branches
194
class TestSFTPInit(TestCaseWithSFTPServer):
195
196
    def test_init(self):
1830.4.3 by Wouter van Heyst
more review comments
197
        # init on a remote url should succeed.
6708.1.3 by Neil Martinsen-Burrell
Fix tests that used format names
198
        out, err = self.run_bzr(['init', '--format=pack-0.92', self.get_url()])
3922.2.1 by Marius Kruger
make `bzr init` less verbose, and update tests
199
        self.assertEqual(out,
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
200
            """Created a standalone branch (format: pack-0.92)\n""")
201
        self.assertEqual('', err)
3922.2.1 by Marius Kruger
make `bzr init` less verbose, and update tests
202
1830.4.3 by Wouter van Heyst
more review comments
203
    def test_init_existing_branch(self):
204
        # when there is already a branch present, make mention
1830.4.4 by Wouter van Heyst
more review comments
205
        self.make_branch('.')
206
207
        # rely on SFTPServer get_url() pointing at '.'
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
208
        out, err = self.run_bzr_error(['Already a branch'],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
209
                                      ['init', self.get_url()])
1830.4.5 by Wouter van Heyst
cleanup
210
6622.1.29 by Jelmer Vernooij
Fix some more tests.
211
        # make sure using 'brz checkout' is not suggested
1830.4.5 by Wouter van Heyst
cleanup
212
        # for remote locations missing a working tree
6622.1.29 by Jelmer Vernooij
Fix some more tests.
213
        self.assertFalse(re.search(r'use brz checkout', err))
1830.4.1 by Wouter van Heyst
Allow bzr init to create remote branches
214
1830.4.4 by Wouter van Heyst
more review comments
215
    def test_init_existing_branch_with_workingtree(self):
1830.4.3 by Wouter van Heyst
more review comments
216
        # don't distinguish between the branch having a working tree or not
217
        # when the branch itself is remote.
218
        self.make_branch_and_tree('.')
219
220
        # rely on SFTPServer get_url() pointing at '.'
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
221
        self.run_bzr_error(['Already a branch'], ['init', self.get_url()])
2230.3.42 by Aaron Bentley
add --append-revisions-only option to init
222
223
    def test_init_append_revisions_only(self):
6708.1.3 by Neil Martinsen-Burrell
Fix tests that used format names
224
        self.run_bzr('init --format=dirstate-tags normal_branch6')
2230.3.42 by Aaron Bentley
add --append-revisions-only option to init
225
        branch = _mod_branch.Branch.open('normal_branch6')
6123.9.11 by Jelmer Vernooij
Make get_append_revisions_only public.
226
        self.assertEqual(None, branch.get_append_revisions_only())
6708.1.3 by Neil Martinsen-Burrell
Fix tests that used format names
227
        self.run_bzr('init --append-revisions-only --format=dirstate-tags branch6')
2230.3.42 by Aaron Bentley
add --append-revisions-only option to init
228
        branch = _mod_branch.Branch.open('branch6')
6123.9.11 by Jelmer Vernooij
Make get_append_revisions_only public.
229
        self.assertEqual(True, branch.get_append_revisions_only())
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
230
        self.run_bzr_error(['cannot be set to append-revisions-only'],
6708.1.3 by Neil Martinsen-Burrell
Fix tests that used format names
231
                           'init --append-revisions-only --format=knit knit')
5187.2.4 by Parth Malwankar
added tests.
232
233
    def test_init_without_username(self):
5187.2.6 by Parth Malwankar
lockdir no long mandates whoami but uses unicode version of getuser
234
        """Ensure init works if username is not set.
5187.2.4 by Parth Malwankar
added tests.
235
        """
6622.1.29 by Jelmer Vernooij
Fix some more tests.
236
        # brz makes user specified whoami mandatory for operations
5187.2.9 by Parth Malwankar
added comment to init/init-repo pass tests for lacking whoami.
237
        # like commit as whoami is recorded. init however is not so final
238
        # and uses whoami only in a lock file. Without whoami the login name
239
        # is used. This test is to ensure that init passes even when whoami
240
        # is not available.
5570.3.12 by Vincent Ladeuil
Replace osutils.set_or_unset_env calls with self.overrideEnv.
241
        self.overrideEnv('EMAIL', None)
6622.1.28 by Jelmer Vernooij
More renames; commands in output, environment variables.
242
        self.overrideEnv('BRZ_EMAIL', None)
5187.2.6 by Parth Malwankar
lockdir no long mandates whoami but uses unicode version of getuser
243
        out, err = self.run_bzr(['init', 'foo'])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
244
        self.assertEqual(err, '')
5187.2.6 by Parth Malwankar
lockdir no long mandates whoami but uses unicode version of getuser
245
        self.assertTrue(os.path.exists('foo'))
5570.3.12 by Vincent Ladeuil
Replace osutils.set_or_unset_env calls with self.overrideEnv.
246