/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1508.1.20 by Robert Collins
Create a checkout command.
1
# Copyright (C) 2005 by Canonical Ltd
2
# -*- coding: utf-8 -*-
3
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.
8
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.
13
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
17
18
"""Tests for the 'checkout' CLI command."""
19
20
from cStringIO import StringIO
21
import os
22
import re
23
import shutil
24
import sys
25
26
import bzrlib.bzrdir as bzrdir
1508.1.28 by Robert Collins
Test using bzr checkout to reconstitute working trees.
27
import bzrlib.errors as errors
1508.1.20 by Robert Collins
Create a checkout command.
28
from bzrlib.tests.blackbox import ExternalBase
29
30
31
class TestCheckout(ExternalBase):
32
    
33
    def setUp(self):
34
        super(TestCheckout, self).setUp()
1508.1.21 by Robert Collins
Implement -r limit for checkout command.
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')
1508.1.20 by Robert Collins
Create a checkout command.
40
1587.1.14 by Robert Collins
Make bound branch creation happen via 'checkout'
41
    def test_checkout_makes_bound_branch(self):
1508.1.20 by Robert Collins
Create a checkout command.
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,
1587.1.14 by Robert Collins
Make bound branch creation happen via 'checkout'
47
                         result.open_branch().get_bound_location())
48
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,
1508.1.20 by Robert Collins
Create a checkout command.
55
                         result.open_branch().bzrdir.root_transport.base)
1508.1.21 by Robert Collins
Implement -r limit for checkout command.
56
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
60
        # from 1.
61
        result = bzrdir.BzrDir.open('checkout')
62
        self.assertEqual('1', result.open_workingtree().last_revision())
63
        self.failIfExists('checkout/added_in_2')
64
1587.1.14 by Robert Collins
Make bound branch creation happen via 'checkout'
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
68
        # from 1.
69
        result = bzrdir.BzrDir.open('checkout')
70
        self.assertEqual('1', result.open_workingtree().last_revision())
71
        self.failIfExists('checkout/added_in_2')
72
1508.1.28 by Robert Collins
Test using bzr checkout to reconstitute working trees.
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(
79
            'treeless-branch',
80
            force_new_tree=False,
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()
87
        # with no diff
88
        out, err = self.run_bzr('diff', 'treeless-branch')
89
90
        # now test with no parameters
91
        branch = bzrdir.BzrDir.create_branch_convenience(
92
            '.',
93
            force_new_tree=False,
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()
100
        # with no diff
101
        out, err = self.run_bzr('diff')