/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_revert.py

Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005 by Canonical Ltd
 
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
 
 
21
<<<<<<< TREE
 
22
from bzrlib.workingtree import WorkingTree
 
23
=======
 
24
import bzrlib.osutils
 
25
>>>>>>> MERGE-SOURCE
 
26
from bzrlib.tests.blackbox import ExternalBase
 
27
from bzrlib.trace import mutter
 
28
 
 
29
 
 
30
class TestRevert(ExternalBase):
 
31
 
 
32
    def _prepare_tree(self):
 
33
        self.runbzr('init')
 
34
        self.runbzr('mkdir dir')
 
35
 
 
36
        f = file('dir/file', 'wb')
 
37
        f.write('spam')
 
38
        f.close()
 
39
        self.runbzr('add dir/file')
 
40
 
 
41
        self.runbzr('commit -m1')
 
42
 
 
43
        # modify file
 
44
        f = file('dir/file', 'wb')
 
45
        f.write('eggs')
 
46
        f.close()
 
47
 
 
48
        # check status
 
49
        self.assertEquals('modified:\n  dir/file\n', self.capture('status'))
 
50
 
 
51
    def _prepare_rename_mod_tree(self):
 
52
        self.build_tree(['a/', 'a/b', 'a/c', 'a/d/', 'a/d/e', 'f/', 'f/g', 
 
53
                         'f/h', 'f/i'])
 
54
        self.run_bzr('init')
 
55
        self.run_bzr('add')
 
56
        self.run_bzr('commit', '-m', '1')
 
57
        wt = WorkingTree.open('.')
 
58
        wt.rename_one('a/b', 'f/b')
 
59
        wt.rename_one('a/d', 'f/d')
 
60
        wt.rename_one('f/g', 'a/g')
 
61
        wt.rename_one('f/h', 'h')
 
62
        wt.rename_one('f', 'j')
 
63
 
 
64
    def helper(self, param=''):
 
65
        self._prepare_tree()
 
66
        # change dir
 
67
        # revert to default revision for file in subdir does work
 
68
        os.chdir('dir')
 
69
        mutter('cd dir\n')
 
70
 
 
71
        self.assertEquals('1\n', self.capture('revno'))
 
72
        self.runbzr('revert %s file' % param)
 
73
        self.assertEquals('spam', open('file', 'rb').read())
 
74
 
 
75
    def test_revert_in_subdir(self):
 
76
        self.helper()
 
77
 
 
78
    def test_revert_to_revision_in_subdir(self):
 
79
        # test case for bug #29424:
 
80
        # revert to specific revision for file in subdir does not work
 
81
        self.helper('-r 1')
 
82
 
 
83
    def test_revert_in_checkout(self):
 
84
        os.mkdir('brach')
 
85
        os.chdir('brach')
 
86
        self._prepare_tree()
 
87
        self.runbzr('checkout --lightweight . ../sprach')
 
88
        self.runbzr('commit -m more')
 
89
        os.chdir('../sprach')
 
90
        self.assertEqual('', self.capture('status'))
 
91
        self.runbzr('revert')
 
92
        self.assertEqual('', self.capture('status'))
 
93
 
 
94
    def test_revert_dirname(self):
 
95
        """Test that revert DIRECTORY does what's expected"""
 
96
        self._prepare_rename_mod_tree()
 
97
        self.run_bzr('revert', 'a')
 
98
        self.failUnlessExists('a/b')
 
99
        self.failUnlessExists('a/d')
 
100
        self.failIfExists('a/g')
 
101
        self.failUnlessExists('j')
 
102
        self.failUnlessExists('h')
 
103
        self.run_bzr('revert', 'f')
 
104
        self.failIfExists('j')
 
105
        self.failIfExists('h')
 
106
 
 
107
    def test_revert(self):
 
108
        self.run_bzr('init')
 
109
 
 
110
        file('hello', 'wt').write('foo')
 
111
        self.run_bzr('add', 'hello')
 
112
        self.run_bzr('commit', '-m', 'setup', 'hello')
 
113
 
 
114
        file('goodbye', 'wt').write('baz')
 
115
        self.run_bzr('add', 'goodbye')
 
116
        self.run_bzr('commit', '-m', 'setup', 'goodbye')
 
117
 
 
118
        file('hello', 'wt').write('bar')
 
119
        file('goodbye', 'wt').write('qux')
 
120
        self.run_bzr('revert', 'hello')
 
121
        self.check_file_contents('hello', 'foo')
 
122
        self.check_file_contents('goodbye', 'qux')
 
123
        self.run_bzr('revert')
 
124
        self.check_file_contents('goodbye', 'baz')
 
125
 
 
126
        os.mkdir('revertdir')
 
127
        self.run_bzr('add', 'revertdir')
 
128
        self.run_bzr('commit', '-m', 'f')
 
129
        os.rmdir('revertdir')
 
130
        self.run_bzr('revert')
 
131
 
 
132
        if bzrlib.osutils.has_symlinks():
 
133
            os.symlink('/unlikely/to/exist', 'symlink')
 
134
            self.run_bzr('add', 'symlink')
 
135
            self.run_bzr('commit', '-m', 'f')
 
136
            os.unlink('symlink')
 
137
            self.run_bzr('revert')
 
138
            self.failUnlessExists('symlink')
 
139
            os.unlink('symlink')
 
140
            os.symlink('a-different-path', 'symlink')
 
141
            self.run_bzr('revert')
 
142
            self.assertEqual('/unlikely/to/exist',
 
143
                             os.readlink('symlink'))
 
144
        else:
 
145
            self.log("skipping revert symlink tests")
 
146
        
 
147
        file('hello', 'wt').write('xyz')
 
148
        self.run_bzr('commit', '-m', 'xyz', 'hello')
 
149
        self.run_bzr('revert', '-r', '1', 'hello')
 
150
        self.check_file_contents('hello', 'foo')
 
151
        self.run_bzr('revert', 'hello')
 
152
        self.check_file_contents('hello', 'xyz')
 
153
        os.chdir('revertdir')
 
154
        self.run_bzr('revert')
 
155
        os.chdir('..')
 
156