1
# Copyright (C) 2005 Canonical Ltd
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.
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.
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
17
"""Black-box tests for bzr revert."""
22
from bzrlib.tests.blackbox import ExternalBase
23
from bzrlib.trace import mutter
24
from bzrlib.workingtree import WorkingTree
27
class TestRevert(ExternalBase):
29
def _prepare_tree(self):
31
self.run_bzr('mkdir dir')
33
f = file('dir/file', 'wb')
36
self.run_bzr('add dir/file')
38
self.run_bzr('commit -m1')
41
f = file('dir/file', 'wb')
46
self.assertEquals('modified:\n dir/file\n', self.run_bzr(['status'])[0])
48
def _prepare_rename_mod_tree(self):
49
self.build_tree(['a/', 'a/b', 'a/c', 'a/d/', 'a/d/e', 'f/', 'f/g',
53
self.run_bzr('commit', '-m', '1')
54
wt = WorkingTree.open('.')
55
wt.rename_one('a/b', 'f/b')
56
wt.rename_one('a/d/e', 'f/e')
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')
62
def helper(self, param=''):
65
# revert to default revision for file in subdir does work
69
self.assertEquals('1\n', self.run_bzr(['revno'])[0])
70
self.run_bzr('revert %s file' % param)
71
self.assertEquals('spam', open('file', 'rb').read())
73
def test_revert_in_subdir(self):
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
81
def test_revert_in_checkout(self):
85
self.run_bzr('checkout --lightweight . ../sprach')
86
self.run_bzr('commit -m more')
88
self.assertEqual('', self.run_bzr(['status'])[0])
89
self.run_bzr('revert')
90
self.assertEqual('', self.run_bzr(['status'])[0])
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')
104
self.failUnlessExists('a/d/e')
106
def test_revert_chatter(self):
107
self._prepare_rename_mod_tree()
108
chatter = self.run_bzr('revert')[1]
109
self.assertEqualDiff(
118
def test_revert(self):
121
file('hello', 'wt').write('foo')
122
self.run_bzr('add', 'hello')
123
self.run_bzr('commit', '-m', 'setup', 'hello')
125
file('goodbye', 'wt').write('baz')
126
self.run_bzr('add', 'goodbye')
127
self.run_bzr('commit', '-m', 'setup', 'goodbye')
129
file('hello', 'wt').write('bar')
130
file('goodbye', 'wt').write('qux')
131
self.run_bzr('revert', 'hello')
132
self.check_file_contents('hello', 'foo')
133
self.check_file_contents('goodbye', 'qux')
134
self.run_bzr('revert')
135
self.check_file_contents('goodbye', 'baz')
137
os.mkdir('revertdir')
138
self.run_bzr('add', 'revertdir')
139
self.run_bzr('commit', '-m', 'f')
140
os.rmdir('revertdir')
141
self.run_bzr('revert')
143
if bzrlib.osutils.has_symlinks():
144
os.symlink('/unlikely/to/exist', 'symlink')
145
self.run_bzr('add', 'symlink')
146
self.run_bzr('commit', '-m', 'f')
148
self.run_bzr('revert')
149
self.failUnlessExists('symlink')
151
os.symlink('a-different-path', 'symlink')
152
self.run_bzr('revert')
153
self.assertEqual('/unlikely/to/exist',
154
os.readlink('symlink'))
156
self.log("skipping revert symlink tests")
158
file('hello', 'wt').write('xyz')
159
self.run_bzr('commit', '-m', 'xyz', 'hello')
160
self.run_bzr('revert', '-r', '1', 'hello')
161
self.check_file_contents('hello', 'foo')
162
self.run_bzr('revert', 'hello')
163
self.check_file_contents('hello', 'xyz')
164
os.chdir('revertdir')
165
self.run_bzr('revert')
168
def test_revert_newly_added(self):
169
# this tests the UI reports reverting a newly added file
170
# correct (such files are not deleted)
171
tree = self.make_branch_and_tree('.')
172
self.build_tree(['file'])
174
out, err = self.run_bzr('revert')
175
self.assertEqual('', out)
176
self.assertEqual('- file\n', err)
178
def test_revert_removing_file(self):
179
# this tests the UI reports reverting a file which has been committed
180
# to a revision that did not have it, reports it as being deleted.
181
tree = self.make_branch_and_tree('.')
182
tree.commit('empty commit')
183
self.build_tree(['file'])
185
tree.commit('add file')
186
out, err = self.run_bzr('revert', '-r', '-2')
187
self.assertEqual('', out)
188
self.assertEqual('-D file\n', err)