/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1185.50.5 by John Arbash Meinel
pull --overwrite should always overwrite, not just if diverged. (Test case from Robey Pointer)
1
# Copyright (C) 2005 by Canonical Ltd
2
# -*- coding: utf-8 -*-
3
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
8
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
18
1666.1.5 by Robert Collins
Merge bound branch test performance improvements.
19
"""Black-box tests for bzr pull."""
1185.50.5 by John Arbash Meinel
pull --overwrite should always overwrite, not just if diverged. (Test case from Robey Pointer)
20
21
import os
22
import sys
23
24
from bzrlib.branch import Branch
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
25
from bzrlib.osutils import abspath
1185.50.5 by John Arbash Meinel
pull --overwrite should always overwrite, not just if diverged. (Test case from Robey Pointer)
26
from bzrlib.tests.blackbox import ExternalBase
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
27
from bzrlib.uncommit import uncommit
1614.2.8 by Olaf Conradi
Added testcases for using pull with --remember. Moved remember code to
28
1185.50.5 by John Arbash Meinel
pull --overwrite should always overwrite, not just if diverged. (Test case from Robey Pointer)
29
1185.50.7 by John Arbash Meinel
Fix broken test from refactoring blackbox/test_pull
30
class TestPull(ExternalBase):
31
32
    def example_branch(test):
33
        test.runbzr('init')
34
        file('hello', 'wt').write('foo')
35
        test.runbzr('add hello')
36
        test.runbzr('commit -m setup hello')
37
        file('goodbye', 'wt').write('baz')
38
        test.runbzr('add goodbye')
39
        test.runbzr('commit -m setup goodbye')
1185.50.5 by John Arbash Meinel
pull --overwrite should always overwrite, not just if diverged. (Test case from Robey Pointer)
40
41
    def test_pull(self):
42
        """Pull changes from one branch to another."""
43
        os.mkdir('a')
44
        os.chdir('a')
45
46
        self.example_branch()
47
        self.runbzr('pull', retcode=3)
48
        self.runbzr('missing', retcode=3)
49
        self.runbzr('missing .')
50
        self.runbzr('missing')
1666.1.5 by Robert Collins
Merge bound branch test performance improvements.
51
        # this will work on windows because we check for the same branch
52
        # in pull - if it fails, it is a regression
53
        self.runbzr('pull')
1185.50.5 by John Arbash Meinel
pull --overwrite should always overwrite, not just if diverged. (Test case from Robey Pointer)
54
        self.runbzr('pull /', retcode=3)
1185.31.31 by John Arbash Meinel
avoiding 'bzr pull .' means all tests pass under cygwin
55
        if sys.platform not in ('win32', 'cygwin'):
56
            self.runbzr('pull')
1185.50.5 by John Arbash Meinel
pull --overwrite should always overwrite, not just if diverged. (Test case from Robey Pointer)
57
58
        os.chdir('..')
59
        self.runbzr('branch a b')
60
        os.chdir('b')
61
        self.runbzr('pull')
62
        os.mkdir('subdir')
63
        self.runbzr('add subdir')
64
        self.runbzr('commit -m blah --unchanged')
65
        os.chdir('../a')
66
        a = Branch.open('.')
67
        b = Branch.open('../b')
68
        self.assertEquals(a.revision_history(), b.revision_history()[:-1])
69
        self.runbzr('pull ../b')
70
        self.assertEquals(a.revision_history(), b.revision_history())
71
        self.runbzr('commit -m blah2 --unchanged')
72
        os.chdir('../b')
73
        self.runbzr('commit -m blah3 --unchanged')
74
        # no overwrite
75
        self.runbzr('pull ../a', retcode=3)
76
        os.chdir('..')
77
        self.runbzr('branch b overwriteme')
78
        os.chdir('overwriteme')
79
        self.runbzr('pull --overwrite ../a')
80
        overwritten = Branch.open('.')
81
        self.assertEqual(overwritten.revision_history(),
82
                         a.revision_history())
83
        os.chdir('../a')
84
        self.runbzr('merge ../b')
85
        self.runbzr('commit -m blah4 --unchanged')
86
        os.chdir('../b/subdir')
87
        self.runbzr('pull ../../a')
