1
# Copyright (C) 2005 by Canonical Ltd
2
# -*- coding: utf-8 -*-
1
# Copyright (C) 2005, 2006 Canonical Ltd
4
3
# This program is free software; you can redistribute it and/or modify
5
4
# it under the terms of the GNU General Public License as published by
6
5
# the Free Software Foundation; either version 2 of the License, or
7
6
# (at your option) any later version.
9
8
# This program is distributed in the hope that it will be useful,
10
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
11
# GNU General Public License for more details.
14
13
# You should have received a copy of the GNU General Public License
15
14
# along with this program; if not, write to the Free Software
16
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
"""Black-box tests for bzr pull.
18
"""Black-box tests for bzr pull."""
25
23
from bzrlib.branch import Branch
26
from bzrlib.osutils import abspath
27
24
from bzrlib.tests.blackbox import ExternalBase
28
25
from bzrlib.uncommit import uncommit
26
from bzrlib import urlutils
31
29
class TestPull(ExternalBase):
49
47
self.runbzr('missing', retcode=3)
50
48
self.runbzr('missing .')
51
49
self.runbzr('missing')
52
if sys.platform not in ('win32', 'cygwin'):
53
# This is equivalent to doing "bzr pull ."
54
# Which means that bzr creates 2 branches grabbing
55
# the same location, and tries to pull.
56
# However, 2 branches mean 2 locks on the same file
57
# which ultimately implies a deadlock.
58
# (non windows platforms allow multiple locks on the
59
# same file by the same calling process)
50
# this will work on windows because we check for the same branch
51
# in pull - if it fails, it is a regression
61
53
self.runbzr('pull /', retcode=3)
62
54
if sys.platform not in ('win32', 'cygwin'):
63
55
self.runbzr('pull')
104
96
self.runbzr('pull ../b')
105
97
self.runbzr('pull ../b')
99
def test_pull_dash_d(self):
102
self.example_branch()
103
self.runbzr('init ../b')
104
self.runbzr('init ../c')
105
# pull into that branch
106
self.runbzr('pull -d ../b .')
107
# pull into a branch specified by a url
108
c_url = urlutils.local_path_to_url('../c')
109
self.assertStartsWith(c_url, 'file://')
110
self.runbzr('pull -d %s .' % c_url)
107
112
def test_pull_revision(self):
108
113
"""Pull some changes from one branch to another."""
233
238
self.build_tree(['branch_a/a'])
235
240
tree_a.commit('commit a')
236
branch_b = branch_a.bzrdir.sprout('branch_b').open_branch()
237
tree_b = branch_b.bzrdir.open_workingtree()
238
branch_c = branch_a.bzrdir.sprout('branch_c').open_branch()
239
tree_c = branch_c.bzrdir.open_workingtree()
241
tree_b = branch_a.bzrdir.sprout('branch_b').open_workingtree()
242
branch_b = tree_b.branch
243
tree_c = branch_a.bzrdir.sprout('branch_c').open_workingtree()
244
branch_c = tree_c.branch
240
245
self.build_tree(['branch_a/b'])
242
247
tree_a.commit('commit b')
255
260
tree_b.commit('commit d')
256
261
out = self.runbzr('pull ../branch_a', retcode=3)
257
262
self.assertEquals(out,
258
('','bzr: ERROR: These branches have diverged. Try merge.\n'))
259
self.assertEquals(abspath(branch_b.get_parent()), abspath(parent))
263
('','bzr: ERROR: These branches have diverged. Use the merge command to reconcile them.\n'))
264
self.assertEquals(branch_b.get_parent(), parent)
260
265
# test implicit --remember after resolving previous failure
261
266
uncommit(branch=branch_b, tree=tree_b)
262
267
transport.delete('branch_b/d')
263
268
self.runbzr('pull')
264
self.assertEquals(abspath(branch_b.get_parent()), abspath(parent))
269
self.assertEquals(branch_b.get_parent(), parent)
265
270
# test explicit --remember
266
271
self.runbzr('pull ../branch_c --remember')
267
self.assertEquals(abspath(branch_b.get_parent()),
268
abspath(branch_c.bzrdir.root_transport.base))
272
self.assertEquals(branch_b.get_parent(),
273
branch_c.bzrdir.root_transport.base)
275
def test_pull_bundle(self):
276
from bzrlib.testament import Testament
277
# Build up 2 trees and prepare for a pull
278
tree_a = self.make_branch_and_tree('branch_a')
279
f = open('branch_a/a', 'wb')
283
tree_a.commit('message')
285
tree_b = tree_a.bzrdir.sprout('branch_b').open_workingtree()
287
# Make a change to 'a' that 'b' can pull
288
f = open('branch_a/a', 'wb')
291
tree_a.commit('message')
293
# Create the bundle for 'b' to pull
295
bundle_file = open('../bundle', 'wb')
296
bundle_file.write(self.run_bzr('bundle', '../branch_b')[0])
299
os.chdir('../branch_b')
300
output = self.run_bzr('pull', '../bundle')
301
self.assertEqual('', output[0])
302
self.assertEqual(' M a\nAll changes applied successfully.\n'
303
'1 revision(s) pulled.\n', output[1])
305
self.assertEqualDiff(tree_a.branch.revision_history(),
306
tree_b.branch.revision_history())
308
testament_a = Testament.from_revision(tree_a.branch.repository,
309
tree_a.get_parent_ids()[0])
310
testament_b = Testament.from_revision(tree_b.branch.repository,
311
tree_b.get_parent_ids()[0])
312
self.assertEqualDiff(testament_a.as_text(),
313
testament_b.as_text())
315
# it is legal to attempt to pull an already-merged bundle
316
output = self.run_bzr('pull', '../bundle')
317
self.assertEqual('', output[0])
318
self.assertEqual('0 revision(s) pulled.\n', output[1])