bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
4634.122.4
by John Arbash Meinel
Add a test which exposes the bug in revert. |
1 |
# Copyright (C) 2006, 2007, 2009, 2010 Canonical Ltd
|
|
1551.8.15
by Aaron Bentley
bug #54172: handle new directories properly in revert |
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
|
|
1551.8.15
by Aaron Bentley
bug #54172: handle new directories properly in revert |
16 |
|
|
2499.1.1
by Aaron Bentley
Revert does not try to preserve file contents produced by revert |
17 |
import os |
|
1551.8.15
by Aaron Bentley
bug #54172: handle new directories properly in revert |
18 |
|
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
19 |
from breezy import merge, tests, transform, workingtree |
|
1551.8.15
by Aaron Bentley
bug #54172: handle new directories properly in revert |
20 |
|
21 |
||
22 |
class TestRevert(tests.TestCaseWithTransport): |
|
23 |
"""Ensure that revert behaves as expected""" |
|
24 |
||
25 |
def test_revert_merged_dir(self): |
|
26 |
"""Reverting a merge that adds a directory deletes the directory""" |
|
27 |
source_tree = self.make_branch_and_tree('source') |
|
28 |
source_tree.commit('empty tree') |
|
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
29 |
target_tree = source_tree.controldir.sprout( |
30 |
'target').open_workingtree() |
|
|
1551.8.15
by Aaron Bentley
bug #54172: handle new directories properly in revert |
31 |
self.build_tree(['source/dir/', 'source/dir/contents']) |
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
32 |
source_tree.add(['dir', 'dir/contents'], [b'dir-id', b'contents-id']) |
|
1551.8.15
by Aaron Bentley
bug #54172: handle new directories properly in revert |
33 |
source_tree.commit('added dir') |
|
3146.4.6
by Aaron Bentley
Fix locking issues in revert tests |
34 |
target_tree.lock_write() |
35 |
self.addCleanup(target_tree.unlock) |
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
36 |
merge.merge_inner(target_tree.branch, source_tree.basis_tree(), |
|
1551.8.15
by Aaron Bentley
bug #54172: handle new directories properly in revert |
37 |
target_tree.basis_tree(), this_tree=target_tree) |
|
5784.1.3
by Martin Pool
Switch away from using failUnlessExists and failIfExists |
38 |
self.assertPathExists('target/dir') |
39 |
self.assertPathExists('target/dir/contents') |
|
|
2748.3.2
by Aaron Bentley
Fix revert, remove-tree, and various tests to use None for 'no files specified' |
40 |
target_tree.revert() |
|
5784.1.3
by Martin Pool
Switch away from using failUnlessExists and failIfExists |
41 |
self.assertPathDoesNotExist('target/dir/contents') |
42 |
self.assertPathDoesNotExist('target/dir') |
|
|
1551.8.32
by Aaron Bentley
Fix iteraction of revert and files not present in target_tree |
43 |
|
44 |
def test_revert_new(self): |
|
45 |
"""Only locally-changed new files should be preserved when reverting |
|
46 |
||
47 |
When a file isn't present in revert's target tree:
|
|
48 |
If a file hasn't been committed, revert should unversion it, but not
|
|
49 |
delete it.
|
|
50 |
If a file has local changes, revert should unversion it, but not
|
|
51 |
delete it.
|
|
52 |
If a file has no changes from the last commit, revert should delete it.
|
|
53 |
If a file has changes due to a merge, revert should delete it.
|
|
54 |
"""
|
|
55 |
tree = self.make_branch_and_tree('tree') |
|
56 |
tree.commit('empty tree') |
|
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
57 |
merge_target = tree.controldir.sprout( |
58 |
'merge_target').open_workingtree() |
|
|
1551.8.32
by Aaron Bentley
Fix iteraction of revert and files not present in target_tree |
59 |
self.build_tree(['tree/new_file']) |
|
1551.8.33
by Aaron Bentley
Changes from review |
60 |
|
61 |
# newly-added files should not be deleted
|
|
|
1551.8.32
by Aaron Bentley
Fix iteraction of revert and files not present in target_tree |
62 |
tree.add('new_file') |
|
2255.7.37
by Robert Collins
Dont use a basis tree that is not in the tree's parents for revert testing - its not guaranteed usable. |
63 |
basis_tree = tree.branch.repository.revision_tree(tree.last_revision()) |
|
2748.3.2
by Aaron Bentley
Fix revert, remove-tree, and various tests to use None for 'no files specified' |
64 |
tree.revert() |
|
5784.1.3
by Martin Pool
Switch away from using failUnlessExists and failIfExists |
65 |
self.assertPathExists('tree/new_file') |
|
1551.8.33
by Aaron Bentley
Changes from review |
66 |
|
67 |
# unchanged files should be deleted
|
|
|
1551.8.32
by Aaron Bentley
Fix iteraction of revert and files not present in target_tree |
68 |
tree.add('new_file') |
69 |
tree.commit('add new_file') |
|
|
2748.3.2
by Aaron Bentley
Fix revert, remove-tree, and various tests to use None for 'no files specified' |
70 |
tree.revert(old_tree=basis_tree) |
|
5784.1.3
by Martin Pool
Switch away from using failUnlessExists and failIfExists |
71 |
self.assertPathDoesNotExist('tree/new_file') |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
72 |
|
|
1551.8.33
by Aaron Bentley
Changes from review |
73 |
# files should be deleted if their changes came from merges
|
|
1551.8.32
by Aaron Bentley
Fix iteraction of revert and files not present in target_tree |
74 |
merge_target.merge_from_branch(tree.branch) |
|
5784.1.3
by Martin Pool
Switch away from using failUnlessExists and failIfExists |
75 |
self.assertPathExists('merge_target/new_file') |
|
2748.3.2
by Aaron Bentley
Fix revert, remove-tree, and various tests to use None for 'no files specified' |
76 |
merge_target.revert() |
|
5784.1.3
by Martin Pool
Switch away from using failUnlessExists and failIfExists |
77 |
self.assertPathDoesNotExist('merge_target/new_file') |
|
1551.8.33
by Aaron Bentley
Changes from review |
78 |
|
79 |
# files should not be deleted if changed after a merge
|
|
|
1551.8.32
by Aaron Bentley
Fix iteraction of revert and files not present in target_tree |
80 |
merge_target.merge_from_branch(tree.branch) |
|
5784.1.3
by Martin Pool
Switch away from using failUnlessExists and failIfExists |
81 |
self.assertPathExists('merge_target/new_file') |
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
82 |
self.build_tree_contents([('merge_target/new_file', b'new_contents')]) |
|
2748.3.2
by Aaron Bentley
Fix revert, remove-tree, and various tests to use None for 'no files specified' |
83 |
merge_target.revert() |
|
5784.1.3
by Martin Pool
Switch away from using failUnlessExists and failIfExists |
84 |
self.assertPathExists('merge_target/new_file') |
|
1551.9.10
by Aaron Bentley
Fix bugs in execute bit handling by revert |
85 |
|
86 |
def tree_with_executable(self): |
|
87 |
tree = self.make_branch_and_tree('tree') |
|
|
7490.77.2
by Jelmer Vernooij
Split out git and bzr-specific transforms. |
88 |
tt = tree.transform() |
|
6973.13.2
by Jelmer Vernooij
Fix some more tests. |
89 |
tt.new_file('newfile', tt.root, [b'helooo!'], b'newfile-id', True) |
|
1551.9.10
by Aaron Bentley
Fix bugs in execute bit handling by revert |
90 |
tt.apply() |
|
7027.3.3
by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents. |
91 |
with tree.lock_write(): |
|
6809.4.4
by Jelmer Vernooij
Swap arguments for Tree.is_executable. |
92 |
self.assertTrue(tree.is_executable('newfile')) |
|
3146.4.6
by Aaron Bentley
Fix locking issues in revert tests |
93 |
tree.commit('added newfile') |
|
1551.9.10
by Aaron Bentley
Fix bugs in execute bit handling by revert |
94 |
return tree |
95 |
||
96 |
def test_preserve_execute(self): |
|
97 |
tree = self.tree_with_executable() |
|
|
7490.77.2
by Jelmer Vernooij
Split out git and bzr-specific transforms. |
98 |
tt = tree.transform() |
|
6885.1.1
by Jelmer Vernooij
Get rid of TreeTransform.trans_id_tree_file_id. |
99 |
newfile = tt.trans_id_tree_path('newfile') |
|
1551.9.10
by Aaron Bentley
Fix bugs in execute bit handling by revert |
100 |
tt.delete_contents(newfile) |
|
7027.3.3
by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents. |
101 |
tt.create_file([b'Woooorld!'], newfile) |
|
1551.9.10
by Aaron Bentley
Fix bugs in execute bit handling by revert |
102 |
tt.apply() |
103 |
tree = workingtree.WorkingTree.open('tree') |
|
|
3146.4.6
by Aaron Bentley
Fix locking issues in revert tests |
104 |
tree.lock_write() |
105 |
self.addCleanup(tree.unlock) |
|
|
6809.4.4
by Jelmer Vernooij
Swap arguments for Tree.is_executable. |
106 |
self.assertTrue(tree.is_executable('newfile')) |
|
2748.3.2
by Aaron Bentley
Fix revert, remove-tree, and various tests to use None for 'no files specified' |
107 |
transform.revert(tree, tree.basis_tree(), None, backups=True) |
|
7058.4.17
by Jelmer Vernooij
Fix test_revert. |
108 |
with tree.get_file('newfile', 'rb') as f: |
109 |
self.assertEqual(b'helooo!', f.read()) |
|
|
6809.4.4
by Jelmer Vernooij
Swap arguments for Tree.is_executable. |
110 |
self.assertTrue(tree.is_executable('newfile')) |
|
1551.9.10
by Aaron Bentley
Fix bugs in execute bit handling by revert |
111 |
|
112 |
def test_revert_executable(self): |
|
113 |
tree = self.tree_with_executable() |
|
|
7490.77.2
by Jelmer Vernooij
Split out git and bzr-specific transforms. |
114 |
tt = tree.transform() |
|
6885.1.1
by Jelmer Vernooij
Get rid of TreeTransform.trans_id_tree_file_id. |
115 |
newfile = tt.trans_id_tree_path('newfile') |
|
1551.9.10
by Aaron Bentley
Fix bugs in execute bit handling by revert |
116 |
tt.set_executability(False, newfile) |
117 |
tt.apply() |
|
|
3146.4.6
by Aaron Bentley
Fix locking issues in revert tests |
118 |
tree.lock_write() |
119 |
self.addCleanup(tree.unlock) |
|
|
2748.3.2
by Aaron Bentley
Fix revert, remove-tree, and various tests to use None for 'no files specified' |
120 |
transform.revert(tree, tree.basis_tree(), None) |
|
6809.4.4
by Jelmer Vernooij
Swap arguments for Tree.is_executable. |
121 |
self.assertTrue(tree.is_executable('newfile')) |
|
2499.1.1
by Aaron Bentley
Revert does not try to preserve file contents produced by revert |
122 |
|
123 |
def test_revert_deletes_files_from_revert(self): |
|
124 |
tree = self.make_branch_and_tree('.') |
|
125 |
self.build_tree(['file']) |
|
126 |
tree.add('file') |
|
|
7350.4.3
by Jelmer Vernooij
Fix tests. |
127 |
rev1 = tree.commit('added file') |
128 |
with tree.lock_read(): |
|
129 |
file_sha = tree.get_file_sha1('file') |
|
|
2499.1.1
by Aaron Bentley
Revert does not try to preserve file contents produced by revert |
130 |
os.unlink('file') |
131 |
tree.commit('removed file') |
|
|
5784.1.3
by Martin Pool
Switch away from using failUnlessExists and failIfExists |
132 |
self.assertPathDoesNotExist('file') |
|
7350.4.3
by Jelmer Vernooij
Fix tests. |
133 |
tree.revert(old_tree=tree.branch.repository.revision_tree(rev1)) |
134 |
self.assertEqual({'file': file_sha}, tree.merge_modified()) |
|
|
5784.1.3
by Martin Pool
Switch away from using failUnlessExists and failIfExists |
135 |
self.assertPathExists('file') |
|
2748.3.2
by Aaron Bentley
Fix revert, remove-tree, and various tests to use None for 'no files specified' |
136 |
tree.revert() |
|
5784.1.3
by Martin Pool
Switch away from using failUnlessExists and failIfExists |
137 |
self.assertPathDoesNotExist('file') |
|
2499.1.1
by Aaron Bentley
Revert does not try to preserve file contents produced by revert |
138 |
self.assertEqual({}, tree.merge_modified()) |
|
2748.3.3
by Aaron Bentley
Add a deprecation warning for revert([]), and handle as revert(None) for now |
139 |
|
|
1551.19.4
by Aaron Bentley
Add failing test case |
140 |
def test_revert_file_in_deleted_dir(self): |
141 |
tree = self.make_branch_and_tree('.') |
|
|
1551.19.9
by Aaron Bentley
Update from review |
142 |
self.build_tree(['dir/', 'dir/file1', 'dir/file2']) |
143 |
tree.add(['dir', 'dir/file1', 'dir/file2'], |
|
|
7027.3.3
by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents. |
144 |
[b'dir-id', b'file1-id', b'file2-id']) |
|
1551.19.9
by Aaron Bentley
Update from review |
145 |
tree.commit("Added files") |
146 |
os.unlink('dir/file1') |
|
147 |
os.unlink('dir/file2') |
|
|
1551.19.4
by Aaron Bentley
Add failing test case |
148 |
os.rmdir('dir') |
|
1551.19.9
by Aaron Bentley
Update from review |
149 |
tree.remove(['dir/', 'dir/file1', 'dir/file2']) |
150 |
tree.revert(['dir/file1']) |
|
|
5784.1.3
by Martin Pool
Switch away from using failUnlessExists and failIfExists |
151 |
self.assertPathExists('dir/file1') |
152 |
self.assertPathDoesNotExist('dir/file2') |
|
|
6973.13.2
by Jelmer Vernooij
Fix some more tests. |
153 |
self.assertEqual(b'dir-id', tree.path2id('dir')) |
|
4634.122.4
by John Arbash Meinel
Add a test which exposes the bug in revert. |
154 |
|
155 |
def test_revert_root_id_change(self): |
|
156 |
tree = self.make_branch_and_tree('.') |
|
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
157 |
tree.set_root_id(b'initial-root-id') |
|
4634.122.4
by John Arbash Meinel
Add a test which exposes the bug in revert. |
158 |
self.build_tree(['file1']) |
159 |
tree.add(['file1']) |
|
160 |
tree.commit('first') |
|
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
161 |
tree.set_root_id(b'temp-root-id') |
|
7358.14.1
by Jelmer Vernooij
Remove Tree.get_root_id() in favour of Tree.path2id(''). |
162 |
self.assertEqual(b'temp-root-id', tree.path2id('')) |
|
4634.122.4
by John Arbash Meinel
Add a test which exposes the bug in revert. |
163 |
tree.revert() |
|
7358.14.1
by Jelmer Vernooij
Remove Tree.get_root_id() in favour of Tree.path2id(''). |
164 |
self.assertEqual(b'initial-root-id', tree.path2id('')) |