5557.1.15
by John Arbash Meinel
Merge bzr.dev 5597 to resolve NEWS, aka bzr-2.3.txt |
1 |
# Copyright (C) 2006-2009, 2011 Canonical Ltd
|
1731.2.1
by Aaron Bentley
Initial subsume implementation |
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
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
1731.2.1
by Aaron Bentley
Initial subsume implementation |
16 |
|
5579.3.1
by Jelmer Vernooij
Remove unused imports. |
17 |
from bzrlib import errors, workingtree, tests |
1731.2.1
by Aaron Bentley
Initial subsume implementation |
18 |
|
19 |
||
1731.2.4
by Aaron Bentley
Ensure subsume works with Knit2 repos |
20 |
class TestWorkingTree(tests.TestCaseWithTransport): |
21 |
||
22 |
def make_branch_and_tree(self, relpath, format=None): |
|
23 |
if format is None: |
|
2255.2.194
by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests. |
24 |
format = 'dirstate-with-subtree' |
3316.2.3
by Robert Collins
Remove manual notification of transaction finishing on versioned files. |
25 |
return tests.TestCaseWithTransport.make_branch_and_tree(self, relpath, |
2100.3.17
by Aaron Bentley
Remove get_format_*, make FormatRegistry.register_metadir vary working tree |
26 |
format) |
1731.2.4
by Aaron Bentley
Ensure subsume works with Knit2 repos |
27 |
|
1731.2.5
by Aaron Bentley
Ensure versionedfile will be produced for subsumed tree root |
28 |
def make_trees(self, format=None, same_root=False): |
2255.2.194
by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests. |
29 |
self.build_tree(['tree/', |
1731.2.2
by Aaron Bentley
Test subsume failure modes |
30 |
'tree/file', |
31 |
'tree/subtree/', |
|
1731.2.1
by Aaron Bentley
Initial subsume implementation |
32 |
'tree/subtree/file2']) |
1731.2.5
by Aaron Bentley
Ensure versionedfile will be produced for subsumed tree root |
33 |
base_tree = self.make_branch_and_tree('tree', format=format) |
1731.2.1
by Aaron Bentley
Initial subsume implementation |
34 |
base_tree.add('file', 'file-id') |
35 |
base_tree.commit('first commit', rev_id='tree-1') |
|
2255.2.194
by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests. |
36 |
sub_tree = self.make_branch_and_tree('tree/subtree', |
37 |
format='dirstate-with-subtree') |
|
1731.2.5
by Aaron Bentley
Ensure versionedfile will be produced for subsumed tree root |
38 |
if same_root is True: |
39 |
sub_tree.set_root_id(base_tree.get_root_id()) |
|
1731.2.1
by Aaron Bentley
Initial subsume implementation |
40 |
sub_tree.add('file2', 'file2-id') |
41 |
sub_tree.commit('first commit', rev_id='subtree-1') |
|
1731.2.2
by Aaron Bentley
Test subsume failure modes |
42 |
return base_tree, sub_tree |
43 |
||
1731.2.5
by Aaron Bentley
Ensure versionedfile will be produced for subsumed tree root |
44 |
def test_old_knit1_failure(self): |
45 |
"""Ensure that BadSubsumeSource is raised.
|
|
46 |
||
47 |
SubsumeTargetNeedsUpgrade must not be raised, because upgrading the
|
|
48 |
target won't help.
|
|
49 |
"""
|
|
2100.3.17
by Aaron Bentley
Remove get_format_*, make FormatRegistry.register_metadir vary working tree |
50 |
base_tree, sub_tree = self.make_trees(format='knit', |
1731.2.5
by Aaron Bentley
Ensure versionedfile will be produced for subsumed tree root |
51 |
same_root=True) |
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
52 |
self.assertRaises(errors.BadSubsumeSource, base_tree.subsume, |
1731.2.5
by Aaron Bentley
Ensure versionedfile will be produced for subsumed tree root |
53 |
sub_tree) |
54 |
||
55 |
def test_knit1_failure(self): |
|
2100.3.17
by Aaron Bentley
Remove get_format_*, make FormatRegistry.register_metadir vary working tree |
56 |
base_tree, sub_tree = self.make_trees(format='knit') |
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
57 |
self.assertRaises(errors.SubsumeTargetNeedsUpgrade, base_tree.subsume, |
1731.2.5
by Aaron Bentley
Ensure versionedfile will be produced for subsumed tree root |
58 |
sub_tree) |
59 |
||
1731.2.2
by Aaron Bentley
Test subsume failure modes |
60 |
def test_subsume_tree(self): |
61 |
base_tree, sub_tree = self.make_trees() |
|
3376.2.4
by Martin Pool
Remove every assert statement from bzrlib! |
62 |
self.assertNotEqual(base_tree.get_root_id(), sub_tree.get_root_id()) |
1731.2.1
by Aaron Bentley
Initial subsume implementation |
63 |
sub_root_id = sub_tree.get_root_id() |
2255.2.214
by Robert Collins
Get _iter_changes on dirstate passing the subtree tests. |
64 |
# this test checks the subdir is removed, so it needs to know the
|
65 |
# control directory; that changes rarely so just hardcode (and check)
|
|
66 |
# it is correct.
|
|
5784.1.3
by Martin Pool
Switch away from using failUnlessExists and failIfExists |
67 |
self.assertPathExists('tree/subtree/.bzr') |
1731.2.1
by Aaron Bentley
Initial subsume implementation |
68 |
base_tree.subsume(sub_tree) |
69 |
self.assertEqual(['tree-1', 'subtree-1'], base_tree.get_parent_ids()) |
|
70 |
self.assertEqual(sub_root_id, base_tree.path2id('subtree')) |
|
71 |
self.assertEqual('file2-id', base_tree.path2id('subtree/file2')) |
|
2255.14.1
by Martin Pool
Add BzrDir.retire_bzrdir and partly fix subsume |
72 |
# subsuming the tree removes the control directory, so you can't open
|
2255.2.214
by Robert Collins
Get _iter_changes on dirstate passing the subtree tests. |
73 |
# it.
|
5784.1.3
by Martin Pool
Switch away from using failUnlessExists and failIfExists |
74 |
self.assertPathDoesNotExist('tree/subtree/.bzr') |
1731.2.4
by Aaron Bentley
Ensure subsume works with Knit2 repos |
75 |
file2 = open('tree/subtree/file2', 'rb') |
76 |
try: |
|
77 |
file2_contents = file2.read() |
|
78 |
finally: |
|
79 |
file2.close() |
|
1731.2.6
by Aaron Bentley
Ensure subsume data survives reopening the tree |
80 |
base_tree = workingtree.WorkingTree.open('tree') |
1731.2.4
by Aaron Bentley
Ensure subsume works with Knit2 repos |
81 |
base_tree.commit('combined', rev_id='combined-1') |
82 |
self.assertEqual('file2-id', base_tree.path2id('subtree/file2')) |
|
83 |
self.assertEqual('subtree/file2', base_tree.id2path('file2-id')) |
|
2255.2.194
by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests. |
84 |
self.assertEqualDiff(file2_contents, |
1731.2.4
by Aaron Bentley
Ensure subsume works with Knit2 repos |
85 |
base_tree.get_file_text('file2-id')) |
86 |
basis_tree = base_tree.basis_tree() |
|
2255.2.194
by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests. |
87 |
basis_tree.lock_read() |
88 |
self.addCleanup(basis_tree.unlock) |
|
89 |
self.assertEqualDiff(file2_contents, |
|
1731.2.4
by Aaron Bentley
Ensure subsume works with Knit2 repos |
90 |
base_tree.get_file_text('file2-id')) |
2255.2.194
by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests. |
91 |
self.assertEqualDiff(file2_contents, |
1731.2.4
by Aaron Bentley
Ensure subsume works with Knit2 repos |
92 |
basis_tree.get_file_text('file2-id')) |
2255.2.194
by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests. |
93 |
self.assertEqual('subtree-1', |
5793.2.3
by Jelmer Vernooij
Add a RevisionTree.get_file_revision() method. |
94 |
basis_tree.get_file_revision('file2-id')) |
2255.2.194
by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests. |
95 |
self.assertEqual('combined-1', |
5793.2.3
by Jelmer Vernooij
Add a RevisionTree.get_file_revision() method. |
96 |
basis_tree.get_file_revision(sub_root_id)) |
1731.2.2
by Aaron Bentley
Test subsume failure modes |
97 |
|
98 |
def test_subsume_failure(self): |
|
99 |
base_tree, sub_tree = self.make_trees() |
|
100 |
if base_tree.get_root_id() == sub_tree.get_root_id(): |
|
101 |
raise tests.TestSkipped('This test requires unique roots') |
|
102 |
sub_root_id = sub_tree.get_root_id() |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
103 |
self.assertRaises(errors.BadSubsumeSource, base_tree.subsume, |
1731.2.2
by Aaron Bentley
Test subsume failure modes |
104 |
base_tree) |
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
105 |
self.assertRaises(errors.BadSubsumeSource, sub_tree.subsume, |
1731.2.2
by Aaron Bentley
Test subsume failure modes |
106 |
base_tree) |
107 |
self.build_tree(['subtree2/']) |
|
108 |
sub_tree2 = self.make_branch_and_tree('subtree2') |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
109 |
self.assertRaises(errors.BadSubsumeSource, sub_tree.subsume, |
1731.2.2
by Aaron Bentley
Test subsume failure modes |
110 |
sub_tree2) |
1731.2.3
by Aaron Bentley
Handle unversioned parents during subsume |
111 |
self.build_tree(['tree/subtree/subtree3/']) |
112 |
sub_tree3 = self.make_branch_and_tree('tree/subtree/subtree3') |
|
1731.2.5
by Aaron Bentley
Ensure versionedfile will be produced for subsumed tree root |
113 |
self.assertRaises(errors.BadSubsumeSource, base_tree.subsume, |
1731.2.3
by Aaron Bentley
Handle unversioned parents during subsume |
114 |
sub_tree3) |