15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24
24
branch as _mod_branch,
25
25
config as _mod_config,
29
from bzrlib.bzrdir import BzrDirMetaFormat1
30
from bzrlib.tests import TestSkipped
31
from bzrlib.tests import TestCaseWithTransport
32
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
33
from bzrlib.workingtree import WorkingTree
29
from breezy.bzr.bzrdir import BzrDirMetaFormat1
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
36
36
class TestInit(TestCaseWithTransport):
40
40
self._default_label = '2a'
42
42
def test_init_with_format(self):
43
# Verify bzr init --format constructs something plausible
43
# Verify brz init --format constructs something plausible
44
44
t = self.get_transport()
45
45
self.run_bzr('init --format default')
46
46
self.assertIsDirectory('.bzr', t)
51
51
"""Smoke test for constructing a format 2a repository."""
52
52
out, err = self.run_bzr('init --format=2a')
53
53
self.assertEqual("""Created a standalone tree (format: 2a)\n""",
55
self.assertEqual('', err)
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')
61
"Created a standalone tree (format: %s)\n" % self._default_label,
55
63
self.assertEqual('', err)
57
65
def test_init_colocated(self):
58
66
"""Smoke test for constructing a colocated branch."""
59
out, err = self.run_bzr('init --format=development-colo file:,branch=abranch')
60
self.assertEqual("""Created a lightweight checkout (format: development-colo)\n""",
67
out, err = self.run_bzr(
68
'init --format=development-colo file:,branch=abranch')
69
self.assertEqual("""Created a standalone tree (format: development-colo)\n""",
62
71
self.assertEqual('', err)
63
72
out, err = self.run_bzr('branches')
64
73
self.assertEqual(" abranch\n", out)
65
74
self.assertEqual('', err)
67
76
def test_init_at_repository_root(self):
68
# bzr init at the root of a repository should create a branch
77
# brz init at the root of a repository should create a branch
69
78
# and working tree even when creation of working trees is disabled.
70
79
t = self.get_transport()
77
86
self.assertEqual("""Created a repository tree (format: %s)
78
87
Using shared repository: %s
79
88
""" % (self._default_label, urlutils.local_path_from_url(
80
repo.bzrdir.root_transport.external_url())), out)
89
repo.controldir.root_transport.external_url())), out)
81
90
cwd = osutils.getcwd()
82
91
self.assertEndsWith(out, cwd + '/repo/\n')
83
92
self.assertEqual('', err)
98
107
WorkingTree.open('subdir1')
100
109
self.run_bzr_error(['Parent directory of subdir2/nothere does not exist'],
101
'init subdir2/nothere')
110
'init subdir2/nothere')
102
111
out, err = self.run_bzr('init subdir2/nothere', retcode=3)
103
112
self.assertEqual('', out)
110
119
# init an existing branch.
111
120
out, err = self.run_bzr('init subdir2', retcode=3)
112
121
self.assertEqual('', out)
113
self.assertTrue(err.startswith('bzr: ERROR: Already a branch:'))
122
self.assertTrue(err.startswith('brz: ERROR: Already a branch:'))
115
124
def test_init_branch_quiet(self):
116
125
out, err = self.run_bzr('init -q')
153
162
def create_simple_tree(self):
154
163
tree = self.make_branch_and_tree('tree')
155
164
self.build_tree(['tree/a'])
156
tree.add(['a'], ['a-id'])
157
tree.commit('one', rev_id='r1')
165
tree.add(['a'], [b'a-id'])
166
tree.commit('one', rev_id=b'r1')
160
169
def test_init_create_prefix(self):
161
"""'bzr init --create-prefix; will create leading directories."""
170
"""'brz init --create-prefix; will create leading directories."""
162
171
tree = self.create_simple_tree()
164
173
self.run_bzr_error(['Parent directory of ../new/tree does not exist'],
165
'init ../new/tree', working_dir='tree')
174
'init ../new/tree', working_dir='tree')
166
175
self.run_bzr('init ../new/tree --create-prefix', working_dir='tree')
167
176
self.assertPathExists('new/tree/.bzr')
169
178
def test_init_default_format_option(self):
170
"""bzr init should read default format from option default_format"""
179
"""brz init should read default format from option default_format"""
171
180
g_store = _mod_config.GlobalStore()
172
g_store._load_from_string('''
181
g_store._load_from_string(b'''
174
183
default_format = 1.9
177
186
out, err = self.run_bzr_subprocess('init')
178
self.assertContainsRe(out, '1.9')
187
self.assertContainsRe(out, b'1.9')
180
189
def test_init_no_tree(self):
181
"""'bzr init --no-tree' creates a branch with no working tree."""
190
"""'brz init --no-tree' creates a branch with no working tree."""
182
191
out, err = self.run_bzr('init --no-tree')
183
192
self.assertStartsWith(out, 'Created a standalone branch')
188
197
def test_init(self):
189
198
# init on a remote url should succeed.
190
out, err = self.run_bzr(['init', '--pack-0.92', self.get_url()])
199
out, err = self.run_bzr(['init', '--format=pack-0.92', self.get_url()])
191
200
self.assertEqual(out,
192
"""Created a standalone branch (format: pack-0.92)\n""")
201
"""Created a standalone branch (format: pack-0.92)\n""")
193
202
self.assertEqual('', err)
195
204
def test_init_existing_branch(self):
200
209
out, err = self.run_bzr_error(['Already a branch'],
201
210
['init', self.get_url()])
203
# make sure using 'bzr checkout' is not suggested
212
# make sure using 'brz checkout' is not suggested
204
213
# for remote locations missing a working tree
205
self.assertFalse(re.search(r'use bzr checkout', err))
214
self.assertFalse(re.search(r'use brz checkout', err))
207
216
def test_init_existing_branch_with_workingtree(self):
208
217
# don't distinguish between the branch having a working tree or not
213
222
self.run_bzr_error(['Already a branch'], ['init', self.get_url()])
215
224
def test_init_append_revisions_only(self):
216
self.run_bzr('init --dirstate-tags normal_branch6')
225
self.run_bzr('init --format=dirstate-tags normal_branch6')
217
226
branch = _mod_branch.Branch.open('normal_branch6')
218
227
self.assertEqual(None, branch.get_append_revisions_only())
219
self.run_bzr('init --append-revisions-only --dirstate-tags branch6')
229
'init --append-revisions-only --format=dirstate-tags branch6')
220
230
branch = _mod_branch.Branch.open('branch6')
221
231
self.assertEqual(True, branch.get_append_revisions_only())
222
232
self.run_bzr_error(['cannot be set to append-revisions-only'],
223
'init --append-revisions-only --knit knit')
233
'init --append-revisions-only --format=knit knit')
225
235
def test_init_without_username(self):
226
236
"""Ensure init works if username is not set.
228
# bzr makes user specified whoami mandatory for operations
238
# brz makes user specified whoami mandatory for operations
229
239
# like commit as whoami is recorded. init however is not so final
230
240
# and uses whoami only in a lock file. Without whoami the login name
231
241
# is used. This test is to ensure that init passes even when whoami
232
242
# is not available.
233
243
self.overrideEnv('EMAIL', None)
234
self.overrideEnv('BZR_EMAIL', None)
244
self.overrideEnv('BRZ_EMAIL', None)
235
245
out, err = self.run_bzr(['init', 'foo'])
236
246
self.assertEqual(err, '')
237
247
self.assertTrue(os.path.exists('foo'))