~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_pull.py

  • Committer: Aaron Bentley
  • Date: 2007-03-07 23:15:10 UTC
  • mto: (1551.19.24 Aaron's mergeable stuff)
  • mto: This revision was merged to the branch mainline in revision 2325.
  • Revision ID: abentley@panoramicfeedback.com-20070307231510-jae63zsli83db3eb
Make ChangeReporter private

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 by Canonical Ltd
2
 
# -*- coding: utf-8 -*-
3
 
 
 
1
# Copyright (C) 2005, 2006 Canonical Ltd
 
2
#
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.
8
 
 
 
7
#
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.
13
 
 
 
12
#
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
22
21
import sys
23
22
 
24
23
from bzrlib.branch import Branch
25
 
from bzrlib.osutils import abspath
26
24
from bzrlib.tests.blackbox import ExternalBase
27
25
from bzrlib.uncommit import uncommit
 
26
from bzrlib import urlutils
28
27
 
29
28
 
30
29
class TestPull(ExternalBase):
97
96
        self.runbzr('pull ../b')
98
97
        self.runbzr('pull ../b')
99
98
 
 
99
    def test_pull_dash_d(self):
 
100
        os.mkdir('a')
 
101
        os.chdir('a')
 
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)
 
111
 
100
112
    def test_pull_revision(self):
101
113
        """Pull some changes from one branch to another."""
102
114
        os.mkdir('a')
248
260
        tree_b.commit('commit d')
249
261
        out = self.runbzr('pull ../branch_a', retcode=3)
250
262
        self.assertEquals(out,
251
 
                ('','bzr: ERROR: These branches have diverged.  Try merge.\n'))
252
 
        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)
253
265
        # test implicit --remember after resolving previous failure
254
266
        uncommit(branch=branch_b, tree=tree_b)
255
267
        transport.delete('branch_b/d')
256
268
        self.runbzr('pull')
257
 
        self.assertEquals(abspath(branch_b.get_parent()), abspath(parent))
 
269
        self.assertEquals(branch_b.get_parent(), parent)
258
270
        # test explicit --remember
259
271
        self.runbzr('pull ../branch_c --remember')
260
 
        self.assertEquals(abspath(branch_b.get_parent()),
261
 
                          abspath(branch_c.bzrdir.root_transport.base))
 
272
        self.assertEquals(branch_b.get_parent(),
 
273
                          branch_c.bzrdir.root_transport.base)
 
274
 
 
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')
 
280
        f.write('hello')
 
281
        f.close()
 
282
        tree_a.add('a')
 
283
        tree_a.commit('message')
 
284
 
 
285
        tree_b = tree_a.bzrdir.sprout('branch_b').open_workingtree()
 
286
 
 
287
        # Make a change to 'a' that 'b' can pull
 
288
        f = open('branch_a/a', 'wb')
 
289
        f.write('hey there')
 
290
        f.close()
 
291
        tree_a.commit('message')
 
292
 
 
293
        # Create the bundle for 'b' to pull
 
294
        os.chdir('branch_a')
 
295
        bundle_file = open('../bundle', 'wb')
 
296
        bundle_file.write(self.run_bzr('bundle', '../branch_b')[0])
 
297
        bundle_file.close()
 
298
 
 
299
        os.chdir('../branch_b')
 
300
        out, err = self.run_bzr('pull', '../bundle')
 
301
        self.assertEqual(out,
 
302
                         'Now on revision 2.\n')
 
303
        self.assertEqual(err,
 
304
                ' M  a\nAll changes applied successfully.\n')
 
305
 
 
306
        self.assertEqualDiff(tree_a.branch.revision_history(),
 
307
                             tree_b.branch.revision_history())
 
308
 
 
309
        testament_a = Testament.from_revision(tree_a.branch.repository,
 
310
                                              tree_a.get_parent_ids()[0])
 
311
        testament_b = Testament.from_revision(tree_b.branch.repository,
 
312
                                              tree_b.get_parent_ids()[0])
 
313
        self.assertEqualDiff(testament_a.as_text(),
 
314
                             testament_b.as_text())
 
315
 
 
316
        # it is legal to attempt to pull an already-merged bundle
 
317
        out, err = self.run_bzr('pull', '../bundle')
 
318
        self.assertEqual(err, '')
 
319
        self.assertEqual(out, 'No revisions to pull.\n')