~bzr-pqm/bzr/bzr.dev

1587.1.11 by Robert Collins
Local commits appear to be working properly.
1
# Copyright (C) 2006 by 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
18
import bzrlib.errors as errors
19
from bzrlib.tests.branch_implementations.test_branch import TestCaseWithBranch
20
21
22
"""Tests for branch.update()"""
23
24
25
class TestUpdate(TestCaseWithBranch):
26
27
    def test_update_unbound_works(self):
28
        b = self.make_branch('.')
29
        b.update()
30
        self.assertEqual(None, b.last_revision())
31
32
    def test_update_prefix_returns_none(self):
33
        # update in a branch when its a prefix of the master should
34
        # indicate that no local changes were present.
35
        master_tree = self.make_branch_and_tree('master')
36
        child_tree = self.make_branch_and_tree('child')
37
        try:
38
            child_tree.branch.bind(master_tree.branch)
39
        except errors.UpgradeRequired:
40
            # old branch, cant test.
41
            return
42
        # commit to the child to make the last rev not-None.
43
        child_tree.commit('foo', rev_id='foo', allow_pointless=True)
44
        # update the master so we can commit there.
45
        master_tree.update()
46
        # commit to the master making the child tree out of date and a prefix.
47
        master_tree.commit('bar', rev_id='bar', allow_pointless=True)
48
        self.assertEqual(None, child_tree.branch.update())
49
50
    def test_update_local_commits_returns_old_tip(self):
51
        # update in a branch when its not a prefix of the master should
52
        # return the previous tip and reset the revision history.
53
        master_tree = self.make_branch_and_tree('master')
54
        child_tree = self.make_branch_and_tree('child')
55
        try:
56
            child_tree.branch.bind(master_tree.branch)
57
        except errors.UpgradeRequired:
58
            # old branch, cant test.
59
            return
60
        # commit to the child to make the last rev not-None and skew it from master.
61
        child_tree.commit('foo', rev_id='foo', allow_pointless=True, local=True)
62
        # commit to the master making the child tree out of date and not a prefix.
63
        master_tree.commit('bar', rev_id='bar', allow_pointless=True)
64
        self.assertEqual('foo', child_tree.branch.update())
65
        self.assertEqual(['bar'], child_tree.branch.revision_history())