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