13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
17
"""Black-box tests for bzr revert."""
46
self.assertEquals('modified:\n dir/file\n', self.run_bzr('status')[0])
46
self.assertEquals('modified:\n dir/file\n', self.capture('status'))
48
48
def _prepare_rename_mod_tree(self):
49
self.build_tree(['a/', 'a/b', 'a/c', 'a/d/', 'a/d/e', 'f/', 'f/g',
49
self.build_tree(['a/', 'a/b', 'a/c', 'a/d/', 'a/d/e', 'f/', 'f/g',
51
51
self.run_bzr('init')
52
52
self.run_bzr('add')
53
self.run_bzr('commit -m 1')
53
self.run_bzr('commit', '-m', '1')
54
54
wt = WorkingTree.open('.')
55
55
wt.rename_one('a/b', 'f/b')
56
56
wt.rename_one('a/d/e', 'f/e')
84
84
self._prepare_tree()
85
self.run_bzr('checkout --lightweight . ../sprach')
86
self.run_bzr('commit -m more')
85
self.runbzr('checkout --lightweight . ../sprach')
86
self.runbzr('commit -m more')
87
87
os.chdir('../sprach')
88
self.assertEqual('', self.run_bzr('status')[0])
89
self.run_bzr('revert')
90
self.assertEqual('', self.run_bzr('status')[0])
88
self.assertEqual('', self.capture('status'))
90
self.assertEqual('', self.capture('status'))
92
92
def test_revert_dirname(self):
93
93
"""Test that revert DIRECTORY does what's expected"""
94
94
self._prepare_rename_mod_tree()
95
self.run_bzr('revert a')
95
self.run_bzr('revert', 'a')
96
96
self.failUnlessExists('a/b')
97
97
self.failUnlessExists('a/d')
98
98
self.failIfExists('a/g')
100
"j is in the delta revert applies because j was renamed too",
101
self.failUnlessExists, 'j')
99
self.failUnlessExists('j')
102
100
self.failUnlessExists('h')
103
self.run_bzr('revert f')
101
self.run_bzr('revert', 'f')
104
102
self.failIfExists('j')
105
103
self.failIfExists('h')
106
104
self.failUnlessExists('a/d/e')
108
def test_revert_chatter(self):
109
self._prepare_rename_mod_tree()
110
chatter = self.run_bzr('revert')[1]
111
self.assertEqualDiff(
120
106
def test_revert(self):
121
107
self.run_bzr('init')
123
109
file('hello', 'wt').write('foo')
124
self.run_bzr('add hello')
125
self.run_bzr('commit -m setup hello')
110
self.run_bzr('add', 'hello')
111
self.run_bzr('commit', '-m', 'setup', 'hello')
127
113
file('goodbye', 'wt').write('baz')
128
self.run_bzr('add goodbye')
129
self.run_bzr('commit -m setup goodbye')
114
self.run_bzr('add', 'goodbye')
115
self.run_bzr('commit', '-m', 'setup', 'goodbye')
131
117
file('hello', 'wt').write('bar')
132
118
file('goodbye', 'wt').write('qux')
133
self.run_bzr('revert hello')
119
self.run_bzr('revert', 'hello')
134
120
self.check_file_contents('hello', 'foo')
135
121
self.check_file_contents('goodbye', 'qux')
136
122
self.run_bzr('revert')
137
123
self.check_file_contents('goodbye', 'baz')
139
125
os.mkdir('revertdir')
140
self.run_bzr('add revertdir')
141
self.run_bzr('commit -m f')
126
self.run_bzr('add', 'revertdir')
127
self.run_bzr('commit', '-m', 'f')
142
128
os.rmdir('revertdir')
143
129
self.run_bzr('revert')
145
131
if bzrlib.osutils.has_symlinks():
146
132
os.symlink('/unlikely/to/exist', 'symlink')
147
self.run_bzr('add symlink')
148
self.run_bzr('commit -m f')
133
self.run_bzr('add', 'symlink')
134
self.run_bzr('commit', '-m', 'f')
149
135
os.unlink('symlink')
150
136
self.run_bzr('revert')
151
137
self.failUnlessExists('symlink')
156
142
os.readlink('symlink'))
158
144
self.log("skipping revert symlink tests")
160
146
file('hello', 'wt').write('xyz')
161
self.run_bzr('commit -m xyz hello')
162
self.run_bzr('revert -r 1 hello')
147
self.run_bzr('commit', '-m', 'xyz', 'hello')
148
self.run_bzr('revert', '-r', '1', 'hello')
163
149
self.check_file_contents('hello', 'foo')
164
self.run_bzr('revert hello')
150
self.run_bzr('revert', 'hello')
165
151
self.check_file_contents('hello', 'xyz')
166
152
os.chdir('revertdir')
167
153
self.run_bzr('revert')
170
def test_revert_newly_added(self):
171
# this tests the UI reports reverting a newly added file
172
# correct (such files are not deleted)
173
tree = self.make_branch_and_tree('.')
174
self.build_tree(['file'])
176
out, err = self.run_bzr('revert')
177
self.assertEqual('', out)
178
self.assertEqual('- file\n', err)
180
def test_revert_removing_file(self):
181
# this tests the UI reports reverting a file which has been committed
182
# to a revision that did not have it, reports it as being deleted.
183
tree = self.make_branch_and_tree('.')
184
tree.commit('empty commit')
185
self.build_tree(['file'])
187
tree.commit('add file')
188
out, err = self.run_bzr('revert -r -2')
189
self.assertEqual('', out)
190
self.assertEqual('-D file\n', err)
192
def test_revert_forget_merges(self):
193
# revert --forget-merges removes any pending merges into the tree, but
194
# leaves the files unchanged
195
tree = self.make_branch_and_tree('.')
196
# forget-merges before first commit, though pointless, does not fail
197
self.run_bzr(['revert', '--forget-merges'])
198
self.build_tree(['file'])
199
first_rev_id = tree.commit('initial commit')
200
self.build_tree_contents([('file', 'new content')])
201
existing_parents = tree.get_parent_ids()
202
self.assertEquals([first_rev_id], existing_parents)
203
merged_parents = existing_parents + ['merged-in-rev']
204
tree.set_parent_ids(merged_parents)
205
self.assertEquals(merged_parents, tree.get_parent_ids())
206
self.run_bzr(['revert', '--forget-merges'])
207
self.assertEquals([first_rev_id], tree.get_parent_ids())
208
# changed files are not reverted
209
self.assertFileEqual('new content', 'file')
210
# you can give it the path of a tree
211
self.run_bzr(['revert', '--forget-merges', tree.abspath('.')])