bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
| 
2052.3.2
by John Arbash Meinel
 Change Copyright .. by Canonical to Copyright ... Canonical  | 
1  | 
# Copyright (C) 2005 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
 | 
|
15  | 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 | 
|
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):  | 
|
30  | 
self.runbzr('init')  | 
|
31  | 
self.runbzr('mkdir dir')  | 
|
32  | 
||
33  | 
f = file('dir/file', 'wb')  | 
|
34  | 
f.write('spam')  | 
|
35  | 
f.close()  | 
|
36  | 
self.runbzr('add dir/file')  | 
|
37  | 
||
38  | 
self.runbzr('commit -m1')  | 
|
39  | 
||
40  | 
        # modify file
 | 
|
41  | 
f = file('dir/file', 'wb')  | 
|
42  | 
f.write('eggs')  | 
|
43  | 
f.close()  | 
|
44  | 
||
45  | 
        # check status
 | 
|
46  | 
self.assertEquals('modified:\n dir/file\n', self.capture('status'))  | 
|
47  | 
||
| 
1551.7.7
by Aaron Bentley
 Handle revert DIRECTORY  | 
48  | 
def _prepare_rename_mod_tree(self):  | 
49  | 
self.build_tree(['a/', 'a/b', 'a/c', 'a/d/', 'a/d/e', 'f/', 'f/g',  | 
|
50  | 
'f/h', 'f/i'])  | 
|
51  | 
self.run_bzr('init')  | 
|
52  | 
self.run_bzr('add')  | 
|
53  | 
self.run_bzr('commit', '-m', '1')  | 
|
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  | 
||
69  | 
self.assertEquals('1\n', self.capture('revno'))  | 
|
70  | 
self.runbzr('revert %s file' % param)  | 
|
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()  | 
|
85  | 
self.runbzr('checkout --lightweight . ../sprach')  | 
|
86  | 
self.runbzr('commit -m more')  | 
|
87  | 
os.chdir('../sprach')  | 
|
88  | 
self.assertEqual('', self.capture('status'))  | 
|
89  | 
self.runbzr('revert')  | 
|
90  | 
self.assertEqual('', self.capture('status'))  | 
|
| 
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()  | 
|
95  | 
self.run_bzr('revert', 'a')  | 
|
96  | 
self.failUnlessExists('a/b')  | 
|
97  | 
self.failUnlessExists('a/d')  | 
|
98  | 
self.failIfExists('a/g')  | 
|
99  | 
self.failUnlessExists('j')  | 
|
100  | 
self.failUnlessExists('h')  | 
|
101  | 
self.run_bzr('revert', 'f')  | 
|
102  | 
self.failIfExists('j')  | 
|
103  | 
self.failIfExists('h')  | 
|
| 
1551.7.9
by Aaron Bentley
 Update for review comments  | 
104  | 
self.failUnlessExists('a/d/e')  | 
| 
1551.7.8
by Aaron Bentley
 Merge bzr.dev  | 
105  | 
|
| 
2225.1.1
by Aaron Bentley
 Added revert change display, with tests  | 
106  | 
def test_revert_chatter(self):  | 
107  | 
self._prepare_rename_mod_tree()  | 
|
108  | 
chatter = self.run_bzr('revert')[1]  | 
|
| 
1551.11.11
by Aaron Bentley
 Get tests passing  | 
109  | 
self.assertEqualDiff('R j/b => a/b\n'  | 
| 
2225.1.6
by Aaron Bentley
 Update blackbox test  | 
110  | 
'R j/d/ => a/d/\n'  | 
111  | 
'R j/e => a/d/e\n'  | 
|
| 
1551.11.11
by Aaron Bentley
 Get tests passing  | 
112  | 
'R j/ => f/\n'  | 
| 
2225.1.6
by Aaron Bentley
 Update blackbox test  | 
113  | 
'R a/g => f/g\n'  | 
114  | 
'R h => f/h\n', chatter)  | 
|
| 
1711.4.24
by John Arbash Meinel
 move the revert tests out of test_too_much.py  | 
115  | 
def test_revert(self):  | 
116  | 
self.run_bzr('init')  | 
|
117  | 
||
118  | 
file('hello', 'wt').write('foo')  | 
|
119  | 
self.run_bzr('add', 'hello')  | 
|
120  | 
self.run_bzr('commit', '-m', 'setup', 'hello')  | 
|
121  | 
||
122  | 
file('goodbye', 'wt').write('baz')  | 
|
123  | 
self.run_bzr('add', 'goodbye')  | 
|
124  | 
self.run_bzr('commit', '-m', 'setup', 'goodbye')  | 
|
125  | 
||
126  | 
file('hello', 'wt').write('bar')  | 
|
127  | 
file('goodbye', 'wt').write('qux')  | 
|
128  | 
self.run_bzr('revert', 'hello')  | 
|
129  | 
self.check_file_contents('hello', 'foo')  | 
|
130  | 
self.check_file_contents('goodbye', 'qux')  | 
|
131  | 
self.run_bzr('revert')  | 
|
132  | 
self.check_file_contents('goodbye', 'baz')  | 
|
133  | 
||
134  | 
os.mkdir('revertdir')  | 
|
135  | 
self.run_bzr('add', 'revertdir')  | 
|
136  | 
self.run_bzr('commit', '-m', 'f')  | 
|
137  | 
os.rmdir('revertdir')  | 
|
138  | 
self.run_bzr('revert')  | 
|
139  | 
||
140  | 
if bzrlib.osutils.has_symlinks():  | 
|
141  | 
os.symlink('/unlikely/to/exist', 'symlink')  | 
|
142  | 
self.run_bzr('add', 'symlink')  | 
|
143  | 
self.run_bzr('commit', '-m', 'f')  | 
|
144  | 
os.unlink('symlink')  | 
|
145  | 
self.run_bzr('revert')  | 
|
146  | 
self.failUnlessExists('symlink')  | 
|
147  | 
os.unlink('symlink')  | 
|
148  | 
os.symlink('a-different-path', 'symlink')  | 
|
149  | 
self.run_bzr('revert')  | 
|
150  | 
self.assertEqual('/unlikely/to/exist',  | 
|
151  | 
os.readlink('symlink'))  | 
|
152  | 
else:  | 
|
153  | 
self.log("skipping revert symlink tests")  | 
|
154  | 
||
155  | 
file('hello', 'wt').write('xyz')  | 
|
156  | 
self.run_bzr('commit', '-m', 'xyz', 'hello')  | 
|
157  | 
self.run_bzr('revert', '-r', '1', 'hello')  | 
|
158  | 
self.check_file_contents('hello', 'foo')  | 
|
159  | 
self.run_bzr('revert', 'hello')  | 
|
160  | 
self.check_file_contents('hello', 'xyz')  | 
|
161  | 
os.chdir('revertdir')  | 
|
162  | 
self.run_bzr('revert')  | 
|
163  | 
os.chdir('..')  |