~bzr-pqm/bzr/bzr.dev

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Copyright (C) 2009 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

from bzrlib import (
    errors,
    )
from bzrlib.tests.per_interbranch import (
    TestCaseWithInterBranch,
    )


class TestUpdateRevisions(TestCaseWithInterBranch):

    def setUp(self):
        super(TestUpdateRevisions, self).setUp()
        self.tree1 = self.make_branch_and_tree('tree1')
        rev1 = self.tree1.commit('one')
        dir2 = self.make_to_bzrdir('tree2')
        dir2.create_repository().fetch(self.tree1.branch.repository)
        branch2 = self.tree1.branch.sprout(dir2)
        self.tree2 = dir2.create_workingtree()

    def test_accepts_graph(self):
        # An implementation may not use it, but it should allow a 'graph' to be
        # supplied
        rev2 = self.tree2.commit('two')

        self.tree1.lock_write()
        self.addCleanup(self.tree1.unlock)
        self.tree2.lock_read()
        self.addCleanup(self.tree2.unlock)
        graph = self.tree2.branch.repository.get_graph(
            self.tree1.branch.repository)

        self.tree1.branch.update_revisions(self.tree2.branch, graph=graph)
        self.assertEqual((2, rev2), self.tree1.branch.last_revision_info())

    def test_overwrite_ignores_diverged(self):
        rev2 = self.tree1.commit('two')
        rev2b = self.tree2.commit('alt two')

        self.assertRaises(errors.DivergedBranches,
                          self.tree1.branch.update_revisions,
                          self.tree2.branch, overwrite=False)
        # However, the revision should be copied into the repository
        self.assertTrue(self.tree1.branch.repository.has_revision(rev2b))

        self.tree1.branch.update_revisions(self.tree2.branch, overwrite=True)
        self.assertEqual((2, rev2b), self.tree1.branch.last_revision_info())

    def test_ignores_older_unless_overwrite(self):
        rev2 = self.tree1.commit('two')

        self.tree1.branch.update_revisions(self.tree2.branch)
        self.assertEqual((2, rev2), self.tree1.branch.last_revision_info())

        self.tree1.branch.update_revisions(self.tree2.branch, overwrite=True)