42
40
super(TestCheckout, self).setUp()
43
41
tree = controldir.ControlDir.create_standalone_workingtree('branch')
44
tree.commit('1', rev_id=b'1', allow_pointless=True)
42
tree.commit('1', rev_id='1', allow_pointless=True)
45
43
self.build_tree(['branch/added_in_2'])
46
44
tree.add('added_in_2')
47
tree.commit('2', rev_id=b'2')
45
tree.commit('2', rev_id='2')
49
47
def test_checkout_makes_bound_branch(self):
50
48
self.run_bzr('checkout branch checkout')
51
49
# if we have a checkout, the branch base should be 'branch'
52
50
source = controldir.ControlDir.open('branch')
53
51
result = controldir.ControlDir.open('checkout')
54
self.assertEqual(source.open_branch().controldir.root_transport.base,
52
self.assertEqual(source.open_branch().bzrdir.root_transport.base,
55
53
result.open_branch().get_bound_location())
57
55
def test_checkout_light_makes_checkout(self):
59
57
# if we have a checkout, the branch base should be 'branch'
60
58
source = controldir.ControlDir.open('branch')
61
59
result = controldir.ControlDir.open('checkout')
62
self.assertEqual(source.open_branch().controldir.root_transport.base,
63
result.open_branch().controldir.root_transport.base)
60
self.assertEqual(source.open_branch().bzrdir.root_transport.base,
61
result.open_branch().bzrdir.root_transport.base)
65
63
def test_checkout_dash_r(self):
66
64
out, err = self.run_bzr(['checkout', '-r', '-2', 'branch', 'checkout'])
67
65
# the working tree should now be at revision '1' with the content
69
67
result = controldir.ControlDir.open('checkout')
70
self.assertEqual([b'1'], result.open_workingtree().get_parent_ids())
68
self.assertEqual(['1'], result.open_workingtree().get_parent_ids())
71
69
self.assertPathDoesNotExist('checkout/added_in_2')
73
71
def test_checkout_light_dash_r(self):
74
out, err = self.run_bzr(['checkout', '--lightweight', '-r', '-2',
75
'branch', 'checkout'])
72
out, err = self.run_bzr(['checkout','--lightweight', '-r', '-2',
73
'branch', 'checkout'])
76
74
# the working tree should now be at revision '1' with the content
78
76
result = controldir.ControlDir.open('checkout')
79
self.assertEqual([b'1'], result.open_workingtree().get_parent_ids())
77
self.assertEqual(['1'], result.open_workingtree().get_parent_ids())
80
78
self.assertPathDoesNotExist('checkout/added_in_2')
82
80
def test_checkout_into_empty_dir(self):
83
self.make_controldir('checkout')
81
self.make_bzrdir('checkout')
84
82
out, err = self.run_bzr(['checkout', 'branch', 'checkout'])
85
83
result = controldir.ControlDir.open('checkout')
86
84
tree = result.open_workingtree()
87
85
branch = result.open_branch()
89
87
def test_checkout_reconstitutes_working_trees(self):
90
# doing a 'brz checkout' in the directory of a branch with no tree
91
# or a 'brz checkout path' with path the name of a directory with
88
# doing a 'bzr checkout' in the directory of a branch with no tree
89
# or a 'bzr checkout path' with path the name of a directory with
92
90
# a branch with no tree will reconsistute the tree.
93
91
os.mkdir('treeless-branch')
94
92
branch = controldir.ControlDir.create_branch_convenience(
96
94
force_new_tree=False,
97
95
format=bzrdir.BzrDirMetaFormat1())
98
96
# check no tree was created
99
self.assertRaises(errors.NoWorkingTree,
100
branch.controldir.open_workingtree)
97
self.assertRaises(errors.NoWorkingTree, branch.bzrdir.open_workingtree)
101
98
out, err = self.run_bzr('checkout treeless-branch')
102
99
# we should have a tree now
103
branch.controldir.open_workingtree()
100
branch.bzrdir.open_workingtree()
105
102
out, err = self.run_bzr('diff treeless-branch')
110
107
force_new_tree=False,
111
108
format=bzrdir.BzrDirMetaFormat1())
112
109
# check no tree was created
113
self.assertRaises(errors.NoWorkingTree,
114
branch.controldir.open_workingtree)
110
self.assertRaises(errors.NoWorkingTree, branch.bzrdir.open_workingtree)
115
111
out, err = self.run_bzr('checkout')
116
112
# we should have a tree now
117
branch.controldir.open_workingtree()
113
branch.bzrdir.open_workingtree()
119
115
out, err = self.run_bzr('diff')
121
117
def _test_checkout_existing_dir(self, lightweight):
122
118
source = self.make_branch_and_tree('source')
123
self.build_tree_contents([('source/file1', b'content1'),
124
('source/file2', b'content2'), ])
119
self.build_tree_contents([('source/file1', 'content1'),
120
('source/file2', 'content2'),])
125
121
source.add(['file1', 'file2'])
126
122
source.commit('added files')
127
self.build_tree_contents([('target/', b''),
128
('target/file1', b'content1'),
129
('target/file2', b'content3'), ])
123
self.build_tree_contents([('target/', ''),
124
('target/file1', 'content1'),
125
('target/file2', 'content3'),])
130
126
cmd = ['checkout', 'source', 'target']
132
128
cmd.append('--lightweight')
145
141
def test_checkout_in_branch_with_r(self):
146
142
branch = _mod_branch.Branch.open('branch')
147
branch.controldir.destroy_workingtree()
143
branch.bzrdir.destroy_workingtree()
148
144
self.run_bzr('checkout -r 1', working_dir='branch')
149
145
tree = workingtree.WorkingTree.open('branch')
150
self.assertEqual(b'1', tree.last_revision())
151
branch.controldir.destroy_workingtree()
146
self.assertEqual('1', tree.last_revision())
147
branch.bzrdir.destroy_workingtree()
152
148
self.run_bzr('checkout -r 0', working_dir='branch')
153
self.assertEqual(b'null:', tree.last_revision())
149
self.assertEqual('null:', tree.last_revision())
155
151
def test_checkout_files_from(self):
156
152
branch = _mod_branch.Branch.open('branch')
186
182
self.build_tree(['source/file1'])
187
183
source.add('file1')
188
184
source.commit('added file')
189
target = source.controldir.sprout('file:second,branch=somebranch',
190
create_tree_if_local=False)
185
target = source.bzrdir.sprout('file:second,branch=somebranch',
186
create_tree_if_local=False)
191
187
out, err = self.run_bzr('checkout file:,branch=somebranch .',
192
working_dir='second')
188
working_dir='second')
193
189
# We should always be creating a lighweight checkout for colocated
195
191
self.assertEqual(
196
target.open_branch(name='somebranch').user_url,
192
target.open_branch(name='somebranch').base,
197
193
target.get_branch_reference(name=""))
211
207
# being too low. If rpc_count increases, more network roundtrips have
212
208
# become necessary for this use case. Please do not adjust this number
213
209
# upwards without agreement from bzr's network support maintainers.
214
self.assertLength(11, self.hpss_calls)
210
self.assertLength(10, self.hpss_calls)
215
211
self.assertLength(1, self.hpss_connections)
216
212
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
222
218
t.commit(message='commit %d' % count)
223
219
self.reset_smart_call_log()
224
220
out, err = self.run_bzr(['checkout', '--lightweight', self.get_url('from'),
226
222
# This figure represent the amount of work to perform this use case. It
227
223
# is entirely ok to reduce this number if a test fails due to rpc_count
228
224
# being too low. If rpc_count increases, more network roundtrips have