2851.2.1
by Martin Pool
Add revert --forget-merges |
1 |
# Copyright (C) 2005, 2007 Canonical Ltd
|
1185.50.53
by John Arbash Meinel
[patch] Aaron Bentley: make revert work in a subdirectory. |
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
|
1185.50.53
by John Arbash Meinel
[patch] Aaron Bentley: make revert work in a subdirectory. |
16 |
|
17 |
"""Black-box tests for bzr revert."""
|
|
18 |
||
19 |
import os |
|
20 |
||
1711.4.24
by John Arbash Meinel
move the revert tests out of test_too_much.py |
21 |
import bzrlib.osutils |
1185.50.53
by John Arbash Meinel
[patch] Aaron Bentley: make revert work in a subdirectory. |
22 |
from bzrlib.tests.blackbox import ExternalBase |
23 |
from bzrlib.trace import mutter |
|
1551.7.9
by Aaron Bentley
Update for review comments |
24 |
from bzrlib.workingtree import WorkingTree |
1185.50.53
by John Arbash Meinel
[patch] Aaron Bentley: make revert work in a subdirectory. |
25 |
|
26 |
||
27 |
class TestRevert(ExternalBase): |
|
28 |
||
29 |
def _prepare_tree(self): |
|
2530.3.1
by Martin Pool
Cleanup old variations on run_bzr in the test suite |
30 |
self.run_bzr('init') |
31 |
self.run_bzr('mkdir dir') |
|
1185.50.53
by John Arbash Meinel
[patch] Aaron Bentley: make revert work in a subdirectory. |
32 |
|
33 |
f = file('dir/file', 'wb') |
|
34 |
f.write('spam') |
|
35 |
f.close() |
|
2530.3.1
by Martin Pool
Cleanup old variations on run_bzr in the test suite |
36 |
self.run_bzr('add dir/file') |
1185.50.53
by John Arbash Meinel
[patch] Aaron Bentley: make revert work in a subdirectory. |
37 |
|
2530.3.1
by Martin Pool
Cleanup old variations on run_bzr in the test suite |
38 |
self.run_bzr('commit -m1') |
1185.50.53
by John Arbash Meinel
[patch] Aaron Bentley: make revert work in a subdirectory. |
39 |
|
40 |
# modify file
|
|
41 |
f = file('dir/file', 'wb') |
|
42 |
f.write('eggs') |
|
43 |
f.close() |
|
44 |
||
45 |
# check status
|
|
2552.2.2
by Vincent Ladeuil
Enforce run_bzr(string) where possible. |
46 |
self.assertEquals('modified:\n dir/file\n', self.run_bzr('status')[0]) |
1185.50.53
by John Arbash Meinel
[patch] Aaron Bentley: make revert work in a subdirectory. |
47 |
|
1551.7.7
by Aaron Bentley
Handle revert DIRECTORY |
48 |
def _prepare_rename_mod_tree(self): |
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
49 |
self.build_tree(['a/', 'a/b', 'a/c', 'a/d/', 'a/d/e', 'f/', 'f/g', |
1551.7.7
by Aaron Bentley
Handle revert DIRECTORY |
50 |
'f/h', 'f/i']) |
51 |
self.run_bzr('init') |
|
52 |
self.run_bzr('add') |
|
2552.2.3
by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests. |
53 |
self.run_bzr('commit -m 1') |
1551.7.7
by Aaron Bentley
Handle revert DIRECTORY |
54 |
wt = WorkingTree.open('.') |
55 |
wt.rename_one('a/b', 'f/b') |
|
1551.7.9
by Aaron Bentley
Update for review comments |
56 |
wt.rename_one('a/d/e', 'f/e') |
1551.7.7
by Aaron Bentley
Handle revert DIRECTORY |
57 |
wt.rename_one('a/d', 'f/d') |
58 |
wt.rename_one('f/g', 'a/g') |
|
59 |
wt.rename_one('f/h', 'h') |
|
60 |
wt.rename_one('f', 'j') |
|
61 |
||
1185.50.53
by John Arbash Meinel
[patch] Aaron Bentley: make revert work in a subdirectory. |
62 |
def helper(self, param=''): |
63 |
self._prepare_tree() |
|
64 |
# change dir
|
|
65 |
# revert to default revision for file in subdir does work
|
|
66 |
os.chdir('dir') |
|
67 |
mutter('cd dir\n') |
|
68 |
||
2552.2.2
by Vincent Ladeuil
Enforce run_bzr(string) where possible. |
69 |
self.assertEquals('1\n', self.run_bzr('revno')[0]) |
2530.3.1
by Martin Pool
Cleanup old variations on run_bzr in the test suite |
70 |
self.run_bzr('revert %s file' % param) |
1185.50.53
by John Arbash Meinel
[patch] Aaron Bentley: make revert work in a subdirectory. |
71 |
self.assertEquals('spam', open('file', 'rb').read()) |
72 |
||
73 |
def test_revert_in_subdir(self): |
|
74 |
self.helper() |
|
75 |
||
76 |
def test_revert_to_revision_in_subdir(self): |
|
77 |
# test case for bug #29424:
|
|
78 |
# revert to specific revision for file in subdir does not work
|
|
79 |
self.helper('-r 1') |
|
1558.4.2
by Aaron Bentley
Revert in checkout works properly |
80 |
|
81 |
def test_revert_in_checkout(self): |
|
82 |
os.mkdir('brach') |
|
83 |
os.chdir('brach') |
|
84 |
self._prepare_tree() |
|
2530.3.1
by Martin Pool
Cleanup old variations on run_bzr in the test suite |
85 |
self.run_bzr('checkout --lightweight . ../sprach') |
86 |
self.run_bzr('commit -m more') |
|
1558.4.2
by Aaron Bentley
Revert in checkout works properly |
87 |
os.chdir('../sprach') |
2552.2.2
by Vincent Ladeuil
Enforce run_bzr(string) where possible. |
88 |
self.assertEqual('', self.run_bzr('status')[0]) |
2530.3.1
by Martin Pool
Cleanup old variations on run_bzr in the test suite |
89 |
self.run_bzr('revert') |
2552.2.2
by Vincent Ladeuil
Enforce run_bzr(string) where possible. |
90 |
self.assertEqual('', self.run_bzr('status')[0]) |
1551.7.7
by Aaron Bentley
Handle revert DIRECTORY |
91 |
|
92 |
def test_revert_dirname(self): |
|
93 |
"""Test that revert DIRECTORY does what's expected"""
|
|
94 |
self._prepare_rename_mod_tree() |
|
2552.2.3
by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests. |
95 |
self.run_bzr('revert a') |
1551.7.7
by Aaron Bentley
Handle revert DIRECTORY |
96 |
self.failUnlessExists('a/b') |
97 |
self.failUnlessExists('a/d') |
|
98 |
self.failIfExists('a/g') |
|
4570.2.10
by Robert Collins
Make test_revert_dirname a KnownFailure. |
99 |
self.expectFailure( |
100 |
"j is in the delta revert applies because j was renamed too", |
|
101 |
self.failUnlessExists, 'j') |
|
1551.7.7
by Aaron Bentley
Handle revert DIRECTORY |
102 |
self.failUnlessExists('h') |
2552.2.3
by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests. |
103 |
self.run_bzr('revert f') |
1551.7.7
by Aaron Bentley
Handle revert DIRECTORY |
104 |
self.failIfExists('j') |
105 |
self.failIfExists('h') |
|
1551.7.9
by Aaron Bentley
Update for review comments |
106 |
self.failUnlessExists('a/d/e') |
1551.7.8
by Aaron Bentley
Merge bzr.dev |
107 |
|
2225.1.1
by Aaron Bentley
Added revert change display, with tests |
108 |
def test_revert_chatter(self): |
109 |
self._prepare_rename_mod_tree() |
|
110 |
chatter = self.run_bzr('revert')[1] |
|
2255.7.96
by Robert Collins
Change _iter_changes interface to yield both old and new paths. |
111 |
self.assertEqualDiff( |
112 |
'R a/g => f/g\n' |
|
113 |
'R h => f/h\n' |
|
114 |
'R j/ => f/\n' |
|
115 |
'R j/b => a/b\n' |
|
116 |
'R j/d/ => a/d/\n' |
|
117 |
'R j/e => a/d/e\n', |
|
118 |
chatter) |
|
119 |
||
1711.4.24
by John Arbash Meinel
move the revert tests out of test_too_much.py |
120 |
def test_revert(self): |
121 |
self.run_bzr('init') |
|
122 |
||
123 |
file('hello', 'wt').write('foo') |
|
2552.2.3
by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests. |
124 |
self.run_bzr('add hello') |
125 |
self.run_bzr('commit -m setup hello') |
|
1711.4.24
by John Arbash Meinel
move the revert tests out of test_too_much.py |
126 |
|
127 |
file('goodbye', 'wt').write('baz') |
|
2552.2.3
by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests. |
128 |
self.run_bzr('add goodbye') |
129 |
self.run_bzr('commit -m setup goodbye') |
|
1711.4.24
by John Arbash Meinel
move the revert tests out of test_too_much.py |
130 |
|
131 |
file('hello', 'wt').write('bar') |
|
132 |
file('goodbye', 'wt').write('qux') |
|
2552.2.3
by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests. |
133 |
self.run_bzr('revert hello') |
1711.4.24
by John Arbash Meinel
move the revert tests out of test_too_much.py |
134 |
self.check_file_contents('hello', 'foo') |
135 |
self.check_file_contents('goodbye', 'qux') |
|
136 |
self.run_bzr('revert') |
|
137 |
self.check_file_contents('goodbye', 'baz') |
|
138 |
||
139 |
os.mkdir('revertdir') |
|
2552.2.3
by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests. |
140 |
self.run_bzr('add revertdir') |
141 |
self.run_bzr('commit -m f') |
|
1711.4.24
by John Arbash Meinel
move the revert tests out of test_too_much.py |
142 |
os.rmdir('revertdir') |
143 |
self.run_bzr('revert') |
|
144 |
||
145 |
if bzrlib.osutils.has_symlinks(): |
|
146 |
os.symlink('/unlikely/to/exist', 'symlink') |
|
2552.2.3
by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests. |
147 |
self.run_bzr('add symlink') |
148 |
self.run_bzr('commit -m f') |
|
1711.4.24
by John Arbash Meinel
move the revert tests out of test_too_much.py |
149 |
os.unlink('symlink') |
150 |
self.run_bzr('revert') |
|
151 |
self.failUnlessExists('symlink') |
|
152 |
os.unlink('symlink') |
|
153 |
os.symlink('a-different-path', 'symlink') |
|
154 |
self.run_bzr('revert') |
|
155 |
self.assertEqual('/unlikely/to/exist', |
|
156 |
os.readlink('symlink')) |
|
157 |
else: |
|
158 |
self.log("skipping revert symlink tests") |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
159 |
|
1711.4.24
by John Arbash Meinel
move the revert tests out of test_too_much.py |
160 |
file('hello', 'wt').write('xyz') |
2552.2.3
by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests. |
161 |
self.run_bzr('commit -m xyz hello') |
162 |
self.run_bzr('revert -r 1 hello') |
|
1711.4.24
by John Arbash Meinel
move the revert tests out of test_too_much.py |
163 |
self.check_file_contents('hello', 'foo') |
2552.2.3
by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests. |
164 |
self.run_bzr('revert hello') |
1711.4.24
by John Arbash Meinel
move the revert tests out of test_too_much.py |
165 |
self.check_file_contents('hello', 'xyz') |
166 |
os.chdir('revertdir') |
|
167 |
self.run_bzr('revert') |
|
168 |
os.chdir('..') |
|
2255.2.231
by Robert Collins
Add test showing reverts UI working as Aaron intended it to. |
169 |
|
170 |
def test_revert_newly_added(self): |
|
171 |
# this tests the UI reports reverting a newly added file
|
|
172 |
# correct (such files are not deleted)
|
|
173 |
tree = self.make_branch_and_tree('.') |
|
174 |
self.build_tree(['file']) |
|
175 |
tree.add(['file']) |
|
176 |
out, err = self.run_bzr('revert') |
|
177 |
self.assertEqual('', out) |
|
178 |
self.assertEqual('- file\n', err) |
|
179 |
||
180 |
def test_revert_removing_file(self): |
|
181 |
# this tests the UI reports reverting a file which has been committed
|
|
182 |
# to a revision that did not have it, reports it as being deleted.
|
|
183 |
tree = self.make_branch_and_tree('.') |
|
184 |
tree.commit('empty commit') |
|
185 |
self.build_tree(['file']) |
|
186 |
tree.add(['file']) |
|
187 |
tree.commit('add file') |
|
2552.2.3
by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests. |
188 |
out, err = self.run_bzr('revert -r -2') |
2255.2.231
by Robert Collins
Add test showing reverts UI working as Aaron intended it to. |
189 |
self.assertEqual('', out) |
190 |
self.assertEqual('-D file\n', err) |
|
2851.2.1
by Martin Pool
Add revert --forget-merges |
191 |
|
192 |
def test_revert_forget_merges(self): |
|
193 |
# revert --forget-merges removes any pending merges into the tree, but
|
|
194 |
# leaves the files unchanged
|
|
195 |
tree = self.make_branch_and_tree('.') |
|
196 |
# forget-merges before first commit, though pointless, does not fail
|
|
197 |
self.run_bzr(['revert', '--forget-merges']) |
|
198 |
self.build_tree(['file']) |
|
199 |
first_rev_id = tree.commit('initial commit') |
|
200 |
self.build_tree_contents([('file', 'new content')]) |
|
201 |
existing_parents = tree.get_parent_ids() |
|
202 |
self.assertEquals([first_rev_id], existing_parents) |
|
203 |
merged_parents = existing_parents + ['merged-in-rev'] |
|
204 |
tree.set_parent_ids(merged_parents) |
|
205 |
self.assertEquals(merged_parents, tree.get_parent_ids()) |
|
206 |
self.run_bzr(['revert', '--forget-merges']) |
|
207 |
self.assertEquals([first_rev_id], tree.get_parent_ids()) |
|
208 |
# changed files are not reverted
|
|
209 |
self.assertFileEqual('new content', 'file') |
|
210 |
# you can give it the path of a tree
|
|
211 |
self.run_bzr(['revert', '--forget-merges', tree.abspath('.')]) |