~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_init.py

  • Committer: Wouter van Heyst
  • Date: 2006-06-07 16:05:27 UTC
  • mto: This revision was merged to the branch mainline in revision 1752.
  • Revision ID: larstiq@larstiq.dyndns.org-20060607160527-2b3649154d0e2e84
more code cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007 Canonical Ltd
2
 
#
 
1
# Copyright (C) 2006 by Canonical Ltd
 
2
 
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.
7
 
#
 
7
 
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.
12
 
#
 
12
 
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
20
20
import os
21
21
import re
22
22
 
23
 
from bzrlib import (
24
 
    branch as _mod_branch,
25
 
    )
26
23
from bzrlib.bzrdir import BzrDirMetaFormat1
27
 
from bzrlib.tests import TestSkipped
28
24
from bzrlib.tests.blackbox import ExternalBase
29
 
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
30
25
from bzrlib.workingtree import WorkingTree
31
26
 
32
27
 
35
30
    def test_init_with_format(self):
36
31
        # Verify bzr init --format constructs something plausible
37
32
        t = self.get_transport()
38
 
        self.run_bzr('init --format default')
 
33
        self.runbzr('init --format default')
39
34
        self.assertIsDirectory('.bzr', t)
40
35
        self.assertIsDirectory('.bzr/checkout', t)
41
36
        self.assertIsDirectory('.bzr/checkout/lock', t)
73
68
        self.assertEqual('', err)
74
69
        WorkingTree.open('subdir1')
75
70
        
76
 
        self.run_bzr_error(['Parent directory of subdir2/nothere does not exist'],
77
 
                            'init', 'subdir2/nothere')
78
71
        out, err = self.run_bzr('init', 'subdir2/nothere', retcode=3)
79
72
        self.assertEqual('', out)
 
73
        self.failUnless(err.startswith(
 
74
            'bzr: ERROR: exceptions.OSError: '
 
75
            '[Errno 2] No such file or directory: '))
80
76
        
81
77
        os.mkdir('subdir2')
82
78
        out, err = self.run_bzr('init', 'subdir2')
96
92
 
97
93
    def test_init_existing_without_workingtree(self):
98
94
        # make a repository
99
 
        repo = self.make_repository('.', shared=True)
100
 
        repo.set_make_working_trees(False)
 
95
        self.run_bzr('init-repo', '.')
101
96
        # make a branch; by default without a working tree
102
97
        self.run_bzr('init', 'subdir')
103
98
        # fail
105
100
        # suggests using checkout
106
101
        self.assertContainsRe(err, 'ontains a branch.*but no working tree.*checkout')
107
102
 
108
 
    def test_no_defaults(self):
109
 
        """Init creates no default ignore rules."""
110
 
        self.run_bzr('init')
111
 
        self.assertFalse(os.path.exists('.bzrignore'))
112
 
 
113
 
    def test_init_unicode(self):
114
 
        # Make sure getcwd can handle unicode filenames
115
 
        try:
116
 
            os.mkdir(u'mu-\xb5')
117
 
        except UnicodeError:
118
 
            raise TestSkipped("Unable to create Unicode filename")
119
 
        # try to init unicode dir
120
 
        self.run_bzr('init', u'mu-\xb5')
121
 
 
122
 
    def create_simple_tree(self):
123
 
        tree = self.make_branch_and_tree('tree')
124
 
        self.build_tree(['tree/a'])
125
 
        tree.add(['a'], ['a-id'])
126
 
        tree.commit('one', rev_id='r1')
127
 
        return tree
128
 
 
129
 
    def test_init_create_prefix(self):
130
 
        """'bzr init --create-prefix; will create leading directories."""
131
 
        tree = self.create_simple_tree()
132
 
 
133
 
        self.run_bzr_error(['Parent directory of ../new/tree does not exist'],
134
 
                            'init', '../new/tree',
135
 
                            working_dir='tree')
136
 
        self.run_bzr('init', '../new/tree', '--create-prefix',
137
 
                        working_dir='tree')
138
 
        self.failUnlessExists('new/tree/.bzr')
139
 
 
140
 
 
141
 
class TestSFTPInit(TestCaseWithSFTPServer):
142
 
 
143
 
    def test_init(self):
144
 
        # init on a remote url should succeed.
145
 
        out, err = self.run_bzr('init', self.get_url())
146
 
        self.assertEqual('', out)
147
 
        self.assertEqual('', err)
148
 
    
149
 
    def test_init_existing_branch(self):
150
 
        # when there is already a branch present, make mention
151
 
        self.make_branch('.')
152
 
 
153
 
        # rely on SFTPServer get_url() pointing at '.'
154
 
        out, err = self.run_bzr_error(['Already a branch'], 'init', self.get_url())
155
 
 
156
 
        # make sure using 'bzr checkout' is not suggested
157
 
        # for remote locations missing a working tree
158
 
        self.assertFalse(re.search(r'use bzr checkout', err))
159
 
 
160
 
    def test_init_existing_branch_with_workingtree(self):
161
 
        # don't distinguish between the branch having a working tree or not
162
 
        # when the branch itself is remote.
163
 
        self.make_branch_and_tree('.')
164
 
 
165
 
        # rely on SFTPServer get_url() pointing at '.'
166
 
        self.run_bzr_error(['Already a branch'], 'init', self.get_url())
167
 
 
168
 
    def test_init_append_revisions_only(self):
169
 
        self.run_bzr('init', '--dirstate-tags', 'normal_branch6')
170
 
        branch = _mod_branch.Branch.open('normal_branch6')
171
 
        self.assertEqual(False, branch._get_append_revisions_only())
172
 
        self.run_bzr('init', '--append-revisions-only',
173
 
                     '--dirstate-tags', 'branch6')
174
 
        branch = _mod_branch.Branch.open('branch6')
175
 
        self.assertEqual(True, branch._get_append_revisions_only())
176
 
        self.run_bzr_error(['cannot be set to append-revisions-only'], 'init',
177
 
            '--append-revisions-only', '--knit', 'knit')