/brz/remove-bazaar

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