1773.4.1
by Martin Pool
Add pyflakes makefile target; fix many warnings |
1 |
# Copyright (C) 2005, 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 |
||
1185.1.41
by Robert Collins
massive patch from Alexander Belchenko - many PEP8 fixes, removes unused function uuid |
17 |
import os |
1551.2.23
by Aaron Bentley
Got merge_inner's ignore_zero parameter working |
18 |
from StringIO import StringIO |
1185.1.41
by Robert Collins
massive patch from Alexander Belchenko - many PEP8 fixes, removes unused function uuid |
19 |
|
974.1.56
by aaron.bentley at utoronto
Added merge test |
20 |
from bzrlib.branch import Branch |
1534.4.28
by Robert Collins
first cut at merge from integration. |
21 |
from bzrlib.builtins import merge |
1551.7.10
by Aaron Bentley
Remerge doesn't clear unrelated conflicts |
22 |
from bzrlib.conflicts import ConflictList, TextConflict |
1185.24.3
by Aaron Bentley
Integrated reprocessing into the rest of the merge stuff |
23 |
from bzrlib.errors import UnrelatedBranches, NoCommits, BzrCommandError |
1551.2.23
by Aaron Bentley
Got merge_inner's ignore_zero parameter working |
24 |
from bzrlib.merge import transform_tree, merge_inner |
1185.31.32
by John Arbash Meinel
Updated the bzr sourcecode to use bzrlib.osutils.pathjoin rather than os.path.join to enforce internal use of / instead of \ |
25 |
from bzrlib.osutils import pathjoin |
1534.4.28
by Robert Collins
first cut at merge from integration. |
26 |
from bzrlib.revision import common_ancestor |
27 |
from bzrlib.tests import TestCaseWithTransport |
|
1551.2.23
by Aaron Bentley
Got merge_inner's ignore_zero parameter working |
28 |
from bzrlib.trace import (enable_test_log, disable_test_log) |
1534.4.26
by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create. |
29 |
from bzrlib.workingtree import WorkingTree |
30 |
||
31 |
||
32 |
class TestMerge(TestCaseWithTransport): |
|
974.1.56
by aaron.bentley at utoronto
Added merge test |
33 |
"""Test appending more than one revision"""
|
1534.4.26
by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create. |
34 |
|
974.1.56
by aaron.bentley at utoronto
Added merge test |
35 |
def test_pending(self): |
1534.4.26
by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create. |
36 |
wt = self.make_branch_and_tree('.') |
37 |
wt.commit("lala!") |
|
38 |
self.assertEquals(len(wt.pending_merges()), 0) |
|
1185.33.66
by Martin Pool
[patch] use unicode literals for all hardcoded paths (Alexander Belchenko) |
39 |
merge([u'.', -1], [None, None]) |
1534.4.26
by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create. |
40 |
self.assertEquals(len(wt.pending_merges()), 0) |
974.1.80
by Aaron Bentley
Improved merge error handling and testing |
41 |
|
1558.4.11
by Aaron Bentley
Allow merge against self, make fetching self a noop |
42 |
def test_undo(self): |
43 |
wt = self.make_branch_and_tree('.') |
|
44 |
wt.commit("lala!") |
|
45 |
wt.commit("haha!") |
|
46 |
wt.commit("blabla!") |
|
47 |
merge([u'.', 2], [u'.', 1]) |
|
48 |
||
974.1.80
by Aaron Bentley
Improved merge error handling and testing |
49 |
def test_nocommits(self): |
50 |
self.test_pending() |
|
1534.4.26
by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create. |
51 |
wt2 = self.make_branch_and_tree('branch2') |
974.1.80
by Aaron Bentley
Improved merge error handling and testing |
52 |
self.assertRaises(NoCommits, merge, ['branch2', -1], |
53 |
[None, None]) |
|
1534.4.26
by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create. |
54 |
return wt2 |
974.1.80
by Aaron Bentley
Improved merge error handling and testing |
55 |
|
56 |
def test_unrelated(self): |
|
1534.4.26
by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create. |
57 |
wt2 = self.test_nocommits() |
58 |
wt2.commit("blah") |
|
974.1.80
by Aaron Bentley
Improved merge error handling and testing |
59 |
self.assertRaises(UnrelatedBranches, merge, ['branch2', -1], |
60 |
[None, None]) |
|
1534.4.26
by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create. |
61 |
return wt2 |
974.1.80
by Aaron Bentley
Improved merge error handling and testing |
62 |
|
1645.1.1
by Aaron Bentley
Implement single-file merge |
63 |
def test_merge_one(self): |
64 |
wt1 = self.make_branch_and_tree('branch1') |
|
65 |
wt1.commit('empty commit') |
|
66 |
wt2 = self.make_branch_and_tree('branch2') |
|
67 |
wt2.pull(wt1.branch) |
|
68 |
file('branch1/foo', 'wb').write('foo') |
|
69 |
file('branch1/bar', 'wb').write('bar') |
|
70 |
wt1.add('foo') |
|
71 |
wt1.add('bar') |
|
72 |
wt1.commit('add foobar') |
|
73 |
os.chdir('branch2') |
|
74 |
self.run_bzr('merge', '../branch1/baz', retcode=3) |
|
75 |
self.run_bzr('merge', '../branch1/foo') |
|
76 |
self.failUnlessExists('foo') |
|
77 |
self.failIfExists('bar') |
|
78 |
wt2 = WorkingTree.open_containing('branch2')[0] |
|
79 |
self.assertEqual(wt2.pending_merges(), []) |
|
80 |
||
974.1.88
by Aaron Bentley
Set a pending_merge if the merge base is forced to revno 0 |
81 |
def test_pending_with_null(self): |
82 |
"""When base is forced to revno 0, pending_merges is set"""
|
|
1534.4.26
by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create. |
83 |
wt2 = self.test_unrelated() |
1508.1.19
by Robert Collins
Give format3 working trees their own last-revision marker. |
84 |
wt1 = WorkingTree.open('.') |
1534.4.26
by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create. |
85 |
br1 = wt1.branch |
1534.1.31
by Robert Collins
Deprecated fetch.fetch and fetch.greedy_fetch for branch.fetch, and move the Repository.fetch internals to InterRepo and InterWeaveRepo. |
86 |
br1.fetch(wt2.branch) |
1390
by Robert Collins
pair programming worx... merge integration and weave |
87 |
# merge all of branch 2 into branch 1 even though they
|
88 |
# are not related.
|
|
1185.24.3
by Aaron Bentley
Integrated reprocessing into the rest of the merge stuff |
89 |
self.assertRaises(BzrCommandError, merge, ['branch2', -1], |
90 |
['branch2', 0], reprocess=True, show_base=True) |
|
91 |
merge(['branch2', -1], ['branch2', 0], reprocess=True) |
|
1534.4.26
by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create. |
92 |
self.assertEquals(len(wt1.pending_merges()), 1) |
93 |
return (wt1, wt2.branch) |
|
974.1.89
by Aaron Bentley
Fixed merging with multiple roots, by using null as graph root. |
94 |
|
95 |
def test_two_roots(self): |
|
96 |
"""Merge base is sane when two unrelated branches are merged"""
|
|
1534.4.26
by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create. |
97 |
wt1, br2 = self.test_pending_with_null() |
98 |
wt1.commit("blah") |
|
99 |
last = wt1.branch.last_revision() |
|
1534.4.28
by Robert Collins
first cut at merge from integration. |
100 |
self.assertEquals(common_ancestor(last, last, wt1.branch.repository), last) |
1185.46.1
by Aaron Bentley
Test case when file to be renamed is also deleted |
101 |
|
102 |
def test_create_rename(self): |
|
103 |
"""Rename an inventory entry while creating the file"""
|
|
1534.4.26
by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create. |
104 |
tree =self.make_branch_and_tree('.') |
1185.46.1
by Aaron Bentley
Test case when file to be renamed is also deleted |
105 |
file('name1', 'wb').write('Hello') |
106 |
tree.add('name1') |
|
107 |
tree.commit(message="hello") |
|
108 |
tree.rename_one('name1', 'name2') |
|
109 |
os.unlink('name2') |
|
1534.4.26
by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create. |
110 |
transform_tree(tree, tree.branch.basis_tree()) |
1185.46.2
by Aaron Bentley
Added test for renaming both parent and child |
111 |
|
112 |
def test_layered_rename(self): |
|
113 |
"""Rename both child and parent at same time"""
|
|
1534.4.26
by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create. |
114 |
tree =self.make_branch_and_tree('.') |
1185.46.2
by Aaron Bentley
Added test for renaming both parent and child |
115 |
os.mkdir('dirname1') |
116 |
tree.add('dirname1') |
|
1185.31.32
by John Arbash Meinel
Updated the bzr sourcecode to use bzrlib.osutils.pathjoin rather than os.path.join to enforce internal use of / instead of \ |
117 |
filename = pathjoin('dirname1', 'name1') |
1185.46.2
by Aaron Bentley
Added test for renaming both parent and child |
118 |
file(filename, 'wb').write('Hello') |
119 |
tree.add(filename) |
|
120 |
tree.commit(message="hello") |
|
1185.31.32
by John Arbash Meinel
Updated the bzr sourcecode to use bzrlib.osutils.pathjoin rather than os.path.join to enforce internal use of / instead of \ |
121 |
filename2 = pathjoin('dirname1', 'name2') |
1185.46.2
by Aaron Bentley
Added test for renaming both parent and child |
122 |
tree.rename_one(filename, filename2) |
123 |
tree.rename_one('dirname1', 'dirname2') |
|
1534.4.26
by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create. |
124 |
transform_tree(tree, tree.branch.basis_tree()) |
1551.2.23
by Aaron Bentley
Got merge_inner's ignore_zero parameter working |
125 |
|
126 |
def test_ignore_zero_merge_inner(self): |
|
127 |
# Test that merge_inner's ignore zero paramter is effective
|
|
128 |
tree_a =self.make_branch_and_tree('a') |
|
129 |
tree_a.commit(message="hello") |
|
130 |
dir_b = tree_a.bzrdir.sprout('b') |
|
131 |
tree_b = dir_b.open_workingtree() |
|
132 |
tree_a.commit(message="hello again") |
|
133 |
log = StringIO() |
|
134 |
merge_inner(tree_b.branch, tree_a, tree_b.basis_tree(), |
|
135 |
this_tree=tree_b, ignore_zero=True) |
|
1551.4.1
by Aaron Bentley
Workaround for silly _get_log behaviour in test |
136 |
log = self._get_log() |
137 |
self.failUnless('All changes applied successfully.\n' not in log) |
|
1551.2.23
by Aaron Bentley
Got merge_inner's ignore_zero parameter working |
138 |
tree_b.revert([]) |
139 |
merge_inner(tree_b.branch, tree_a, tree_b.basis_tree(), |
|
140 |
this_tree=tree_b, ignore_zero=False) |
|
1551.4.1
by Aaron Bentley
Workaround for silly _get_log behaviour in test |
141 |
log = self._get_log() |
142 |
self.failUnless('All changes applied successfully.\n' in log) |
|
1551.7.10
by Aaron Bentley
Remerge doesn't clear unrelated conflicts |
143 |
|
144 |
def test_merge_inner_conflicts(self): |
|
145 |
tree_a = self.make_branch_and_tree('a') |
|
146 |
tree_a.set_conflicts(ConflictList([TextConflict('patha')])) |
|
1551.7.11
by Aaron Bentley
Add WorkingTree.add_conflicts |
147 |
merge_inner(tree_a.branch, tree_a, tree_a, this_tree=tree_a) |
1551.7.13
by Aaron Bentley
Switched from actual, expected to expected, actual, for John. |
148 |
self.assertEqual(1, len(tree_a.conflicts())) |