~bzr-pqm/bzr/bzr.dev

2370.3.1 by John Arbash Meinel
(John Arbash Meinel) Fix bug #93854, make 'bzr checkout' create branches in the same format as the source.
1
# Copyright (C) 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
"""Tests for the Branch.create_checkout"""
18
19
from bzrlib import (
20
    branch,
21
    )
2018.5.122 by Robert Collins
More Branch implementation test passing foo.
22
from bzrlib.remote import RemoteBranch
2370.3.1 by John Arbash Meinel
(John Arbash Meinel) Fix bug #93854, make 'bzr checkout' create branches in the same format as the source.
23
from bzrlib.tests.branch_implementations.test_branch import TestCaseWithBranch
24
25
26
class TestCreateCheckout(TestCaseWithBranch):
27
28
    def test_checkout_format(self):
29
        """Make sure the new checkout uses the same branch format."""
30
        a_branch = self.make_branch('branch')
2018.5.122 by Robert Collins
More Branch implementation test passing foo.
31
        if isinstance(a_branch, RemoteBranch):
32
            # RemoteBranch formats are not the same as local ones, and dont
33
            # duplicate the format string (because there is no format string as
34
            # such - it might be e.g. totally virtual on the server end).
35
            # This test can only assess the checkout format correctness *in
36
            # general* when there is a real object locally present for both the
37
            # source and target.
38
            return
2370.3.1 by John Arbash Meinel
(John Arbash Meinel) Fix bug #93854, make 'bzr checkout' create branches in the same format as the source.
39
        tree = a_branch.create_checkout('checkout')
40
        if self.branch_format in branch._legacy_formats:
41
            # Legacy formats create checkouts with the default format.
42
            # Only newer formats create identical checkouts.
43
            expected_format = branch.BranchFormat.get_default_format()
44
        else:
45
            expected_format = a_branch._format
2018.5.122 by Robert Collins
More Branch implementation test passing foo.
46
        self.assertEqual(expected_format.__class__,
47
                         tree.branch._format.__class__)
2370.3.1 by John Arbash Meinel
(John Arbash Meinel) Fix bug #93854, make 'bzr checkout' create branches in the same format as the source.
48
49
    def test_create_revision_checkout(self):
50
        """Test that we can create a checkout from an earlier revision."""
51
        tree1 = self.make_branch_and_tree('base')
52
        self.build_tree(['base/a'])
53
        tree1.add(['a'], ['a-id'])
54
        tree1.commit('first', rev_id='rev-1')
55
        self.build_tree(['base/b'])
56
        tree1.add(['b'], ['b-id'])
57
        tree1.commit('second', rev_id='rev-2')
58
59
        tree2 = tree1.branch.create_checkout('checkout', revision_id='rev-1')
60
        self.assertEqual('rev-1', tree2.last_revision())
61
        self.failUnlessExists('checkout/a')
62
        self.failIfExists('checkout/b')
63
64
    def test_create_lightweight_checkout(self):
65
        """We should be able to make a lightweight checkout."""
66
        tree1 = self.make_branch_and_tree('base')
67
        tree2 = tree1.branch.create_checkout('checkout', lightweight=True)
68
        self.assertNotEqual(tree1.basedir, tree2.basedir)
69
        self.assertEqual(tree1.branch.base, tree2.branch.base)
70
71
    def test_create_checkout_exists(self):
72
        """We shouldn't fail if the directory already exists."""
73
        tree1 = self.make_branch_and_tree('base')
74
        self.build_tree('checkout')
75
        tree2 = tree1.branch.create_checkout('checkout', lightweight=True)