46
self.assertEquals('modified:\n dir/file\n', self.capture('status'))
46
self.assertEquals('modified:\n dir/file\n', self.run_bzr('status')[0])
48
48
def _prepare_rename_mod_tree(self):
49
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.runbzr('checkout --lightweight . ../sprach')
86
self.runbzr('commit -m more')
85
self.run_bzr('checkout --lightweight . ../sprach')
86
self.run_bzr('commit -m more')
87
87
os.chdir('../sprach')
88
self.assertEqual('', self.capture('status'))
90
self.assertEqual('', self.capture('status'))
88
self.assertEqual('', self.run_bzr('status')[0])
89
self.run_bzr('revert')
90
self.assertEqual('', self.run_bzr('status')[0])
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')
99
99
self.failUnlessExists('j')
100
100
self.failUnlessExists('h')
101
self.run_bzr('revert', 'f')
101
self.run_bzr('revert f')
102
102
self.failIfExists('j')
103
103
self.failIfExists('h')
104
104
self.failUnlessExists('a/d/e')
106
106
def test_revert_chatter(self):
107
107
self._prepare_rename_mod_tree()
108
108
chatter = self.run_bzr('revert')[1]
109
self.assertEqualDiff('R j/b => a/b\n'
114
'R h => f/h\n', chatter)
109
self.assertEqualDiff(
115
118
def test_revert(self):
116
119
self.run_bzr('init')
118
121
file('hello', 'wt').write('foo')
119
self.run_bzr('add', 'hello')
120
self.run_bzr('commit', '-m', 'setup', 'hello')
122
self.run_bzr('add hello')
123
self.run_bzr('commit -m setup hello')
122
125
file('goodbye', 'wt').write('baz')
123
self.run_bzr('add', 'goodbye')
124
self.run_bzr('commit', '-m', 'setup', 'goodbye')
126
self.run_bzr('add goodbye')
127
self.run_bzr('commit -m setup goodbye')
126
129
file('hello', 'wt').write('bar')
127
130
file('goodbye', 'wt').write('qux')
128
self.run_bzr('revert', 'hello')
131
self.run_bzr('revert hello')
129
132
self.check_file_contents('hello', 'foo')
130
133
self.check_file_contents('goodbye', 'qux')
131
134
self.run_bzr('revert')
132
135
self.check_file_contents('goodbye', 'baz')
134
137
os.mkdir('revertdir')
135
self.run_bzr('add', 'revertdir')
136
self.run_bzr('commit', '-m', 'f')
138
self.run_bzr('add revertdir')
139
self.run_bzr('commit -m f')
137
140
os.rmdir('revertdir')
138
141
self.run_bzr('revert')
140
143
if bzrlib.osutils.has_symlinks():
141
144
os.symlink('/unlikely/to/exist', 'symlink')
142
self.run_bzr('add', 'symlink')
143
self.run_bzr('commit', '-m', 'f')
145
self.run_bzr('add symlink')
146
self.run_bzr('commit -m f')
144
147
os.unlink('symlink')
145
148
self.run_bzr('revert')
146
149
self.failUnlessExists('symlink')
153
156
self.log("skipping revert symlink tests")
155
158
file('hello', 'wt').write('xyz')
156
self.run_bzr('commit', '-m', 'xyz', 'hello')
157
self.run_bzr('revert', '-r', '1', 'hello')
159
self.run_bzr('commit -m xyz hello')
160
self.run_bzr('revert -r 1 hello')
158
161
self.check_file_contents('hello', 'foo')
159
self.run_bzr('revert', 'hello')
162
self.run_bzr('revert hello')
160
163
self.check_file_contents('hello', 'xyz')
161
164
os.chdir('revertdir')
162
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)
190
def test_revert_forget_merges(self):
191
# revert --forget-merges removes any pending merges into the tree, but
192
# leaves the files unchanged
193
tree = self.make_branch_and_tree('.')
194
# forget-merges before first commit, though pointless, does not fail
195
self.run_bzr(['revert', '--forget-merges'])
196
self.build_tree(['file'])
197
first_rev_id = tree.commit('initial commit')
198
self.build_tree_contents([('file', 'new content')])
199
existing_parents = tree.get_parent_ids()
200
self.assertEquals([first_rev_id], existing_parents)
201
merged_parents = existing_parents + ['merged-in-rev']
202
tree.set_parent_ids(merged_parents)
203
self.assertEquals(merged_parents, tree.get_parent_ids())
204
self.run_bzr(['revert', '--forget-merges'])
205
self.assertEquals([first_rev_id], tree.get_parent_ids())
206
# changed files are not reverted
207
self.assertFileEqual('new content', 'file')
208
# you can give it the path of a tree
209
self.run_bzr(['revert', '--forget-merges', tree.abspath('.')])