1
# Copyright (C) 2005 by Canonical Ltd
2
# -*- coding: utf-8 -*-
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
"""Tests for the 'checkout' CLI command."""
20
from cStringIO import StringIO
26
import bzrlib.bzrdir as bzrdir
27
import bzrlib.errors as errors
28
from bzrlib.tests.blackbox import ExternalBase
31
class TestCheckout(ExternalBase):
34
super(TestCheckout, self).setUp()
35
tree = bzrdir.BzrDir.create_standalone_workingtree('branch')
36
tree.commit('1', rev_id='1', allow_pointless=True)
37
self.build_tree(['branch/added_in_2'])
38
tree.add('added_in_2')
39
tree.commit('2', rev_id='2')
41
def test_checkout_makes_bound_branch(self):
42
self.runbzr('checkout branch checkout')
43
# if we have a checkout, the branch base should be 'branch'
44
source = bzrdir.BzrDir.open('branch')
45
result = bzrdir.BzrDir.open('checkout')
46
self.assertEqual(source.open_branch().bzrdir.root_transport.base,
47
result.open_branch().get_bound_location())
49
def test_checkout_light_makes_checkout(self):
50
self.runbzr('checkout --lightweight branch checkout')
51
# if we have a checkout, the branch base should be 'branch'
52
source = bzrdir.BzrDir.open('branch')
53
result = bzrdir.BzrDir.open('checkout')
54
self.assertEqual(source.open_branch().bzrdir.root_transport.base,
55
result.open_branch().bzrdir.root_transport.base)
57
def test_checkout_dash_r(self):
58
self.runbzr('checkout -r -2 branch checkout')
59
# the working tree should now be at revision '1' with the content
61
result = bzrdir.BzrDir.open('checkout')
62
self.assertEqual('1', result.open_workingtree().last_revision())
63
self.failIfExists('checkout/added_in_2')
65
def test_checkout_light_dash_r(self):
66
self.runbzr('checkout --lightweight -r -2 branch checkout')
67
# the working tree should now be at revision '1' with the content
69
result = bzrdir.BzrDir.open('checkout')
70
self.assertEqual('1', result.open_workingtree().last_revision())
71
self.failIfExists('checkout/added_in_2')
73
def test_checkout_reconstitutes_working_trees(self):
74
# doing a 'bzr checkout' in the directory of a branch with no tree
75
# or a 'bzr checkout path' with path the name of a directory with
76
# a branch with no tree will reconsistute the tree.
77
os.mkdir('treeless-branch')
78
branch = bzrdir.BzrDir.create_branch_convenience(
81
format=bzrdir.BzrDirMetaFormat1())
82
# check no tree was created
83
self.assertRaises(errors.NoWorkingTree, branch.bzrdir.open_workingtree)
84
out, err = self.run_bzr('checkout', 'treeless-branch')
85
# we should have a tree now
86
branch.bzrdir.open_workingtree()
88
out, err = self.run_bzr('diff', 'treeless-branch')
90
# now test with no parameters
91
branch = bzrdir.BzrDir.create_branch_convenience(
94
format=bzrdir.BzrDirMetaFormat1())
95
# check no tree was created
96
self.assertRaises(errors.NoWorkingTree, branch.bzrdir.open_workingtree)
97
out, err = self.run_bzr('checkout')
98
# we should have a tree now
99
branch.bzrdir.open_workingtree()
101
out, err = self.run_bzr('diff')