/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.436.30 by Jelmer Vernooij
Add test demonstrating issues rebasing revisions with multiple parents. (maybe same cause as #126743).
1
# Copyright (C) 2007 by Jelmer Vernooij <jelmer@samba.org>
0.436.19 by Jelmer Vernooij
- Add blackbox tests
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
0.436.131 by Jelmer Vernooij
Change license back to GPLv2+
5
# the Free Software Foundation; either version 2 of the License, or
0.436.19 by Jelmer Vernooij
- Add blackbox tests
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
0.441.4 by Robert Collins
* Fixed O(history) access during plan creation (Robert Collins, lp:#249823).
16
0.436.19 by Jelmer Vernooij
- Add blackbox tests
17
"""Couple of blackbox tests for the rebase plugin."""
18
0.436.157 by Jelmer Vernooij
use absolute imports everywhere.
19
import os
20
0.436.42 by Jelmer Vernooij
Support the -r argument to rebase.
21
from bzrlib.branch import Branch
0.436.19 by Jelmer Vernooij
- Add blackbox tests
22
from bzrlib.tests.blackbox import ExternalBase
23
24
class TestRebaseSimple(ExternalBase):
0.441.4 by Robert Collins
* Fixed O(history) access during plan creation (Robert Collins, lp:#249823).
25
0.436.19 by Jelmer Vernooij
- Add blackbox tests
26
    def make_file(self, name, contents):
27
        f = open(name, 'wb')
28
        try:
29
            f.write(contents)
30
        finally:
31
            f.close()
32
33
    def setUp(self):
34
        super(TestRebaseSimple, self).setUp()
35
        os.mkdir('main')
36
        os.chdir('main')
37
        self.run_bzr('init')
38
        self.make_file('hello', "hi world")
39
        self.run_bzr('add')
40
        self.run_bzr('commit -m bla')
41
        self.run_bzr('branch . ../feature')
42
43
    def test_notneeded(self):
44
        os.chdir('../feature')
0.436.77 by Jelmer Vernooij
Fix test.
45
        self.check_output('No revisions to rebase.\n', 'rebase ../main')
0.436.19 by Jelmer Vernooij
- Add blackbox tests
46
0.436.92 by Jelmer Vernooij
Handle case where base branch is descendant of current branch.
47
    def test_notneeded_feature_ahead(self):
48
        os.chdir('../feature')
49
        self.make_file('barbla', "bloe")
50
        self.run_bzr('add')
51
        self.run_bzr('commit -m bloe')
52
        self.check_output('No revisions to rebase.\n', 'rebase ../main')
53
54
    def test_notneeded_main_ahead(self):
55
        self.make_file('barbla', "bloe")
56
        self.run_bzr('add')
57
        self.run_bzr('commit -m bloe')
58
        os.chdir('../feature')
0.436.105 by Jelmer Vernooij
Rebase if we can't pull.
59
        self.check_output("Base branch is descendant of current branch. Pulling instead.\n", 'rebase ../main')
60
        self.assertEquals(Branch.open("../feature").revision_history(), 
61
                          Branch.open("../main").revision_history())
0.436.92 by Jelmer Vernooij
Handle case where base branch is descendant of current branch.
62
0.436.84 by Jelmer Vernooij
Support rebasing pending merges.
63
    def test_no_pending_merges(self):
0.436.147 by Jelmer Vernooij
Fix tests against bzr.dev.
64
        self.run_bzr_error(['bzr: ERROR: No pending merges present.\n'], 
65
                           ['rebase', '--pending-merges'])
0.436.84 by Jelmer Vernooij
Support rebasing pending merges.
66
67
    def test_pending_merges(self):
0.441.3 by Robert Collins
Update rebase to 1.6b3 API changes.
68
        os.chdir('..')
69
        self.build_tree_contents([('main/hello', '42')])
70
        self.run_bzr('add', working_dir='main')
71
        self.run_bzr('commit -m that main')
72
        self.build_tree_contents([('feature/hoi', 'my data')])
73
        self.run_bzr('add', working_dir='feature')
74
        self.run_bzr('commit -m this feature')
75
        self.assertEqual(('', ' M  hello\nAll changes applied successfully.\n'),
76
            self.run_bzr('merge ../main', working_dir='feature'))
77
        out, err = self.run_bzr('rebase --pending-merges', working_dir='feature')
78
        self.assertEqual('', out)
79
        self.assertContainsRe(err, 'modified hello')
80
        self.assertEqual(('3\n', ''),
81
            self.run_bzr('revno', working_dir='feature'))
0.436.84 by Jelmer Vernooij
Support rebasing pending merges.
82
0.436.19 by Jelmer Vernooij
- Add blackbox tests
83
    def test_simple_success(self):
84
        self.make_file('hello', '42')
85
        self.run_bzr('commit -m that')
86
        os.chdir('../feature')
87
        self.make_file('hoi', "my data")
88
        self.run_bzr('add')
89
        self.run_bzr('commit -m this')
90
        self.check_output('', 'rebase ../main')
91
        self.check_output('3\n', 'revno')
0.436.20 by Jelmer Vernooij
Some more blackbox tests.
92
0.436.42 by Jelmer Vernooij
Support the -r argument to rebase.
93
    def test_range(self):
0.441.4 by Robert Collins
* Fixed O(history) access during plan creation (Robert Collins, lp:#249823).
94
        # commit mainline rev 2
0.436.42 by Jelmer Vernooij
Support the -r argument to rebase.
95
        self.make_file('hello', '42')
96
        self.run_bzr('commit -m that')
0.441.4 by Robert Collins
* Fixed O(history) access during plan creation (Robert Collins, lp:#249823).
97
        # commit feature rev 2
0.436.42 by Jelmer Vernooij
Support the -r argument to rebase.
98
        os.chdir('../feature')
99
        self.make_file('hoi', "my data")
100
        self.run_bzr('add')
101
        self.run_bzr('commit -m this')
0.441.4 by Robert Collins
* Fixed O(history) access during plan creation (Robert Collins, lp:#249823).
102
        # commit feature rev 3
0.436.42 by Jelmer Vernooij
Support the -r argument to rebase.
103
        self.make_file('hooi', "your data")
104
        self.run_bzr('add')
105
        self.run_bzr('commit -m that')
0.441.4 by Robert Collins
* Fixed O(history) access during plan creation (Robert Collins, lp:#249823).
106
        # commit feature rev 4
0.436.42 by Jelmer Vernooij
Support the -r argument to rebase.
107
        self.make_file('hoooi', "someone else's data")
108
        self.run_bzr('add')
109
        self.run_bzr('commit -m these')
0.441.4 by Robert Collins
* Fixed O(history) access during plan creation (Robert Collins, lp:#249823).
110
        # pick up just rev 2 and discard 3 & 4 from feature
0.436.42 by Jelmer Vernooij
Support the -r argument to rebase.
111
        self.check_output('', 'rebase -r2..3 ../main')
0.441.4 by Robert Collins
* Fixed O(history) access during plan creation (Robert Collins, lp:#249823).
112
        # our rev 2 is now rev3:
113
        self.check_output('3\n', 'revno')
114
        # content added from our old revisions 3 and 4 should be gone.
115
        self.failIfExists('hooi')
116
        self.failIfExists('hoooi')
0.436.42 by Jelmer Vernooij
Support the -r argument to rebase.
117
118
    def test_range_open_end(self):
0.441.4 by Robert Collins
* Fixed O(history) access during plan creation (Robert Collins, lp:#249823).
119
        # commit mainline rev 2
0.436.42 by Jelmer Vernooij
Support the -r argument to rebase.
120
        self.make_file('hello', '42')
121
        self.run_bzr('commit -m that')
0.441.4 by Robert Collins
* Fixed O(history) access during plan creation (Robert Collins, lp:#249823).
122
        # commit feature rev 2
0.436.42 by Jelmer Vernooij
Support the -r argument to rebase.
123
        os.chdir('../feature')
124
        self.make_file('hoi', "my data")
125
        self.run_bzr('add')
126
        self.run_bzr('commit -m this')
0.441.4 by Robert Collins
* Fixed O(history) access during plan creation (Robert Collins, lp:#249823).
127
        # commit feature rev 3
0.436.42 by Jelmer Vernooij
Support the -r argument to rebase.
128
        self.make_file('hooi', "your data")
129
        self.run_bzr('add')
130
        self.run_bzr('commit -m that')
0.441.4 by Robert Collins
* Fixed O(history) access during plan creation (Robert Collins, lp:#249823).
131
        # commit feature rev 4
0.436.42 by Jelmer Vernooij
Support the -r argument to rebase.
132
        self.make_file('hoooi', "someone else's data")
133
        self.run_bzr('add')
134
        self.run_bzr('commit -m these')
0.441.4 by Robert Collins
* Fixed O(history) access during plan creation (Robert Collins, lp:#249823).
135
        # rebase only rev 4 onto main
0.436.42 by Jelmer Vernooij
Support the -r argument to rebase.
136
        self.check_output('', 'rebase -r4.. ../main')
0.441.4 by Robert Collins
* Fixed O(history) access during plan creation (Robert Collins, lp:#249823).
137
        # should only get rev 3 (our old 2 and 3 are gone)
0.436.42 by Jelmer Vernooij
Support the -r argument to rebase.
138
        self.check_output('3\n', 'revno')
0.441.4 by Robert Collins
* Fixed O(history) access during plan creation (Robert Collins, lp:#249823).
139
        self.failIfExists('hoi')
140
        self.failIfExists('hooi')
0.436.42 by Jelmer Vernooij
Support the -r argument to rebase.
141
        branch = Branch.open(".")
0.441.4 by Robert Collins
* Fixed O(history) access during plan creation (Robert Collins, lp:#249823).
142
        self.assertEquals("these",
0.436.42 by Jelmer Vernooij
Support the -r argument to rebase.
143
            branch.repository.get_revision(branch.last_revision()).message)
0.441.4 by Robert Collins
* Fixed O(history) access during plan creation (Robert Collins, lp:#249823).
144
        self.failUnlessExists('hoooi')
0.436.42 by Jelmer Vernooij
Support the -r argument to rebase.
145
0.436.20 by Jelmer Vernooij
Some more blackbox tests.
146
    def test_conflicting(self):
0.441.4 by Robert Collins
* Fixed O(history) access during plan creation (Robert Collins, lp:#249823).
147
        # commit mainline rev 2
0.436.20 by Jelmer Vernooij
Some more blackbox tests.
148
        self.make_file('hello', '42')
149
        self.run_bzr('commit -m that')
0.441.4 by Robert Collins
* Fixed O(history) access during plan creation (Robert Collins, lp:#249823).
150
        # commit feature rev 2 changing hello differently
0.436.20 by Jelmer Vernooij
Some more blackbox tests.
151
        os.chdir('../feature')
152
        self.make_file('hello', "other data")
153
        self.run_bzr('commit -m this')
0.441.4 by Robert Collins
* Fixed O(history) access during plan creation (Robert Collins, lp:#249823).
154
        self.run_bzr_error([
0.436.147 by Jelmer Vernooij
Fix tests against bzr.dev.
155
            'Text conflict in hello\n1 conflicts encountered.\nbzr: ERROR: A conflict occurred replaying a commit. Resolve the conflict and run \'bzr rebase-continue\' or run \'bzr rebase-abort\'.',
156
            ], ['rebase', '../main'])
0.436.20 by Jelmer Vernooij
Some more blackbox tests.
157
158
    def test_conflicting_abort(self):
159
        self.make_file('hello', '42')
160
        self.run_bzr('commit -m that')
161
        os.chdir('../feature')
162
        self.make_file('hello', "other data")
163
        self.run_bzr('commit -m this')
164
        old_log = self.run_bzr('log')[0]
0.436.147 by Jelmer Vernooij
Fix tests against bzr.dev.
165
        self.run_bzr_error(['Text conflict in hello\n1 conflicts encountered.\nbzr: ERROR: A conflict occurred replaying a commit. Resolve the conflict and run \'bzr rebase-continue\' or run \'bzr rebase-abort\'.\n'], ['rebase', '../main'])
0.436.20 by Jelmer Vernooij
Some more blackbox tests.
166
        self.check_output('', 'rebase-abort')
167
        self.check_output(old_log, 'log')
168
169
    def test_conflicting_continue(self):
170
        self.make_file('hello', '42')
171
        self.run_bzr('commit -m that')
172
        os.chdir('../feature')
173
        self.make_file('hello', "other data")
174
        self.run_bzr('commit -m this')
0.436.147 by Jelmer Vernooij
Fix tests against bzr.dev.
175
        self.run_bzr_error(['Text conflict in hello\n1 conflicts encountered.\nbzr: ERROR: A conflict occurred replaying a commit. Resolve the conflict and run \'bzr rebase-continue\' or run \'bzr rebase-abort\'.\n'], ['rebase', '../main'])
0.436.20 by Jelmer Vernooij
Some more blackbox tests.
176
        self.run_bzr('resolved hello')
177
        self.check_output('', 'rebase-continue')
178
        self.check_output('3\n', 'revno')
179
180
    def test_continue_nothing(self):
0.436.147 by Jelmer Vernooij
Fix tests against bzr.dev.
181
        self.run_bzr_error(['bzr: ERROR: No rebase to continue'], 
182
                           ['rebase-continue'])
0.436.20 by Jelmer Vernooij
Some more blackbox tests.
183
184
    def test_abort_nothing(self):
0.436.147 by Jelmer Vernooij
Fix tests against bzr.dev.
185
        self.run_bzr_error(['bzr: ERROR: No rebase to abort'], 
186
                           ['rebase-abort'])
0.436.20 by Jelmer Vernooij
Some more blackbox tests.
187
0.436.21 by Jelmer Vernooij
Tests.
188
    def test_todo_nothing(self):
0.436.147 by Jelmer Vernooij
Fix tests against bzr.dev.
189
        self.run_bzr_error(['bzr: ERROR: No rebase in progress'], 
190
                           ['rebase-todo'])
0.437.2 by James Westby
Lookup the onto revision in the upstream branch.
191
192
    def test_onto(self):
193
        self.make_file('hello', '42')
194
        self.run_bzr('add')
195
        self.run_bzr('commit -m that')
196
        self.make_file('other', '43')
197
        self.run_bzr('add')
198
        self.run_bzr('commit -m that_other')
199
        os.chdir('../feature')
200
        self.make_file('hoi', "my data")
201
        self.run_bzr('add')
202
        self.run_bzr('commit -m this')
203
        self.check_output('', 'rebase --onto -2 ../main')
204
        self.check_output('3\n', 'revno')
205
0.436.51 by Jelmer Vernooij
Give proper warning when there is no common base.
206
    def test_unrelated(self):
207
        os.chdir('..')
208
        os.mkdir('unrelated')
209
        os.chdir('unrelated')
210
        self.run_bzr('init')
211
        self.make_file('hello', "hi world")
212
        self.run_bzr('add')
213
        self.run_bzr('commit -m x')
214
        self.run_bzr_error(['bzr: ERROR: Branches have no common ancestor, and no merge base.*'],
0.436.147 by Jelmer Vernooij
Fix tests against bzr.dev.
215
                           ['rebase', '../main'])
0.436.51 by Jelmer Vernooij
Give proper warning when there is no common base.
216
0.437.4 by James Westby
Import rebase_todo as it is needed for --verbose.
217
    def test_verbose(self):
218
        self.make_file('hello', '42')
219
        self.run_bzr('commit -m that')
220
        os.chdir('../feature')
221
        self.make_file('hoi', "my data")
222
        self.run_bzr('add')
223
        self.run_bzr('commit -m this')
224
        out, err = self.run_bzr('rebase -v ../main')
0.436.30 by Jelmer Vernooij
Add test demonstrating issues rebasing revisions with multiple parents. (maybe same cause as #126743).
225
        self.assertContainsRe(err, '1 revisions will be rebased:')
0.437.4 by James Westby
Import rebase_todo as it is needed for --verbose.
226
        self.assertEqual('', out)
227
        self.check_output('3\n', 'revno')
228
0.436.30 by Jelmer Vernooij
Add test demonstrating issues rebasing revisions with multiple parents. (maybe same cause as #126743).
229
    def test_useless_merge(self):
230
        self.make_file('bar', '42')
231
        self.run_bzr('add')
232
        self.run_bzr('commit -m that')
233
        os.chdir('../feature')
234
        self.make_file('hello', "my data")
235
        self.run_bzr('commit -m this')
236
        self.run_bzr('merge')
237
        self.run_bzr('commit -m merge')
238
        self.run_bzr('rebase')
0.436.63 by Jelmer Vernooij
Fix replay command, add test.
239
240
class ReplayTests(ExternalBase):
241
    def test_replay(self):
242
        os.mkdir('main')
243
        os.chdir('main')
244
        self.run_bzr('init')
245
        open('bar', 'w').write('42')
246
        self.run_bzr('add')
247
        self.run_bzr('commit -m that')
248
        os.mkdir('../feature')
249
        os.chdir('../feature')
250
        self.run_bzr('init')
251
        branch = Branch.open('.')
252
        open('hello', 'w').write("my data")
253
        self.run_bzr('add')
254
        self.run_bzr('commit -m this')
255
        self.assertEquals(1, len(branch.revision_history()))
256
        self.run_bzr('replay -r1 ../main')
257
        self.assertEquals(2, len(branch.revision_history()))
258
        self.assertTrue(os.path.exists('bar'))
0.436.64 by Jelmer Vernooij
Support revision ranges to replay.
259
260
class ReplayTests(ExternalBase):
261
    def test_replay(self):
262
        os.mkdir('main')
263
        os.chdir('main')
264
        self.run_bzr('init')
265
        open('bar', 'w').write('42')
266
        self.run_bzr('add')
267
        self.run_bzr('commit -m that')
268
        open('bar', 'w').write('84')
269
        self.run_bzr('commit -m blathat')
270
        os.mkdir('../feature')
271
        os.chdir('../feature')
272
        self.run_bzr('init')
273
        branch = Branch.open('.')
274
        open('hello', 'w').write("my data")
275
        self.run_bzr('add')
276
        self.run_bzr('commit -m this')
277
        self.assertEquals(1, len(branch.revision_history()))
278
        self.run_bzr('replay -r1.. ../main')
279
        self.assertEquals(3, len(branch.revision_history()))
280
        self.assertTrue(os.path.exists('bar'))