/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
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
"""Couple of blackbox tests for the rebase plugin."""
17
0.436.42 by Jelmer Vernooij
Support the -r argument to rebase.
18
from bzrlib.branch import Branch
0.436.19 by Jelmer Vernooij
- Add blackbox tests
19
from bzrlib.tests.blackbox import ExternalBase
20
21
import os
22
23
class TestRebaseSimple(ExternalBase):
24
    def make_file(self, name, contents):
25
        f = open(name, 'wb')
26
        try:
27
            f.write(contents)
28
        finally:
29
            f.close()
30
31
    def setUp(self):
32
        super(TestRebaseSimple, self).setUp()
33
        os.mkdir('main')
34
        os.chdir('main')
35
        self.run_bzr('init')
36
        self.make_file('hello', "hi world")
37
        self.run_bzr('add')
38
        self.run_bzr('commit -m bla')
39
        self.run_bzr('branch . ../feature')
40
41
    def test_notneeded(self):
42
        os.chdir('../feature')
0.436.77 by Jelmer Vernooij
Fix test.
43
        self.check_output('No revisions to rebase.\n', 'rebase ../main')
0.436.19 by Jelmer Vernooij
- Add blackbox tests
44
45
    def test_simple_success(self):
46
        self.make_file('hello', '42')
47
        self.run_bzr('commit -m that')
48
        os.chdir('../feature')
49
        self.make_file('hoi', "my data")
50
        self.run_bzr('add')
51
        self.run_bzr('commit -m this')
52
        self.check_output('', 'rebase ../main')
53
        self.check_output('3\n', 'revno')
0.436.20 by Jelmer Vernooij
Some more blackbox tests.
54
0.436.42 by Jelmer Vernooij
Support the -r argument to rebase.
55
    def test_range(self):
56
        self.make_file('hello', '42')
57
        self.run_bzr('commit -m that')
58
        os.chdir('../feature')
59
        self.make_file('hoi', "my data")
60
        self.run_bzr('add')
61
        self.run_bzr('commit -m this')
62
        self.make_file('hooi', "your data")
63
        self.run_bzr('add')
64
        self.run_bzr('commit -m that')
65
        self.make_file('hoooi', "someone else's data")
66
        self.run_bzr('add')
67
        self.run_bzr('commit -m these')
68
        self.check_output('', 'rebase -r2..3 ../main')
69
        self.check_output('4\n', 'revno')
70
71
    def test_range_open_end(self):
72
        self.make_file('hello', '42')
73
        self.run_bzr('commit -m that')
74
        os.chdir('../feature')
75
        self.make_file('hoi', "my data")
76
        self.run_bzr('add')
77
        self.run_bzr('commit -m this')
78
        self.make_file('hooi', "your data")
79
        self.run_bzr('add')
80
        self.run_bzr('commit -m that')
81
        self.make_file('hoooi', "someone else's data")
82
        self.run_bzr('add')
83
        self.run_bzr('commit -m these')
84
        self.check_output('', 'rebase -r4.. ../main')
85
        self.check_output('3\n', 'revno')
86
        branch = Branch.open(".")
87
        self.assertEquals("these", 
88
            branch.repository.get_revision(branch.last_revision()).message)
89
0.436.20 by Jelmer Vernooij
Some more blackbox tests.
90
    def test_conflicting(self):
91
        self.make_file('hello', '42')
92
        self.run_bzr('commit -m that')
93
        os.chdir('../feature')
94
        self.make_file('hello', "other data")
95
        self.run_bzr('commit -m this')
96
        self.run_bzr_error('Text conflict in hello\nbzr: ERROR: A conflict occurred replaying a commit. Resolve the conflict and run \'bzr rebase-continue\' or run \'bzr rebase-abort\'.\n', 'rebase ../main')
97
98
    def test_conflicting_abort(self):
99
        self.make_file('hello', '42')
100
        self.run_bzr('commit -m that')
101
        os.chdir('../feature')
102
        self.make_file('hello', "other data")
103
        self.run_bzr('commit -m this')
104
        old_log = self.run_bzr('log')[0]
105
        self.run_bzr_error('Text conflict in hello\nbzr: ERROR: A conflict occurred replaying a commit. Resolve the conflict and run \'bzr rebase-continue\' or run \'bzr rebase-abort\'.\n', 'rebase ../main')
106
        self.check_output('', 'rebase-abort')
107
        self.check_output(old_log, 'log')
108
109
    def test_conflicting_continue(self):
110
        self.make_file('hello', '42')
111
        self.run_bzr('commit -m that')
112
        os.chdir('../feature')
113
        self.make_file('hello', "other data")
114
        self.run_bzr('commit -m this')
115
        self.run_bzr_error('Text conflict in hello\nbzr: ERROR: A conflict occurred replaying a commit. Resolve the conflict and run \'bzr rebase-continue\' or run \'bzr rebase-abort\'.\n', 'rebase ../main')
