1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
# Copyright (C) 2006, 2007, 2009, 2010 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
"""Tests for the 'checkout' CLI command."""
from cStringIO import StringIO
import os
import re
import shutil
import sys
from bzrlib import (
branch as _mod_branch,
bzrdir,
errors,
workingtree,
)
from bzrlib.tests import (
TestCaseWithTransport,
)
from bzrlib.tests import (
HardlinkFeature,
KnownFailure,
)
class TestCheckout(TestCaseWithTransport):
def setUp(self):
super(TestCheckout, self).setUp()
tree = bzrdir.BzrDir.create_standalone_workingtree('branch')
tree.commit('1', rev_id='1', allow_pointless=True)
self.build_tree(['branch/added_in_2'])
tree.add('added_in_2')
tree.commit('2', rev_id='2')
def test_checkout_makes_bound_branch(self):
self.run_bzr('checkout branch checkout')
# if we have a checkout, the branch base should be 'branch'
source = bzrdir.BzrDir.open('branch')
result = bzrdir.BzrDir.open('checkout')
self.assertEqual(source.open_branch().bzrdir.root_transport.base,
result.open_branch().get_bound_location())
def test_checkout_light_makes_checkout(self):
self.run_bzr('checkout --lightweight branch checkout')
# if we have a checkout, the branch base should be 'branch'
source = bzrdir.BzrDir.open('branch')
result = bzrdir.BzrDir.open('checkout')
self.assertEqual(source.open_branch().bzrdir.root_transport.base,
result.open_branch().bzrdir.root_transport.base)
def test_checkout_dash_r(self):
out, err = self.run_bzr(['checkout', '-r', '-2', 'branch', 'checkout'])
# the working tree should now be at revision '1' with the content
# from 1.
result = bzrdir.BzrDir.open('checkout')
self.assertEqual(['1'], result.open_workingtree().get_parent_ids())
self.failIfExists('checkout/added_in_2')
def test_checkout_light_dash_r(self):
out, err = self.run_bzr(['checkout','--lightweight', '-r', '-2',
'branch', 'checkout'])
# the working tree should now be at revision '1' with the content
# from 1.
result = bzrdir.BzrDir.open('checkout')
self.assertEqual(['1'], result.open_workingtree().get_parent_ids())
self.failIfExists('checkout/added_in_2')
def test_checkout_reconstitutes_working_trees(self):
# doing a 'bzr checkout' in the directory of a branch with no tree
# or a 'bzr checkout path' with path the name of a directory with
# a branch with no tree will reconsistute the tree.
os.mkdir('treeless-branch')
branch = bzrdir.BzrDir.create_branch_convenience(
'treeless-branch',
force_new_tree=False,
format=bzrdir.BzrDirMetaFormat1())
# check no tree was created
self.assertRaises(errors.NoWorkingTree, branch.bzrdir.open_workingtree)
out, err = self.run_bzr('checkout treeless-branch')
# we should have a tree now
branch.bzrdir.open_workingtree()
# with no diff
out, err = self.run_bzr('diff treeless-branch')
# now test with no parameters
branch = bzrdir.BzrDir.create_branch_convenience(
'.',
force_new_tree=False,
format=bzrdir.BzrDirMetaFormat1())
# check no tree was created
self.assertRaises(errors.NoWorkingTree, branch.bzrdir.open_workingtree)
out, err = self.run_bzr('checkout')
# we should have a tree now
branch.bzrdir.open_workingtree()
# with no diff
out, err = self.run_bzr('diff')
def _test_checkout_existing_dir(self, lightweight):
source = self.make_branch_and_tree('source')
self.build_tree_contents([('source/file1', 'content1'),
('source/file2', 'content2'),])
source.add(['file1', 'file2'])
source.commit('added files')
self.build_tree_contents([('target/', ''),
('target/file1', 'content1'),
('target/file2', 'content3'),])
cmd = ['checkout', 'source', 'target']
if lightweight:
cmd.append('--lightweight')
self.run_bzr('checkout source target')
# files with unique content should be moved
self.failUnlessExists('target/file2.moved')
# files with content matching tree should not be moved
self.failIfExists('target/file1.moved')
def test_checkout_existing_dir_heavy(self):
self._test_checkout_existing_dir(False)
def test_checkout_existing_dir_lightweight(self):
self._test_checkout_existing_dir(True)
def test_checkout_in_branch_with_r(self):
branch = _mod_branch.Branch.open('branch')
branch.bzrdir.destroy_workingtree()
os.chdir('branch')
self.run_bzr('checkout -r 1')
tree = workingtree.WorkingTree.open('.')
self.assertEqual('1', tree.last_revision())
branch.bzrdir.destroy_workingtree()
self.run_bzr('checkout -r 0')
self.assertEqual('null:', tree.last_revision())
def test_checkout_files_from(self):
branch = _mod_branch.Branch.open('branch')
self.run_bzr(['checkout', 'branch', 'branch2', '--files-from',
'branch'])
def test_checkout_hardlink(self):
self.requireFeature(HardlinkFeature)
source = self.make_branch_and_tree('source')
self.build_tree(['source/file1'])
source.add('file1')
source.commit('added file')
out, err = self.run_bzr('checkout source target --hardlink')
source_stat = os.stat('source/file1')
target_stat = os.stat('target/file1')
self.assertEqual(source_stat, target_stat)
def test_checkout_hardlink_files_from(self):
self.requireFeature(HardlinkFeature)
source = self.make_branch_and_tree('source')
self.build_tree(['source/file1'])
source.add('file1')
source.commit('added file')
source.bzrdir.sprout('second')
out, err = self.run_bzr('checkout source target --hardlink'
' --files-from second')
second_stat = os.stat('second/file1')
target_stat = os.stat('target/file1')
self.assertEqual(second_stat, target_stat)
|