~bzr-pqm/bzr/bzr.dev

5582.5.1 by John Arbash Meinel
Fix bug 701212. Don't set the tags for a master branch during update.
1
# Copyright (C) 2006-2011 Canonical Ltd
1587.1.11 by Robert Collins
Local commits appear to be working properly.
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1587.1.11 by Robert Collins
Local commits appear to be working properly.
16
17
2598.5.2 by Aaron Bentley
Got all tests passing with Branch returning 'null:' for null revision
18
from bzrlib import (
5582.5.1 by John Arbash Meinel
Fix bug 701212. Don't set the tags for a master branch during update.
19
    branch,
2598.5.2 by Aaron Bentley
Got all tests passing with Branch returning 'null:' for null revision
20
    errors,
21
    revision as _mod_revision,
5582.5.1 by John Arbash Meinel
Fix bug 701212. Don't set the tags for a master branch during update.
22
    tests,
2598.5.2 by Aaron Bentley
Got all tests passing with Branch returning 'null:' for null revision
23
    )
5010.2.22 by Vincent Ladeuil
Fix imports in per_branch/test_update.py.
24
from bzrlib.tests import per_branch
1587.1.11 by Robert Collins
Local commits appear to be working properly.
25
26
27
"""Tests for branch.update()"""
28
29
5010.2.22 by Vincent Ladeuil
Fix imports in per_branch/test_update.py.
30
class TestUpdate(per_branch.TestCaseWithBranch):
1587.1.11 by Robert Collins
Local commits appear to be working properly.
31
32
    def test_update_unbound_works(self):
33
        b = self.make_branch('.')
34
        b.update()
2598.5.4 by Aaron Bentley
Restore original Branch.last_revision behavior, fix bits that care
35
        self.assertEqual(_mod_revision.NULL_REVISION,
36
                         _mod_revision.ensure_null(b.last_revision()))
1587.1.11 by Robert Collins
Local commits appear to be working properly.
37
38
    def test_update_prefix_returns_none(self):
39
        # update in a branch when its a prefix of the master should
40
        # indicate that no local changes were present.
41
        master_tree = self.make_branch_and_tree('master')
42
        child_tree = self.make_branch_and_tree('child')
43
        try:
44
            child_tree.branch.bind(master_tree.branch)
45
        except errors.UpgradeRequired:
46
            # old branch, cant test.
47
            return
48
        # commit to the child to make the last rev not-None.
49
        child_tree.commit('foo', rev_id='foo', allow_pointless=True)
50
        # update the master so we can commit there.
51
        master_tree.update()
52
        # commit to the master making the child tree out of date and a prefix.
53
        master_tree.commit('bar', rev_id='bar', allow_pointless=True)
54
        self.assertEqual(None, child_tree.branch.update())
55
56
    def test_update_local_commits_returns_old_tip(self):
57
        # update in a branch when its not a prefix of the master should
58
        # return the previous tip and reset the revision history.
59
        master_tree = self.make_branch_and_tree('master')
60
        child_tree = self.make_branch_and_tree('child')
61
        try:
62
            child_tree.branch.bind(master_tree.branch)
63
        except errors.UpgradeRequired:
64
            # old branch, cant test.
65
            return
66
        # commit to the child to make the last rev not-None and skew it from master.
67
        child_tree.commit('foo', rev_id='foo', allow_pointless=True, local=True)
68
        # commit to the master making the child tree out of date and not a prefix.
69
        master_tree.commit('bar', rev_id='bar', allow_pointless=True)
70
        self.assertEqual('foo', child_tree.branch.update())
6165.4.4 by Jelmer Vernooij
Avoid .revision_history().
71
        self.assertEqual('bar', child_tree.branch.last_revision())
3445.1.5 by John Arbash Meinel
allow passing a 'graph' object into Branch.update_revisions.
72
5582.5.1 by John Arbash Meinel
Fix bug 701212. Don't set the tags for a master branch during update.
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())