88
        self.assertEquals(a.revision_history()[-1], b.revision_history()[-1])
89
        self.runbzr('commit -m blah5 --unchanged')
90
        self.runbzr('commit -m blah6 --unchanged')
91
        os.chdir('..')
92
        self.runbzr('pull ../a')
93
        os.chdir('../a')
94
        self.runbzr('commit -m blah7 --unchanged')
95
        self.runbzr('merge ../b')
96
        self.runbzr('commit -m blah8 --unchanged')
97
        self.runbzr('pull ../b')
98
        self.runbzr('pull ../b')
99
1185.76.2 by Erik Bågfors
test for pull --revision
100
    def test_pull_revision(self):
101
        """Pull some changes from one branch to another."""
102
        os.mkdir('a')
103
        os.chdir('a')
104
105
        self.example_branch()
106
        file('hello2', 'wt').write('foo')
107
        self.runbzr('add hello2')
108
        self.runbzr('commit -m setup hello2')
109
        file('goodbye2', 'wt').write('baz')
110
        self.runbzr('add goodbye2')
111
        self.runbzr('commit -m setup goodbye2')
112
113
        os.chdir('..')
114
        self.runbzr('branch -r 1 a b')
115
        os.chdir('b')
116
        self.runbzr('pull -r 2')
117
        a = Branch.open('../a')
118
        b = Branch.open('.')
1185.76.4 by Erik Bågfors
expanded tabs
119
        self.assertEquals(a.revno(),4)
120
        self.assertEquals(b.revno(),2)
1185.76.2 by Erik Bågfors
test for pull --revision
121
        self.runbzr('pull -r 3')
1185.76.4 by Erik Bågfors
expanded tabs
122
        self.assertEquals(b.revno(),3)
1185.76.2 by Erik Bågfors
test for pull --revision
123
        self.runbzr('pull -r 4')
124
        self.assertEquals(a.revision_history(), b.revision_history())
125
126
1185.50.7 by John Arbash Meinel
Fix broken test from refactoring blackbox/test_pull
127
    def test_overwrite_uptodate(self):
1185.50.5 by John Arbash Meinel
pull --overwrite should always overwrite, not just if diverged. (Test case from Robey Pointer)
128
        # Make sure pull --overwrite overwrites
129
        # even if the target branch has merged
130
        # everything already.
131
        bzr = self.run_bzr
132
133
        def get_rh(expected_len):
134
            rh = self.capture('revision-history')
135
            # Make sure we don't have trailing empty revisions
136
            rh = rh.strip().split('\n')
137
            self.assertEqual(len(rh), expected_len)
138
            return rh
139
140
        os.mkdir('a')
141
        os.chdir('a')
142
        bzr('init')
143
        open('foo', 'wb').write('original\n')
144
        bzr('add', 'foo')
145
        bzr('commit', '-m', 'initial commit')
146
147
        os.chdir('..')
148
        bzr('branch', 'a', 'b')
149
150
        os.chdir('a')
151
        open('foo', 'wb').write('changed\n')
152
        bzr('commit', '-m', 'later change')
153
154
        open('foo', 'wb').write('another\n')
155
        bzr('commit', '-m', 'a third change')
156
157
        rev_history_a = get_rh(3)
158
159
        os.chdir('../b')
160
        bzr('merge', '../a')
161
        bzr('commit', '-m', 'merge')
162
163
        rev_history_b = get_rh(2)
164
165
        bzr('pull', '--overwrite', '../a')
166
        rev_history_b = get_rh(3)
167
168
        self.assertEqual(rev_history_b, rev_history_a)
169
1185.50.7 by John Arbash Meinel
Fix broken test from refactoring blackbox/test_pull
170
    def test_overwrite_children(self):
1185.50.5 by John Arbash Meinel
pull --overwrite should always overwrite, not just if diverged. (Test case from Robey Pointer)
171
        # Make sure pull --overwrite sets the revision-history
172
        # to be identical to the pull source, even if we have convergence
173
        bzr = self.run_bzr
174
175
        def get_rh(expected_len):
176
            rh = self.capture('revision-history')
177
            # Make sure we don't have trailing empty revisions
178
            rh = rh.strip().split('\n')
179
            self.assertEqual(len(rh), expected_len)
180
            return rh
