~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/branch_implementations/test_push.py

  • Committer: Alexander Belchenko
  • Date: 2007-02-02 09:14:30 UTC
  • mfrom: (2256 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2259.
  • Revision ID: bialix@ukr.net-20070202091430-vdgouvazded1yfqw
merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2004, 2005, 2007 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
"""Tests for branch.push behaviour."""
 
18
 
 
19
import os
 
20
 
 
21
from bzrlib.branch import Branch
 
22
from bzrlib import errors
 
23
from bzrlib.tests import TestCaseWithTransport
 
24
 
 
25
 
 
26
class TestPush(TestCaseWithTransport):
 
27
 
 
28
    def test_push_convergence_simple(self):
 
29
        # when revisions are pushed, the left-most accessible parents must 
 
30
        # become the revision-history.
 
31
        mine = self.make_branch_and_tree('mine')
 
32
        mine.commit('1st post', rev_id='P1', allow_pointless=True)
 
33
        other = mine.bzrdir.sprout('other').open_workingtree()
 
34
        other.commit('my change', rev_id='M1', allow_pointless=True)
 
35
        mine.merge_from_branch(other.branch)
 
36
        mine.commit('merge my change', rev_id='P2')
 
37
        mine.branch.push(other.branch)
 
38
        self.assertEqual(['P1', 'P2'], other.branch.revision_history())
 
39
 
 
40
    def test_push_merged_indirect(self):
 
41
        # it should be possible to do a push from one branch into another
 
42
        # when the tip of the target was merged into the source branch
 
43
        # via a third branch - so its buried in the ancestry and is not
 
44
        # directly accessible.
 
45
        mine = self.make_branch_and_tree('mine')
 
46
        mine.commit('1st post', rev_id='P1', allow_pointless=True)
 
47
        target = mine.bzrdir.sprout('target').open_workingtree()
 
48
        target.commit('my change', rev_id='M1', allow_pointless=True)
 
49
        other = mine.bzrdir.sprout('other').open_workingtree()
 
50
        other.merge_from_branch(target.branch)
 
51
        other.commit('merge my change', rev_id='O2')
 
52
        mine.merge_from_branch(other.branch)
 
53
        mine.commit('merge other', rev_id='P2')
 
54
        mine.branch.push(target.branch)
 
55
        self.assertEqual(['P1', 'P2'], target.branch.revision_history())
 
56
 
 
57
    def test_push_to_checkout_updates_master(self):
 
58
        """Pushing into a checkout updates the checkout and the master branch"""
 
59
        master_tree = self.make_branch_and_tree('master')
 
60
        rev1 = master_tree.commit('master')
 
61
        checkout = master_tree.branch.create_checkout('checkout')
 
62
 
 
63
        other = master_tree.branch.bzrdir.sprout('other').open_workingtree()
 
64
        rev2 = other.commit('other commit')
 
65
        # now push, which should update both checkout and master.
 
66
        other.branch.push(checkout.branch)
 
67
        self.assertEqual([rev1, rev2], checkout.branch.revision_history())
 
68
        self.assertEqual([rev1, rev2], master_tree.branch.revision_history())
 
69
 
 
70
    def test_push_raises_specific_error_on_master_connection_error(self):
 
71
        master_tree = self.make_branch_and_tree('master')
 
72
        checkout = master_tree.branch.create_checkout('checkout')
 
73
        other = master_tree.branch.bzrdir.sprout('other').open_workingtree()
 
74
        # move the branch out of the way on disk to cause a connection
 
75
        # error.
 
76
        os.rename('master', 'master_gone')
 
77
        # try to push, which should raise a BoundBranchConnectionFailure.
 
78
        self.assertRaises(errors.BoundBranchConnectionFailure,
 
79
                other.branch.push, checkout.branch)