~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: John Arbash Meinel
  • Author(s): Mark Hammond
  • Date: 2008-09-09 17:02:21 UTC
  • mto: This revision was merged to the branch mainline in revision 3697.
  • Revision ID: john@arbash-meinel.com-20080909170221-svim3jw2mrz0amp3
An updated transparent icon for bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2011 Canonical Ltd
 
1
# Copyright (C) 2006 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
18
18
from bzrlib import (
19
 
    branch,
20
19
    errors,
21
20
    revision as _mod_revision,
22
 
    tests,
23
21
    )
24
 
from bzrlib.tests import per_branch
 
22
from bzrlib.tests.branch_implementations.test_branch import TestCaseWithBranch
25
23
 
26
24
 
27
25
"""Tests for branch.update()"""
28
26
 
29
27
 
30
 
class TestUpdate(per_branch.TestCaseWithBranch):
 
28
class TestUpdate(TestCaseWithBranch):
31
29
 
32
30
    def test_update_unbound_works(self):
33
31
        b = self.make_branch('.')
68
66
        # commit to the master making the child tree out of date and not a prefix.
69
67
        master_tree.commit('bar', rev_id='bar', allow_pointless=True)
70
68
        self.assertEqual('foo', child_tree.branch.update())
71
 
        self.assertEqual('bar', child_tree.branch.last_revision())
72
 
 
73
 
    def test_update_in_checkout_of_readonly(self):
74
 
        tree1 = self.make_branch_and_tree('tree1')
75
 
        rev1 = tree1.commit('one')
76
 
        try:
77
 
            tree1.branch.tags.set_tag('test-tag', rev1)
78
 
        except errors.TagsNotSupported:
79
 
            # Tags not supported
80
 
            raise tests.TestNotApplicable("only triggered from branches with"
81
 
                " tags")
82
 
        readonly_branch1 = branch.Branch.open('readonly+' + tree1.branch.base)
83
 
        tree2 = tree1.bzrdir.sprout('tree2').open_workingtree()
84
 
        try:
85
 
            tree2.branch.bind(readonly_branch1)
86
 
        except errors.UpgradeRequired:
87
 
            # old branch, cant test.
88
 
            raise tests.TestNotApplicable("only triggered in bound branches")
89
 
        rev2 = tree1.commit('two')
90
 
        tree2.update()
91
 
        self.assertEqual(rev2, tree2.branch.last_revision())
 
69
        self.assertEqual(['bar'], child_tree.branch.revision_history())
 
70
 
 
71
 
 
72
class TestUpdateRevisions(TestCaseWithBranch):
 
73
 
 
74
    def test_accepts_graph(self):
 
75
        # An implementation may not use it, but it should allow a 'graph' to be
 
76
        # supplied
 
77
        tree1 = self.make_branch_and_tree('tree1')
 
78
        rev1 = tree1.commit('one')
 
79
        tree2 = tree1.bzrdir.sprout('tree2').open_workingtree()
 
80
        rev2 = tree2.commit('two')
 
81
 
 
82
        tree1.lock_write()
 
83
        self.addCleanup(tree1.unlock)
 
84
        tree2.lock_read()
 
85
        self.addCleanup(tree2.unlock)
 
86
        graph = tree2.branch.repository.get_graph(tree1.branch.repository)
 
87
 
 
88
        tree1.branch.update_revisions(tree2.branch, graph=graph)
 
89
        self.assertEqual((2, rev2), tree1.branch.last_revision_info())
 
90
 
 
91
    def test_overwrite_ignores_diverged(self):
 
92
        tree1 = self.make_branch_and_tree('tree1')
 
93
        rev1 = tree1.commit('one')
 
94
        tree2 = tree1.bzrdir.sprout('tree2').open_workingtree()
 
95
        rev2 = tree1.commit('two')
 
96
        rev2b = tree2.commit('alt two')
 
97
 
 
98
        self.assertRaises(errors.DivergedBranches,
 
99
                          tree1.branch.update_revisions,
 
100
                          tree2.branch, overwrite=False)
 
101
        # However, the revision should be copied into the repository
 
102
        self.assertTrue(tree1.branch.repository.has_revision(rev2b))
 
103
 
 
104
        tree1.branch.update_revisions(tree2.branch, overwrite=True)
 
105
        self.assertEqual((2, rev2b), tree1.branch.last_revision_info())
 
106
 
 
107
    def test_ignores_older_unless_overwrite(self):
 
108
        tree1 = self.make_branch_and_tree('tree1')
 
109
        rev1 = tree1.commit('one')
 
110
        tree2 = tree1.bzrdir.sprout('tree2').open_workingtree()
 
111
        rev2 = tree1.commit('two')
 
112
 
 
113
        tree1.branch.update_revisions(tree2.branch)
 
114
        self.assertEqual((2, rev2), tree1.branch.last_revision_info())
 
115
 
 
116
        tree1.branch.update_revisions(tree2.branch, overwrite=True)
 
117
        self.assertEqual((1, rev1), tree1.branch.last_revision_info())