1
# Copyright (C) 2007 Canonical Ltd
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.
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.
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
17
"""Tests for the Branch.create_checkout"""
22
from bzrlib.remote import RemoteBranch
23
from bzrlib.tests.branch_implementations.test_branch import TestCaseWithBranch
26
class TestCreateCheckout(TestCaseWithBranch):
28
def test_checkout_format(self):
29
"""Make sure the new checkout uses the desired branch format."""
30
a_branch = self.make_branch('branch')
31
tree = a_branch.create_checkout('checkout')
32
# All branches can define the format they want checkouts made in.
33
# This checks it is honoured.
34
expected_format = a_branch._get_checkout_format().get_branch_format()
35
self.assertEqual(expected_format.__class__,
36
tree.branch._format.__class__)
38
def test_create_revision_checkout(self):
39
"""Test that we can create a checkout from an earlier revision."""
40
tree1 = self.make_branch_and_tree('base')
41
self.build_tree(['base/a'])
42
tree1.add(['a'], ['a-id'])
43
tree1.commit('first', rev_id='rev-1')
44
self.build_tree(['base/b'])
45
tree1.add(['b'], ['b-id'])
46
tree1.commit('second', rev_id='rev-2')
48
tree2 = tree1.branch.create_checkout('checkout', revision_id='rev-1')
49
self.assertEqual('rev-1', tree2.last_revision())
50
self.failUnlessExists('checkout/a')
51
self.failIfExists('checkout/b')
53
def test_create_lightweight_checkout(self):
54
"""We should be able to make a lightweight checkout."""
55
tree1 = self.make_branch_and_tree('base')
56
tree2 = tree1.branch.create_checkout('checkout', lightweight=True)
57
self.assertNotEqual(tree1.basedir, tree2.basedir)
58
self.assertEqual(tree1.branch.base, tree2.branch.base)
60
def test_create_checkout_exists(self):
61
"""We shouldn't fail if the directory already exists."""
62
tree1 = self.make_branch_and_tree('base')
63
self.build_tree(['checkout/'])
64
tree2 = tree1.branch.create_checkout('checkout', lightweight=True)