116
        self.run_bzr('resolved hello')
117
        self.check_output('', 'rebase-continue')
118
        self.check_output('3\n', 'revno')
119
120
    def test_continue_nothing(self):
121
        self.run_bzr_error('bzr: ERROR: No rebase to continue', 
122
                           'rebase-continue')
123
124
    def test_abort_nothing(self):
125
        self.run_bzr_error('bzr: ERROR: No rebase to abort', 
126
                           'rebase-abort')
127
0.436.21 by Jelmer Vernooij
Tests.
128
    def test_todo_nothing(self):
129
        self.run_bzr_error('bzr: ERROR: No rebase in progress', 
130
                           'rebase-todo')
0.437.2 by James Westby
Lookup the onto revision in the upstream branch.
131
132
    def test_onto(self):
133
        self.make_file('hello', '42')
134
        self.run_bzr('add')
135
        self.run_bzr('commit -m that')
136
        self.make_file('other', '43')
137
        self.run_bzr('add')
138
        self.run_bzr('commit -m that_other')
139
        os.chdir('../feature')
140
        self.make_file('hoi', "my data")
141
        self.run_bzr('add')
142
        self.run_bzr('commit -m this')
143
        self.check_output('', 'rebase --onto -2 ../main')
144
        self.check_output('3\n', 'revno')
145
0.436.51 by Jelmer Vernooij
Give proper warning when there is no common base.
146
    def test_unrelated(self):
147
        os.chdir('..')
148
        os.mkdir('unrelated')
149
        os.chdir('unrelated')
150
        self.run_bzr('init')
151
        self.make_file('hello', "hi world")
152
        self.run_bzr('add')
153
        self.run_bzr('commit -m x')
154
        self.run_bzr_error(['bzr: ERROR: Branches have no common ancestor, and no merge base.*'],
155
                           'rebase ../main')
156
0.437.4 by James Westby
Import rebase_todo as it is needed for --verbose.
157
    def test_verbose(self):
158
        self.make_file('hello', '42')
159
        self.run_bzr('commit -m that')
160
        os.chdir('../feature')
161
        self.make_file('hoi', "my data")
162
        self.run_bzr('add')
163
        self.run_bzr('commit -m this')
164
        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).
165
        self.assertContainsRe(err, '1 revisions will be rebased:')
0.437.4 by James Westby
Import rebase_todo as it is needed for --verbose.
166
        self.assertEqual('', out)
167
        self.check_output('3\n', 'revno')
168
0.436.30 by Jelmer Vernooij
Add test demonstrating issues rebasing revisions with multiple parents. (maybe same cause as #126743).
169
    def test_useless_merge(self):
170
        self.make_file('bar', '42')
171
        self.run_bzr('add')
172
        self.run_bzr('commit -m that')
173
        os.chdir('../feature')
174
        self.make_file('hello', "my data")
175
        self.run_bzr('commit -m this')
176
        self.run_bzr('merge')
177
        self.run_bzr('commit -m merge')
178
        self.run_bzr('rebase')
0.436.63 by Jelmer Vernooij
Fix replay command, add test.
179
180
class ReplayTests(ExternalBase):
181
    def test_replay(self):
182
        os.mkdir('main')
183
        os.chdir('main')
184
        self.run_bzr('init')
185
        open('bar', 'w').write('42')
186
        self.run_bzr('add')
187
        self.run_bzr('commit -m that')
188
        os.mkdir('../feature')
189
        os.chdir('../feature')
190
        self.run_bzr('init')
191
        branch = Branch.open('.')
192
        open('hello', 'w').write("my data")
193
        self.run_bzr('add')
194
        self.run_bzr('commit -m this')
195
        self.assertEquals(1, len(branch.revision_history()))
196
        self.run_bzr('replay -r1 ../main')
197
        self.assertEquals(2, len(branch.revision_history()))
198
        self.assertTrue(os.path.exists('bar'))
0.436.64 by Jelmer Vernooij
Support revision ranges to replay.
199
200
class ReplayTests(ExternalBase):
201
    def test_replay(self):
202
        os.mkdir('main')
203
        os.chdir('main')
204
        self.run_bzr('init')
205
        open('bar', 'w').write('42')
206
        self.run_bzr('add')
207
        self.run_bzr('commit -m that')
208
        open('bar', 'w').write('84')
209
        self.run_bzr('commit -m blathat')
210
        os.mkdir('../feature')
211
        os.chdir('../feature')
212
        self.run_bzr('init')
213
        branch = Branch.open('.')
214
        open('hello', 'w').write("my data")
215
        self.run_bzr('add')
216
        self.run_bzr('commit -m this')
217
        self.assertEquals(1, len(branch.revision_history()))
218
        self.run_bzr('replay -r1.. ../main')
219
        self.assertEquals(3, len(branch.revision_history()))
220
        self.assertTrue(os.path.exists('bar'))