~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

Crufty but existing _iter_changes implementation for WorkingTreeFormat4.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006 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.blackbox import ExternalBase
 
28
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
 
29
from bzrlib.workingtree import WorkingTree
 
30
 
 
31
 
 
32
class TestInit(ExternalBase):
 
33
 
 
34
    def test_init_with_format(self):
 
35
        # Verify bzr init --format constructs something plausible
 
36
        t = self.get_transport()
 
37
        self.runbzr('init --format default')
 
38
        self.assertIsDirectory('.bzr', t)
 
39
        self.assertIsDirectory('.bzr/checkout', t)
 
40
        self.assertIsDirectory('.bzr/checkout/lock', t)
 
41
 
 
42
    def test_init_weave(self):
 
43
        # --format=weave should be accepted to allow interoperation with
 
44
        # old releases when desired.
 
45
        out, err = self.run_bzr('init', '--format=weave')
 
46
        self.assertEqual('', out)
 
47
        self.assertEqual('', err)
 
48
 
 
49
    def test_init_at_repository_root(self):
 
50
        # bzr init at the root of a repository should create a branch
 
51
        # and working tree even when creation of working trees is disabled.
 
52
        t = self.get_transport()
 
53
        t.mkdir('repo')
 
54
        format = BzrDirMetaFormat1()
 
55
        newdir = format.initialize(t.abspath('repo'))
 
56
        repo = newdir.create_repository(shared=True)
 
57
        repo.set_make_working_trees(False)
 
58
        out, err = self.run_bzr('init', 'repo')
 
59
        self.assertEqual('', out)
 
60
        self.assertEqual('', err)
 
61
        newdir.open_branch()
 
62
        newdir.open_workingtree()
 
63
        
 
64
    def test_init_branch(self):
 
65
        out, err = self.run_bzr('init')
 
66
        self.assertEqual('', out)
 
67
        self.assertEqual('', err)
 
68
 
 
69
        # Can it handle subdirectories of branches too ?
 
70
        out, err = self.run_bzr('init', 'subdir1')
 
71
        self.assertEqual('', out)
 
72
        self.assertEqual('', err)
 
73
        WorkingTree.open('subdir1')
 
74
        
 
75
        out, err = self.run_bzr('init', 'subdir2/nothere', retcode=3)
 
76
        self.assertEqual('', out)
 
77
        self.assertContainsRe(err,
 
78
            r'^bzr: ERROR: .*'
 
79
            '\[Errno 2\] No such file or directory')
 
80
        
 
81
        os.mkdir('subdir2')
 
82
        out, err = self.run_bzr('init', 'subdir2')
 
83
        self.assertEqual('', out)
 
84
        self.assertEqual('', err)
 
85
        # init an existing branch.
 
86
        out, err = self.run_bzr('init', 'subdir2', retcode=3)
 
87
        self.assertEqual('', out)
 
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
        self.run_bzr('init-repo', '.')
 
100
        # make a branch; by default without a working tree
 
101
        self.run_bzr('init', 'subdir')
 
102
        # fail
 
103
        out, err = self.run_bzr('init', 'subdir', retcode=3)
 
104
        # suggests using checkout
 
105
        self.assertContainsRe(err, 'ontains a branch.*but no working tree.*checkout')
 
106
 
 
107
    def test_no_defaults(self):
 
108
        """Init creates no default ignore rules."""
 
109
        self.run_bzr('init')
 
110
        self.assertFalse(os.path.exists('.bzrignore'))
 
111
 
 
112
 
 
113
class TestSFTPInit(TestCaseWithSFTPServer):
 
114
 
 
115
    def test_init(self):
 
116
        # init on a remote url should succeed.
 
117
        out, err = self.run_bzr('init', self.get_url())
 
118
        self.assertEqual('', out)
 
119
        self.assertEqual('', err)
 
120
    
 
121
    def test_init_existing_branch(self):
 
122
        # when there is already a branch present, make mention
 
123
        self.make_branch('.')
 
124
 
 
125
        # rely on SFTPServer get_url() pointing at '.'
 
126
        out, err = self.run_bzr_error(['Already a branch'], 'init', self.get_url())
 
127
 
 
128
        # make sure using 'bzr checkout' is not suggested
 
129
        # for remote locations missing a working tree
 
130
        self.assertFalse(re.search(r'use bzr checkout', err))
 
131
 
 
132
    def test_init_existing_branch_with_workingtree(self):
 
133
        # don't distinguish between the branch having a working tree or not
 
134
        # when the branch itself is remote.
 
135
        self.make_branch_and_tree('.')
 
136
 
 
137
        # rely on SFTPServer get_url() pointing at '.'
 
138
        self.run_bzr_error(['Already a branch'], 'init', self.get_url())
 
139
 
 
140
    def test_init_append_revisions_only(self):
 
141
        self.run_bzr('init', '--experimental-branch6', 'normal_branch6')
 
142
        branch = _mod_branch.Branch.open('normal_branch6')
 
143
        self.assertEqual(False, branch._get_append_revisions_only())
 
144
        self.run_bzr('init', '--append-revisions-only',
 
145
                     '--experimental-branch6', 'branch6')
 
146
        branch = _mod_branch.Branch.open('branch6')
 
147
        self.assertEqual(True, branch._get_append_revisions_only())
 
148
        self.run_bzr_error(['cannot be set to append-revisions-only'], 'init',
 
149
            '--append-revisions-only', '--knit', 'knit')