1
# Copyright (C) 2006-2010 Canonical Ltd
1
# Copyright (C) 2006, 2007 Canonical Ltd
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
23
23
from bzrlib import (
24
24
branch as _mod_branch,
28
27
from bzrlib.bzrdir import BzrDirMetaFormat1
29
28
from bzrlib.tests import TestSkipped
30
from bzrlib.tests import TestCaseWithTransport
29
from bzrlib.tests.blackbox import ExternalBase
31
30
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
32
31
from bzrlib.workingtree import WorkingTree
35
class TestInit(TestCaseWithTransport):
38
TestCaseWithTransport.setUp(self)
39
self._default_label = '2a'
34
class TestInit(ExternalBase):
41
36
def test_init_with_format(self):
42
37
# Verify bzr init --format constructs something plausible
55
50
self.assertEqual('', err)
57
def test_init_format_2a(self):
58
"""Smoke test for constructing a format 2a repoistory."""
59
out, err = self.run_bzr('init --format=2a')
60
self.assertEqual("""Created a standalone tree (format: 2a)\n""",
62
self.assertEqual('', err)
64
52
def test_init_at_repository_root(self):
65
53
# bzr init at the root of a repository should create a branch
66
54
# and working tree even when creation of working trees is disabled.
71
59
repo = newdir.create_repository(shared=True)
72
60
repo.set_make_working_trees(False)
73
61
out, err = self.run_bzr('init repo')
74
self.assertEqual("""Created a repository tree (format: %s)
62
self.assertEqual("""Created a repository tree (format: pack-0.92)
75
63
Using shared repository: %s
76
""" % (self._default_label, urlutils.local_path_from_url(
77
repo.bzrdir.root_transport.external_url())), out)
78
cwd = osutils.getcwd()
79
self.assertEndsWith(out, cwd + '/repo/\n')
64
""" % urlutils.local_path_from_url(
65
repo.bzrdir.root_transport.external_url()), out)
66
self.assertEndsWith(out, "bzrlib.tests.blackbox.test_init.TestInit."
67
"test_init_at_repository_root/work/repo/\n")
80
68
self.assertEqual('', err)
81
69
newdir.open_branch()
82
70
newdir.open_workingtree()
84
72
def test_init_branch(self):
85
73
out, err = self.run_bzr('init')
86
self.assertEqual("Created a standalone tree (format: %s)\n" % (
87
self._default_label,), out)
74
self.assertEqual("""Created a standalone tree (format: pack-0.92)\n""",
88
76
self.assertEqual('', err)
90
78
# Can it handle subdirectories of branches too ?
91
79
out, err = self.run_bzr('init subdir1')
92
self.assertEqual("Created a standalone tree (format: %s)\n" % (
93
self._default_label,), out)
80
self.assertEqual("""Created a standalone tree (format: pack-0.92)\n""",
94
82
self.assertEqual('', err)
95
83
WorkingTree.open('subdir1')
102
90
os.mkdir('subdir2')
103
91
out, err = self.run_bzr('init subdir2')
104
self.assertEqual("Created a standalone tree (format: %s)\n" % (
105
self._default_label,), out)
92
self.assertEqual("""Created a standalone tree (format: pack-0.92)\n""",
106
94
self.assertEqual('', err)
107
95
# init an existing branch.
108
96
out, err = self.run_bzr('init subdir2', retcode=3)
169
157
def test_init(self):
170
158
# init on a remote url should succeed.
171
out, err = self.run_bzr(['init', '--pack-0.92', self.get_url()])
159
out, err = self.run_bzr(['init', self.get_url()])
172
160
self.assertEqual(out,
173
161
"""Created a standalone branch (format: pack-0.92)\n""")
174
162
self.assertEqual('', err)
196
184
def test_init_append_revisions_only(self):
197
185
self.run_bzr('init --dirstate-tags normal_branch6')
198
186
branch = _mod_branch.Branch.open('normal_branch6')
199
self.assertEqual(None, branch._get_append_revisions_only())
187
self.assertEqual(False, branch._get_append_revisions_only())
200
188
self.run_bzr('init --append-revisions-only --dirstate-tags branch6')
201
189
branch = _mod_branch.Branch.open('branch6')
202
190
self.assertEqual(True, branch._get_append_revisions_only())
203
191
self.run_bzr_error(['cannot be set to append-revisions-only'],
204
192
'init --append-revisions-only --knit knit')
206
def test_init_without_username(self):
207
"""Ensure init works if username is not set.
209
# bzr makes user specified whoami mandatory for operations
210
# like commit as whoami is recorded. init however is not so final
211
# and uses whoami only in a lock file. Without whoami the login name
212
# is used. This test is to ensure that init passes even when whoami
214
osutils.set_or_unset_env('EMAIL', None)
215
osutils.set_or_unset_env('BZR_EMAIL', None)
216
out, err = self.run_bzr(['init', 'foo'])
217
self.assertEqual(err, '')
218
self.assertTrue(os.path.exists('foo'))