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
24
23
from bzrlib.branch import Branch
25
24
from bzrlib.tests.blackbox import ExternalBase
26
25
from bzrlib.uncommit import uncommit
26
from bzrlib import urlutils
29
29
class TestPull(ExternalBase):
96
96
self.runbzr('pull ../b')
97
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)
99
112
def test_pull_revision(self):
100
113
"""Pull some changes from one branch to another."""
247
260
tree_b.commit('commit d')
248
261
out = self.runbzr('pull ../branch_a', retcode=3)
249
262
self.assertEquals(out,
250
('','bzr: ERROR: These branches have diverged. Try merge.\n'))
263
('','bzr: ERROR: These branches have diverged.'
264
' Use the merge command to reconcile them.\n'))
251
265
self.assertEquals(branch_b.get_parent(), parent)
252
266
# test implicit --remember after resolving previous failure
253
267
uncommit(branch=branch_b, tree=tree_b)
258
272
self.runbzr('pull ../branch_c --remember')
259
273
self.assertEquals(branch_b.get_parent(),
260
274
branch_c.bzrdir.root_transport.base)
276
def test_pull_bundle(self):
277
from bzrlib.testament import Testament
278
# Build up 2 trees and prepare for a pull
279
tree_a = self.make_branch_and_tree('branch_a')
280
f = open('branch_a/a', 'wb')
284
tree_a.commit('message')
286
tree_b = tree_a.bzrdir.sprout('branch_b').open_workingtree()
288
# Make a change to 'a' that 'b' can pull
289
f = open('branch_a/a', 'wb')
292
tree_a.commit('message')
294
# Create the bundle for 'b' to pull
296
bundle_file = open('../bundle', 'wb')
297
bundle_file.write(self.run_bzr('bundle', '../branch_b')[0])
300
os.chdir('../branch_b')
301
out, err = self.run_bzr('pull', '../bundle')
302
self.assertEqual(out,
303
'Now on revision 2.\n')
304
self.assertEqual(err,
305
' M a\nAll changes applied successfully.\n')
307
self.assertEqualDiff(tree_a.branch.revision_history(),
308
tree_b.branch.revision_history())
310
testament_a = Testament.from_revision(tree_a.branch.repository,
311
tree_a.get_parent_ids()[0])
312
testament_b = Testament.from_revision(tree_b.branch.repository,
313
tree_b.get_parent_ids()[0])
314
self.assertEqualDiff(testament_a.as_text(),
315
testament_b.as_text())
317
# it is legal to attempt to pull an already-merged bundle
318
out, err = self.run_bzr('pull', '../bundle')
319
self.assertEqual(err, '')
320
self.assertEqual(out, 'No revisions to pull.\n')