1
# Copyright (C) 2005 by 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
26
class TestRevert(ExternalBase):
28
def _prepare_tree(self):
30
self.runbzr('mkdir dir')
32
f = file('dir/file', 'wb')
35
self.runbzr('add dir/file')
37
self.runbzr('commit -m1')
40
f = file('dir/file', 'wb')
45
self.assertEquals('modified:\n dir/file\n', self.capture('status'))
47
def helper(self, param=''):
50
# revert to default revision for file in subdir does work
54
self.assertEquals('1\n', self.capture('revno'))
55
self.runbzr('revert %s file' % param)
56
self.assertEquals('spam', open('file', 'rb').read())
58
def test_revert_in_subdir(self):
61
def test_revert_to_revision_in_subdir(self):
62
# test case for bug #29424:
63
# revert to specific revision for file in subdir does not work
66
def test_revert_in_checkout(self):
70
self.runbzr('checkout --lightweight . ../sprach')
71
self.runbzr('commit -m more')
73
self.assertEqual('', self.capture('status'))
75
self.assertEqual('', self.capture('status'))
77
def test_revert(self):
80
file('hello', 'wt').write('foo')
81
self.run_bzr('add', 'hello')
82
self.run_bzr('commit', '-m', 'setup', 'hello')
84
file('goodbye', 'wt').write('baz')
85
self.run_bzr('add', 'goodbye')
86
self.run_bzr('commit', '-m', 'setup', 'goodbye')
88
file('hello', 'wt').write('bar')
89
file('goodbye', 'wt').write('qux')
90
self.run_bzr('revert', 'hello')
91
self.check_file_contents('hello', 'foo')
92
self.check_file_contents('goodbye', 'qux')
93
self.run_bzr('revert')
94
self.check_file_contents('goodbye', 'baz')
97
self.run_bzr('add', 'revertdir')
98
self.run_bzr('commit', '-m', 'f')
100
self.run_bzr('revert')
102
if bzrlib.osutils.has_symlinks():
103
os.symlink('/unlikely/to/exist', 'symlink')
104
self.run_bzr('add', 'symlink')
105
self.run_bzr('commit', '-m', 'f')
107
self.run_bzr('revert')
108
self.failUnlessExists('symlink')
110
os.symlink('a-different-path', 'symlink')
111
self.run_bzr('revert')
112
self.assertEqual('/unlikely/to/exist',
113
os.readlink('symlink'))
115
self.log("skipping revert symlink tests")
117
file('hello', 'wt').write('xyz')
118
self.run_bzr('commit', '-m', 'xyz', 'hello')
119
self.run_bzr('revert', '-r', '1', 'hello')
120
self.check_file_contents('hello', 'foo')
121
self.run_bzr('revert', 'hello')
122
self.check_file_contents('hello', 'xyz')
123
os.chdir('revertdir')
124
self.run_bzr('revert')