~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_interbranch/test_update_revisions.py

Merge bzr.dev, update to use new hooks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009, 2010 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
from bzrlib import (
18
 
    errors,
19
 
    )
20
 
from bzrlib.tests.per_interbranch import (
21
 
    TestCaseWithInterBranch,
22
 
    )
23
 
 
24
 
 
25
 
class TestUpdateRevisions(TestCaseWithInterBranch):
26
 
 
27
 
    def setUp(self):
28
 
        super(TestUpdateRevisions, self).setUp()
29
 
        self.tree1 = self.make_from_branch_and_tree('tree1')
30
 
        rev1 = self.tree1.commit('one')
31
 
        branch2 = self.make_to_branch('tree2')
32
 
        branch2.repository.fetch(self.tree1.branch.repository)
33
 
        self.tree1.branch.copy_content_into(branch2)
34
 
        self.tree2 = branch2.bzrdir.create_workingtree()
35
 
 
36
 
    def test_accepts_graph(self):
37
 
        # An implementation may not use it, but it should allow a 'graph' to be
38
 
        # supplied
39
 
        rev2 = self.tree2.commit('two')
40
 
 
41
 
        self.tree1.lock_write()
42
 
        self.addCleanup(self.tree1.unlock)
43
 
        self.tree2.lock_read()
44
 
        self.addCleanup(self.tree2.unlock)
45
 
        graph = self.tree2.branch.repository.get_graph(
46
 
            self.tree1.branch.repository)
47
 
 
48
 
        self.tree1.branch.update_revisions(self.tree2.branch, graph=graph)
49
 
        self.assertEqual((2, rev2), self.tree1.branch.last_revision_info())
50
 
 
51
 
    def test_overwrite_ignores_diverged(self):
52
 
        rev2 = self.tree1.commit('two')
53
 
        rev2b = self.tree2.commit('alt two')
54
 
 
55
 
        self.assertRaises(errors.DivergedBranches,
56
 
                          self.tree1.branch.update_revisions,
57
 
                          self.tree2.branch, overwrite=False)
58
 
        # However, the revision should be copied into the repository
59
 
        self.assertTrue(self.tree1.branch.repository.has_revision(rev2b))
60
 
 
61
 
        self.tree1.branch.update_revisions(self.tree2.branch, overwrite=True)
62
 
        self.assertEqual((2, rev2b), self.tree1.branch.last_revision_info())
63
 
 
64
 
    def test_ignores_older_unless_overwrite(self):
65
 
        rev2 = self.tree1.commit('two')
66
 
 
67
 
        self.tree1.branch.update_revisions(self.tree2.branch)
68
 
        self.assertEqual((2, rev2), self.tree1.branch.last_revision_info())
69
 
 
70
 
        self.tree1.branch.update_revisions(self.tree2.branch, overwrite=True)