~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-05-29 15:57:16 UTC
  • mfrom: (3427.5.9 dep_warnings)
  • Revision ID: pqm@pqm.ubuntu.com-20080529155716-0w3kic8lioa63231
(jam) Enable Deprecation Warnings when running -Werror and when
        running selftest

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 by Canonical Ltd
2
 
 
 
1
# Copyright (C) 2006, 2007 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
18
18
"""Test "bzr init"""
19
19
 
20
20
import os
 
21
import re
21
22
 
 
23
from bzrlib import (
 
24
    branch as _mod_branch,
 
25
    )
22
26
from bzrlib.bzrdir import BzrDirMetaFormat1
 
27
from bzrlib.tests import TestSkipped
23
28
from bzrlib.tests.blackbox import ExternalBase
 
29
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
24
30
from bzrlib.workingtree import WorkingTree
25
31
 
26
32
 
29
35
    def test_init_with_format(self):
30
36
        # Verify bzr init --format constructs something plausible
31
37
        t = self.get_transport()
32
 
        self.runbzr('init --format metadir')
 
38
        self.run_bzr('init --format default')
33
39
        self.assertIsDirectory('.bzr', t)
34
40
        self.assertIsDirectory('.bzr/checkout', t)
35
41
        self.assertIsDirectory('.bzr/checkout/lock', t)
37
43
    def test_init_weave(self):
38
44
        # --format=weave should be accepted to allow interoperation with
39
45
        # old releases when desired.
40
 
        out, err = self.run_bzr('init', '--format=weave')
 
46
        out, err = self.run_bzr('init --format=weave')
41
47
        self.assertEqual('', out)
42
48
        self.assertEqual('', err)
43
49
 
50
56
        newdir = format.initialize(t.abspath('repo'))
51
57
        repo = newdir.create_repository(shared=True)
52
58
        repo.set_make_working_trees(False)
53
 
        out, err = self.run_bzr('init', 'repo')
 
59
        out, err = self.run_bzr('init repo')
54
60
        self.assertEqual('', out)
55
61
        self.assertEqual('', err)
56
62
        newdir.open_branch()
62
68
        self.assertEqual('', err)
63
69
 
64
70
        # Can it handle subdirectories of branches too ?
65
 
        out, err = self.run_bzr('init', 'subdir1')
 
71
        out, err = self.run_bzr('init subdir1')
66
72
        self.assertEqual('', out)
67
73
        self.assertEqual('', err)
68
74
        WorkingTree.open('subdir1')
69
75
        
70
 
        out, err = self.run_bzr('init', 'subdir2/nothere', retcode=3)
 
76
        self.run_bzr_error(['Parent directory of subdir2/nothere does not exist'],
 
77
                            'init subdir2/nothere')
 
78
        out, err = self.run_bzr('init subdir2/nothere', retcode=3)
71
79
        self.assertEqual('', out)
72
 
        self.failUnless(err.startswith(
73
 
            'bzr: ERROR: exceptions.OSError: '
74
 
            '[Errno 2] No such file or directory: '))
75
80
        
76
81
        os.mkdir('subdir2')
77
 
        out, err = self.run_bzr('init', 'subdir2')
 
82
        out, err = self.run_bzr('init subdir2')
78
83
        self.assertEqual('', out)
79
84
        self.assertEqual('', err)
80
85
        # init an existing branch.
81
 
        out, err = self.run_bzr('init', 'subdir2', retcode=3)
 
86
        out, err = self.run_bzr('init subdir2', retcode=3)
82
87
        self.assertEqual('', out)
83
88
        self.failUnless(err.startswith('bzr: ERROR: Already a branch:'))
 
89
 
 
90
    def test_init_existing_branch(self):
 
91
        self.run_bzr('init')
 
92
        out, err = self.run_bzr('init', retcode=3)
 
93
        self.assertContainsRe(err, 'Already a branch')
 
94
        # don't suggest making a checkout, there's already a working tree
 
95
        self.assertFalse(re.search(r'checkout', err))
 
96
 
 
97
    def test_init_existing_without_workingtree(self):
 
98
        # make a repository
 
99
        repo = self.make_repository('.', shared=True)
 
100
        repo.set_make_working_trees(False)
 
101
        # make a branch; by default without a working tree
 
102
        self.run_bzr('init subdir')
 
103
        # fail
 
104
        out, err = self.run_bzr('init subdir', retcode=3)
 
105
        # suggests using checkout
 
106
        self.assertContainsRe(err,
 
107
                              'ontains a branch.*but no working tree.*checkout')
 
108
 
 
109
    def test_no_defaults(self):
 
110
        """Init creates no default ignore rules."""
 
111
        self.run_bzr('init')
 
112
        self.assertFalse(os.path.exists('.bzrignore'))
 
113
 
 
114
    def test_init_unicode(self):
 
115
        # Make sure getcwd can handle unicode filenames
 
116
        try:
 
117
            os.mkdir(u'mu-\xb5')
 
118
        except UnicodeError:
 
119
            raise TestSkipped("Unable to create Unicode filename")
 
120
        # try to init unicode dir
 
121
        self.run_bzr(['init', u'mu-\xb5'])
 
122
 
 
123
    def create_simple_tree(self):
 
124
        tree = self.make_branch_and_tree('tree')
 
125
        self.build_tree(['tree/a'])
 
126
        tree.add(['a'], ['a-id'])
 
127
        tree.commit('one', rev_id='r1')
 
128
        return tree
 
129
 
 
130
    def test_init_create_prefix(self):
 
131
        """'bzr init --create-prefix; will create leading directories."""
 
132
        tree = self.create_simple_tree()
 
133
 
 
134
        self.run_bzr_error(['Parent directory of ../new/tree does not exist'],
 
135
                            'init ../new/tree', working_dir='tree')
 
136
        self.run_bzr('init ../new/tree --create-prefix', working_dir='tree')
 
137
        self.failUnlessExists('new/tree/.bzr')
 
138
 
 
139
 
 
140
class TestSFTPInit(TestCaseWithSFTPServer):
 
141
 
 
142
    def test_init(self):
 
143
        # init on a remote url should succeed.
 
144
        out, err = self.run_bzr(['init', self.get_url()])
 
145
        self.assertEqual('', out)
 
146
        self.assertEqual('', err)
 
147
    
 
148
    def test_init_existing_branch(self):
 
149
        # when there is already a branch present, make mention
 
150
        self.make_branch('.')
 
151
 
 
152
        # rely on SFTPServer get_url() pointing at '.'
 
153
        out, err = self.run_bzr_error(['Already a branch'],
 
154
                                      ['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 --dirstate-tags branch6')
 
173
        branch = _mod_branch.Branch.open('branch6')
 
174
        self.assertEqual(True, branch._get_append_revisions_only())
 
175
        self.run_bzr_error(['cannot be set to append-revisions-only'],
 
176
                           'init --append-revisions-only --knit knit')