1
# Copyright (C) 2006, 2007 Canonical Ltd
1
# Copyright (C) 2006 by 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
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
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.
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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
59
51
newdir = format.initialize(t.abspath('repo'))
60
52
repo = newdir.create_repository(shared=True)
61
53
repo.set_make_working_trees(False)
62
out, err = self.run_bzr('init repo')
64
"""Repository tree (format: pack-0.92)
66
shared repository: repo
67
repository branch: repo
54
out, err = self.run_bzr('init', 'repo')
55
self.assertEqual('', out)
69
56
self.assertEqual('', err)
70
57
newdir.open_branch()
71
58
newdir.open_workingtree()
73
60
def test_init_branch(self):
74
61
out, err = self.run_bzr('init')
76
"""Standalone tree (format: pack-0.92)
62
self.assertEqual('', out)
80
63
self.assertEqual('', err)
82
65
# Can it handle subdirectories of branches too ?
83
out, err = self.run_bzr('init subdir1')
85
"""Standalone tree (format: pack-0.92)
66
out, err = self.run_bzr('init', 'subdir1')
67
self.assertEqual('', out)
89
68
self.assertEqual('', err)
90
69
WorkingTree.open('subdir1')
92
self.run_bzr_error(['Parent directory of subdir2/nothere does not exist'],
93
'init subdir2/nothere')
94
out, err = self.run_bzr('init subdir2/nothere', retcode=3)
71
out, err = self.run_bzr('init', 'subdir2/nothere', retcode=3)
95
72
self.assertEqual('', out)
73
self.failUnless(err.startswith(
74
'bzr: ERROR: exceptions.OSError: '
75
'[Errno 2] No such file or directory: '))
97
77
os.mkdir('subdir2')
98
out, err = self.run_bzr('init subdir2')
99
self.assertEqual("""Standalone tree (format: pack-0.92)
78
out, err = self.run_bzr('init', 'subdir2')
79
self.assertEqual('', out)
103
80
self.assertEqual('', err)
104
81
# init an existing branch.
105
out, err = self.run_bzr('init subdir2', retcode=3)
82
out, err = self.run_bzr('init', 'subdir2', retcode=3)
106
83
self.assertEqual('', out)
107
84
self.failUnless(err.startswith('bzr: ERROR: Already a branch:'))
109
def test_init_branch_quiet(self):
110
out, err = self.run_bzr('init -q')
111
self.assertEqual('', out)
112
self.assertEqual('', err)
114
86
def test_init_existing_branch(self):
115
87
self.run_bzr('init')
116
88
out, err = self.run_bzr('init', retcode=3)
121
93
def test_init_existing_without_workingtree(self):
122
94
# make a repository
123
repo = self.make_repository('.', shared=True)
124
repo.set_make_working_trees(False)
95
self.run_bzr('init-repo', '.')
125
96
# make a branch; by default without a working tree
126
self.run_bzr('init subdir')
97
self.run_bzr('init', 'subdir')
128
out, err = self.run_bzr('init subdir', retcode=3)
99
out, err = self.run_bzr('init', 'subdir', retcode=3)
129
100
# suggests using checkout
130
self.assertContainsRe(err,
131
'ontains a branch.*but no working tree.*checkout')
133
def test_no_defaults(self):
134
"""Init creates no default ignore rules."""
136
self.assertFalse(os.path.exists('.bzrignore'))
138
def test_init_unicode(self):
139
# Make sure getcwd can handle unicode filenames
143
raise TestSkipped("Unable to create Unicode filename")
144
# try to init unicode dir
145
self.run_bzr(['init', '-q', u'mu-\xb5'])
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')
154
def test_init_create_prefix(self):
155
"""'bzr init --create-prefix; will create leading directories."""
156
tree = self.create_simple_tree()
158
self.run_bzr_error(['Parent directory of ../new/tree does not exist'],
159
'init ../new/tree', working_dir='tree')
160
self.run_bzr('init ../new/tree --create-prefix', working_dir='tree')
161
self.failUnlessExists('new/tree/.bzr')
164
class TestSFTPInit(TestCaseWithSFTPServer):
167
# init on a remote url should succeed.
168
out, err = self.run_bzr(['init', self.get_url()])
169
self.assertStartsWith(out, """Standalone branch (format: pack-0.92)
172
self.assertEqual('', err)
174
def test_init_existing_branch(self):
175
# when there is already a branch present, make mention
176
self.make_branch('.')
178
# rely on SFTPServer get_url() pointing at '.'
179
out, err = self.run_bzr_error(['Already a branch'],
180
['init', self.get_url()])
182
# make sure using 'bzr checkout' is not suggested
183
# for remote locations missing a working tree
184
self.assertFalse(re.search(r'use bzr checkout', err))
186
def test_init_existing_branch_with_workingtree(self):
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('.')
191
# rely on SFTPServer get_url() pointing at '.'
192
self.run_bzr_error(['Already a branch'], ['init', self.get_url()])
194
def test_init_append_revisions_only(self):
195
self.run_bzr('init --dirstate-tags normal_branch6')
196
branch = _mod_branch.Branch.open('normal_branch6')
197
self.assertEqual(False, branch._get_append_revisions_only())
198
self.run_bzr('init --append-revisions-only --dirstate-tags branch6')
199
branch = _mod_branch.Branch.open('branch6')
200
self.assertEqual(True, branch._get_append_revisions_only())
201
self.run_bzr_error(['cannot be set to append-revisions-only'],
202
'init --append-revisions-only --knit knit')
101
self.assertContainsRe(err, 'ontains a branch.*but no working tree.*checkout')