/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: Robert Collins
  • Date: 2007-04-18 08:39:02 UTC
  • mto: (2425.1.2 integration)
  • mto: This revision was merged to the branch mainline in revision 2427.
  • Revision ID: robertc@robertcollins.net-20070418083902-4o66h9fk7zeisvwa
Command objects can now declare related help topics by having _see_also
set to a list of related topic. Updated the HACKING guide entry on
documentation to be more clear about how the help for commands is
generated and to reference this new feature. (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006, 2007 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
 
 
18
"""Test "bzr init"""
 
19
 
 
20
import os
 
21
import re
 
22
 
 
23
from bzrlib import (
 
24
    branch as _mod_branch,
 
25
    )
 
26
from bzrlib.bzrdir import BzrDirMetaFormat1
 
27
from bzrlib.tests import TestSkipped
 
28
from bzrlib.tests.blackbox import ExternalBase
 
29
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
 
30
from bzrlib.workingtree import WorkingTree
 
31
 
 
32
 
 
33
class TestInit(ExternalBase):
 
34
 
 
35
    def test_init_with_format(self):
 
36
        # Verify bzr init --format constructs something plausible
 
37
        t = self.get_transport()
 
38
        self.runbzr('init --format default')
 
39
        self.assertIsDirectory('.bzr', t)
 
40
        self.assertIsDirectory('.bzr/checkout', t)
 
41
        self.assertIsDirectory('.bzr/checkout/lock', t)
 
42
 
 
43
    def test_init_weave(self):
 
44
        # --format=weave should be accepted to allow interoperation with
 
45
        # old releases when desired.
 
46
        out, err = self.run_bzr('init', '--format=weave')
 
47
        self.assertEqual('', out)
 
48
        self.assertEqual('', err)
 
49
 
 
50
    def test_init_at_repository_root(self):
 
51
        # bzr init at the root of a repository should create a branch
 
52
        # and working tree even when creation of working trees is disabled.
 
53
        t = self.get_transport()
 
54
        t.mkdir('repo')
 
55
        format = BzrDirMetaFormat1()
 
56
        newdir = format.initialize(t.abspath('repo'))
 
57
        repo = newdir.create_repository(shared=True)
 
58
        repo.set_make_working_trees(False)
 
59
        out, err = self.run_bzr('init', 'repo')
 
60
        self.assertEqual('', out)
 
61
        self.assertEqual('', err)
 
62
        newdir.open_branch()
 
63
        newdir.open_workingtree()
 
64
        
 
65
    def test_init_branch(self):
 
66
        out, err = self.run_bzr('init')
 
67
        self.assertEqual('', out)
 
68
        self.assertEqual('', err)
 
69
 
 
70
        # Can it handle subdirectories of branches too ?
 
71
        out, err = self.run_bzr('init', 'subdir1')
 
72
        self.assertEqual('', out)
 
73
        self.assertEqual('', err)
 
74
        WorkingTree.open('subdir1')
 
75
        
 
76
        out, err = self.run_bzr('init', 'subdir2/nothere', retcode=3)
 
77
        self.assertEqual('', out)
 
78
        self.assertContainsRe(err,
 
79
            r'^bzr: ERROR: No such file: .*'
 
80
            '\[Err(no|or) 2\]')
 
81
        
 
82
        os.mkdir('subdir2')
 
83
        out, err = self.run_bzr('init', 'subdir2')
 
84
        self.assertEqual('', out)
 
85
        self.assertEqual('', err)
 
86
        # init an existing branch.
 
87
        out, err = self.run_bzr('init', 'subdir2', retcode=3)
 
88
        self.assertEqual('', out)
 
89
        self.failUnless(err.startswith('bzr: ERROR: Already a branch:'))
 
90
 
 
91
    def test_init_existing_branch(self):
 
92
        self.run_bzr('init')
 
93
        out, err = self.run_bzr('init', retcode=3)
 
94
        self.assertContainsRe(err, 'Already a branch')
 
95
        # don't suggest making a checkout, there's already a working tree
 
96
        self.assertFalse(re.search(r'checkout', err))
 
97
 
 
98
    def test_init_existing_without_workingtree(self):
 
99
        # make a repository
 
100
        repo = self.make_repository('.', shared=True)
 
101
        repo.set_make_working_trees(False)
 
102
        # make a branch; by default without a working tree
 
103
        self.run_bzr('init', 'subdir')
 
104
        # fail
 
105
        out, err = self.run_bzr('init', 'subdir', retcode=3)
 
106
        # suggests using checkout
 
107
        self.assertContainsRe(err, '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
 
 
124
class TestSFTPInit(TestCaseWithSFTPServer):
 
125
 
 
126
    def test_init(self):
 
127
        # init on a remote url should succeed.
 
128
        out, err = self.run_bzr('init', self.get_url())
 
129
        self.assertEqual('', out)
 
130
        self.assertEqual('', err)
 
131
    
 
132
    def test_init_existing_branch(self):
 
133
        # when there is already a branch present, make mention
 
134
        self.make_branch('.')
 
135
 
 
136
        # rely on SFTPServer get_url() pointing at '.'
 
137
        out, err = self.run_bzr_error(['Already a branch'], 'init', self.get_url())
 
138
 
 
139
        # make sure using 'bzr checkout' is not suggested
 
140
        # for remote locations missing a working tree
 
141
        self.assertFalse(re.search(r'use bzr checkout', err))
 
142
 
 
143
    def test_init_existing_branch_with_workingtree(self):
 
144
        # don't distinguish between the branch having a working tree or not
 
145
        # when the branch itself is remote.
 
146
        self.make_branch_and_tree('.')
 
147
 
 
148
        # rely on SFTPServer get_url() pointing at '.'
 
149
        self.run_bzr_error(['Already a branch'], 'init', self.get_url())
 
150
 
 
151
    def test_init_append_revisions_only(self):
 
152
        self.run_bzr('init', '--dirstate-tags', 'normal_branch6')
 
153
        branch = _mod_branch.Branch.open('normal_branch6')
 
154
        self.assertEqual(False, branch._get_append_revisions_only())
 
155
        self.run_bzr('init', '--append-revisions-only',
 
156
                     '--dirstate-tags', 'branch6')
 
157
        branch = _mod_branch.Branch.open('branch6')
 
158
        self.assertEqual(True, branch._get_append_revisions_only())
 
159
        self.run_bzr_error(['cannot be set to append-revisions-only'], 'init',
 
160
            '--append-revisions-only', '--knit', 'knit')