4000.5.3
by Jelmer Vernooij
Add tests for InterBranch. |
1 |
# Copyright (C) 2009 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 |
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_branch_and_tree('tree1') |
|
30 |
rev1 = self.tree1.commit('one') |
|
31 |
dir2 = self.make_to_bzrdir('tree2') |
|
4000.5.4
by Jelmer Vernooij
Fix tests. |
32 |
dir2.create_repository().fetch(self.tree1.branch.repository) |
33 |
branch2 = self.tree1.branch.sprout(dir2) |
|
4000.5.3
by Jelmer Vernooij
Add tests for InterBranch. |
34 |
self.tree2 = dir2.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) |