181
182
        os.mkdir('a')
183
        os.chdir('a')
184
        bzr('init')
185
        open('foo', 'wb').write('original\n')
186
        bzr('add', 'foo')
187
        bzr('commit', '-m', 'initial commit')
188
189
        os.chdir('..')
190
        bzr('branch', 'a', 'b')
191
192
        os.chdir('a')
193
        open('foo', 'wb').write('changed\n')
194
        bzr('commit', '-m', 'later change')
195
196
        open('foo', 'wb').write('another\n')
197
        bzr('commit', '-m', 'a third change')
198
199
        rev_history_a = get_rh(3)
200
201
        os.chdir('../b')
202
        bzr('merge', '../a')
203
        bzr('commit', '-m', 'merge')
204
205
        rev_history_b = get_rh(2)
206
207
        os.chdir('../a')
208
        open('foo', 'wb').write('a fourth change\n')
209
        bzr('commit', '-m', 'a fourth change')
210
211
        rev_history_a = get_rh(4)
212
213
        # With convergence, we could just pull over the
214
        # new change, but with --overwrite, we want to switch our history
215
        os.chdir('../b')
216
        bzr('pull', '--overwrite', '../a')
217
        rev_history_b = get_rh(4)
218
219
        self.assertEqual(rev_history_b, rev_history_a)
220
1614.2.8 by Olaf Conradi
Added testcases for using pull with --remember. Moved remember code to
221
    def test_pull_remember(self):
222
        """Pull changes from one branch to another and test parent location."""
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
223
        transport = self.get_transport()
224
        tree_a = self.make_branch_and_tree('branch_a')
225
        branch_a = tree_a.branch
226
        self.build_tree(['branch_a/a'])
227
        tree_a.add('a')
228
        tree_a.commit('commit a')
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
229
        tree_b = branch_a.bzrdir.sprout('branch_b').open_workingtree()
230
        branch_b = tree_b.branch
231
        tree_c = branch_a.bzrdir.sprout('branch_c').open_workingtree()
232
        branch_c = tree_c.branch
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
233
        self.build_tree(['branch_a/b'])
234
        tree_a.add('b')
235
        tree_a.commit('commit b')
1614.2.8 by Olaf Conradi
Added testcases for using pull with --remember. Moved remember code to
236
        # reset parent
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
237
        parent = branch_b.get_parent()
238
        branch_b.set_parent(None)
239
        self.assertEqual(None, branch_b.get_parent())
1614.2.8 by Olaf Conradi
Added testcases for using pull with --remember. Moved remember code to
240
        # test pull for failure without parent set
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
241
        os.chdir('branch_b')
1614.2.8 by Olaf Conradi
Added testcases for using pull with --remember. Moved remember code to
242
        out = self.runbzr('pull', retcode=3)
243
        self.assertEquals(out,
244
                ('','bzr: ERROR: No pull location known or specified.\n'))
245
        # test implicit --remember when no parent set, this pull conflicts
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
246
        self.build_tree(['d'])
247
        tree_b.add('d')
248
        tree_b.commit('commit d')
249
        out = self.runbzr('pull ../branch_a', retcode=3)
1614.2.8 by Olaf Conradi
Added testcases for using pull with --remember. Moved remember code to
250
        self.assertEquals(out,
251
                ('','bzr: ERROR: These branches have diverged.  Try merge.\n'))
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
252
        self.assertEquals(abspath(branch_b.get_parent()), abspath(parent))
1614.2.8 by Olaf Conradi
Added testcases for using pull with --remember. Moved remember code to
253
        # test implicit --remember after resolving previous failure
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
254
        uncommit(branch=branch_b, tree=tree_b)
255
        transport.delete('branch_b/d')
1614.2.8 by Olaf Conradi
Added testcases for using pull with --remember. Moved remember code to
256
        self.runbzr('pull')
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
257
        self.assertEquals(abspath(branch_b.get_parent()), abspath(parent))
1614.2.8 by Olaf Conradi
Added testcases for using pull with --remember. Moved remember code to
258
        # test explicit --remember
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
259
        self.runbzr('pull ../branch_c --remember')
260
        self.assertEquals(abspath(branch_b.get_parent()),
261
                          abspath(branch_c.bzrdir.root_transport.base))