/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_pull.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-07-03 07:35:46 UTC
  • mfrom: (2574.1.1 ianc-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20070703073546-9dv8bocak8u3ou6m
(Vincent Ladeuil) Fix #115209 - Unable to handle http code 400: Bad Request When issuing too many ranges

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 by Canonical Ltd
2
 
# -*- coding: utf-8 -*-
3
 
 
 
1
# Copyright (C) 2005, 2006 Canonical Ltd
 
2
#
4
3
# This program is free software; you can redistribute it and/or modify
5
4
# it under the terms of the GNU General Public License as published by
6
5
# the Free Software Foundation; either version 2 of the License, or
7
6
# (at your option) any later version.
8
 
 
 
7
#
9
8
# This program is distributed in the hope that it will be useful,
10
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
11
# GNU General Public License for more details.
13
 
 
 
12
#
14
13
# You should have received a copy of the GNU General Public License
15
14
# along with this program; if not, write to the Free Software
16
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
16
 
18
17
 
19
 
"""Black-box tests for bzr pull.
20
 
"""
 
18
"""Black-box tests for bzr pull."""
21
19
 
22
20
import os
23
21
import sys
24
22
 
25
23
from bzrlib.branch import Branch
26
 
from bzrlib.osutils import abspath
27
24
from bzrlib.tests.blackbox import ExternalBase
28
25
from bzrlib.uncommit import uncommit
 
26
from bzrlib import urlutils
29
27
 
30
28
 
31
29
class TestPull(ExternalBase):
32
30
 
33
31
    def example_branch(test):
34
 
        test.runbzr('init')
 
32
        test.run_bzr('init')
35
33
        file('hello', 'wt').write('foo')
36
 
        test.runbzr('add hello')
37
 
        test.runbzr('commit -m setup hello')
 
34
        test.run_bzr('add hello')
 
35
        test.run_bzr('commit -m setup hello')
38
36
        file('goodbye', 'wt').write('baz')
39
 
        test.runbzr('add goodbye')
40
 
        test.runbzr('commit -m setup goodbye')
 
37
        test.run_bzr('add goodbye')
 
38
        test.run_bzr('commit -m setup goodbye')
41
39
 
42
40
    def test_pull(self):
43
41
        """Pull changes from one branch to another."""
45
43
        os.chdir('a')
46
44
 
47
45
        self.example_branch()
48
 
        self.runbzr('pull', retcode=3)
49
 
        self.runbzr('missing', retcode=3)
50
 
        self.runbzr('missing .')
51
 
        self.runbzr('missing')
52
 
        if sys.platform not in ('win32', 'cygwin'):
53
 
            # This is equivalent to doing "bzr pull ."
54
 
            # Which means that bzr creates 2 branches grabbing
55
 
            # the same location, and tries to pull.
56
 
            # However, 2 branches mean 2 locks on the same file
57
 
            # which ultimately implies a deadlock.
58
 
            # (non windows platforms allow multiple locks on the
59
 
            # same file by the same calling process)
60
 
            self.runbzr('pull')
61
 
        self.runbzr('pull /', retcode=3)
62
 
        if sys.platform not in ('win32', 'cygwin'):
63
 
            self.runbzr('pull')
 
46
        self.run_bzr('pull', retcode=3)
 
47
        self.run_bzr('missing', retcode=3)
 
48
        self.run_bzr('missing .')
 
49
        self.run_bzr('missing')
 
50
        # this will work on windows because we check for the same branch
 
51
        # in pull - if it fails, it is a regression
 
52
        self.run_bzr('pull')
 
53
        self.run_bzr('pull /', retcode=3)
 
54
        if sys.platform not in ('win32', 'cygwin'):
 
55
            self.run_bzr('pull')
64
56
 
65
57
        os.chdir('..')
66
 
        self.runbzr('branch a b')
 
58
        self.run_bzr('branch a b')
67
59
        os.chdir('b')
68
 
        self.runbzr('pull')
 
60
        self.run_bzr('pull')
69
61
        os.mkdir('subdir')
70
 
        self.runbzr('add subdir')
71
 
        self.runbzr('commit -m blah --unchanged')
 
62
        self.run_bzr('add subdir')
 
63
        self.run_bzr('commit -m blah --unchanged')
72
64
        os.chdir('../a')
73
65
        a = Branch.open('.')
74
66
        b = Branch.open('../b')
75
67
        self.assertEquals(a.revision_history(), b.revision_history()[:-1])
76
 
        self.runbzr('pull ../b')
 
68
        self.run_bzr('pull ../b')
77
69
        self.assertEquals(a.revision_history(), b.revision_history())
78
 
        self.runbzr('commit -m blah2 --unchanged')
 
70
        self.run_bzr('commit -m blah2 --unchanged')
79
71
        os.chdir('../b')
80
 
        self.runbzr('commit -m blah3 --unchanged')
 
72
        self.run_bzr('commit -m blah3 --unchanged')
81
73
        # no overwrite
82
 
        self.runbzr('pull ../a', retcode=3)
 
74
        self.run_bzr('pull ../a', retcode=3)
83
75
        os.chdir('..')
84
 
        self.runbzr('branch b overwriteme')
 
76
        self.run_bzr('branch b overwriteme')
85
77
        os.chdir('overwriteme')
86
 
        self.runbzr('pull --overwrite ../a')
 
78
        self.run_bzr('pull --overwrite ../a')
87
79
        overwritten = Branch.open('.')
88
80
        self.assertEqual(overwritten.revision_history(),
89
81
                         a.revision_history())
90
82
        os.chdir('../a')
91
 
        self.runbzr('merge ../b')
92
 
        self.runbzr('commit -m blah4 --unchanged')
 
83
        self.run_bzr('merge ../b')
 
84
        self.run_bzr('commit -m blah4 --unchanged')
93
85
        os.chdir('../b/subdir')
94
 
        self.runbzr('pull ../../a')
 
86
        self.run_bzr('pull ../../a')
95
87
        self.assertEquals(a.revision_history()[-1], b.revision_history()[-1])
96
 
        self.runbzr('commit -m blah5 --unchanged')
97
 
        self.runbzr('commit -m blah6 --unchanged')
 
88
        self.run_bzr('commit -m blah5 --unchanged')
 
89
        self.run_bzr('commit -m blah6 --unchanged')
98
90
        os.chdir('..')
99
 
        self.runbzr('pull ../a')
 
91
        self.run_bzr('pull ../a')
100
92
        os.chdir('../a')
101
 
        self.runbzr('commit -m blah7 --unchanged')
102
 
        self.runbzr('merge ../b')
103
 
        self.runbzr('commit -m blah8 --unchanged')
104
 
        self.runbzr('pull ../b')
105
 
        self.runbzr('pull ../b')
 
93
        self.run_bzr('commit -m blah7 --unchanged')
 
94
        self.run_bzr('merge ../b')
 
95
        self.run_bzr('commit -m blah8 --unchanged')
 
96
        self.run_bzr('pull ../b')
 
97
        self.run_bzr('pull ../b')
 
98
 
 
99
    def test_pull_dash_d(self):
 
100
        os.mkdir('a')
 
101
        os.chdir('a')
 
102
        self.example_branch()
 
103
        self.run_bzr('init ../b')
 
104
        self.run_bzr('init ../c')
 
105
        # pull into that branch
 
106
        self.run_bzr('pull -d ../b .')
 
107
        # pull into a branch specified by a url
 
108
        c_url = urlutils.local_path_to_url('../c')
 
109
        self.assertStartsWith(c_url, 'file://')
 
110
        self.run_bzr('pull -d %s .' % c_url)
106
111
 
107
112
    def test_pull_revision(self):
108
113
        """Pull some changes from one branch to another."""
111
116
 
112
117
        self.example_branch()
113
118
        file('hello2', 'wt').write('foo')
114
 
        self.runbzr('add hello2')
115
 
        self.runbzr('commit -m setup hello2')
 
119
        self.run_bzr('add hello2')
 
120
        self.run_bzr('commit -m setup hello2')
116
121
        file('goodbye2', 'wt').write('baz')
117
 
        self.runbzr('add goodbye2')
118
 
        self.runbzr('commit -m setup goodbye2')
 
122
        self.run_bzr('add goodbye2')
 
123
        self.run_bzr('commit -m setup goodbye2')
119
124
 
120
125
        os.chdir('..')
121
 
        self.runbzr('branch -r 1 a b')
 
126
        self.run_bzr('branch -r 1 a b')
122
127
        os.chdir('b')
123
 
        self.runbzr('pull -r 2')
 
128
        self.run_bzr('pull -r 2')
124
129
        a = Branch.open('../a')
125
130
        b = Branch.open('.')
126
131
        self.assertEquals(a.revno(),4)
127
132
        self.assertEquals(b.revno(),2)
128
 
        self.runbzr('pull -r 3')
 
133
        self.run_bzr('pull -r 3')
129
134
        self.assertEquals(b.revno(),3)
130
 
        self.runbzr('pull -r 4')
 
135
        self.run_bzr('pull -r 4')
131
136
        self.assertEquals(a.revision_history(), b.revision_history())
132
137
 
133
138
 
138
143
        bzr = self.run_bzr
139
144
 
140
145
        def get_rh(expected_len):
141
 
            rh = self.capture('revision-history')
 
146
            rh = self.run_bzr(['revision-history'])[0]
142
147
            # Make sure we don't have trailing empty revisions
143
148
            rh = rh.strip().split('\n')
144
149
            self.assertEqual(len(rh), expected_len)
180
185
        bzr = self.run_bzr
181
186
 
182
187
        def get_rh(expected_len):
183
 
            rh = self.capture('revision-history')
 
188
            rh = self.run_bzr(['revision-history'])[0]
184
189
            # Make sure we don't have trailing empty revisions
185
190
            rh = rh.strip().split('\n')
186
191
            self.assertEqual(len(rh), expected_len)
233
238
        self.build_tree(['branch_a/a'])
234
239
        tree_a.add('a')
235
240
        tree_a.commit('commit a')
236
 
        branch_b = branch_a.bzrdir.sprout('branch_b').open_branch()
237
 
        tree_b = branch_b.bzrdir.open_workingtree()
238
 
        branch_c = branch_a.bzrdir.sprout('branch_c').open_branch()
239
 
        tree_c = branch_c.bzrdir.open_workingtree()
 
241
        tree_b = branch_a.bzrdir.sprout('branch_b').open_workingtree()
 
242
        branch_b = tree_b.branch
 
243
        tree_c = branch_a.bzrdir.sprout('branch_c').open_workingtree()
 
244
        branch_c = tree_c.branch
240
245
        self.build_tree(['branch_a/b'])
241
246
        tree_a.add('b')
242
247
        tree_a.commit('commit b')
246
251
        self.assertEqual(None, branch_b.get_parent())
247
252
        # test pull for failure without parent set
248
253
        os.chdir('branch_b')
249
 
        out = self.runbzr('pull', retcode=3)
 
254
        out = self.run_bzr('pull', retcode=3)
250
255
        self.assertEquals(out,
251
256
                ('','bzr: ERROR: No pull location known or specified.\n'))
252
257
        # test implicit --remember when no parent set, this pull conflicts
253
258
        self.build_tree(['d'])
254
259
        tree_b.add('d')
255
260
        tree_b.commit('commit d')
256
 
        out = self.runbzr('pull ../branch_a', retcode=3)
 
261
        out = self.run_bzr('pull ../branch_a', retcode=3)
257
262
        self.assertEquals(out,
258
 
                ('','bzr: ERROR: These branches have diverged.  Try merge.\n'))
259
 
        self.assertEquals(abspath(branch_b.get_parent()), abspath(parent))
 
263
                ('','bzr: ERROR: These branches have diverged.'
 
264
                    ' Use the merge command to reconcile them.\n'))
 
265
        self.assertEquals(branch_b.get_parent(), parent)
260
266
        # test implicit --remember after resolving previous failure
261
267
        uncommit(branch=branch_b, tree=tree_b)
262
268
        transport.delete('branch_b/d')
263
 
        self.runbzr('pull')
264
 
        self.assertEquals(abspath(branch_b.get_parent()), abspath(parent))
 
269
        self.run_bzr('pull')
 
270
        self.assertEquals(branch_b.get_parent(), parent)
265
271
        # test explicit --remember
266
 
        self.runbzr('pull ../branch_c --remember')
267
 
        self.assertEquals(abspath(branch_b.get_parent()),
268
 
                          abspath(branch_c.bzrdir.root_transport.base))
 
272
        self.run_bzr('pull ../branch_c --remember')
 
273
        self.assertEquals(branch_b.get_parent(),
 
274
                          branch_c.bzrdir.root_transport.base)
 
275
 
 
276
    def test_pull_bundle(self):
 
277
        from bzrlib.testament import Testament
 
278
        # Build up 2 trees and prepare for a pull
 
279
        tree_a = self.make_branch_and_tree('branch_a')
 
280
        f = open('branch_a/a', 'wb')
 
281
        f.write('hello')
 
282
        f.close()
 
283
        tree_a.add('a')
 
284
        tree_a.commit('message')
 
285
 
 
286
        tree_b = tree_a.bzrdir.sprout('branch_b').open_workingtree()
 
287
 
 
288
        # Make a change to 'a' that 'b' can pull
 
289
        f = open('branch_a/a', 'wb')
 
290
        f.write('hey there')
 
291
        f.close()
 
292
        tree_a.commit('message')
 
293
 
 
294
        # Create the bundle for 'b' to pull
 
295
        os.chdir('branch_a')
 
296
        bundle_file = open('../bundle', 'wb')
 
297
        bundle_file.write(self.run_bzr('bundle', '../branch_b')[0])
 
298
        bundle_file.close()
 
299
 
 
300
        os.chdir('../branch_b')
 
301
        out, err = self.run_bzr('pull', '../bundle')
 
302
        self.assertEqual(out,
 
303
                         'Now on revision 2.\n')
 
304
        self.assertEqual(err,
 
305
                ' M  a\nAll changes applied successfully.\n')
 
306
 
 
307
        self.assertEqualDiff(tree_a.branch.revision_history(),
 
308
                             tree_b.branch.revision_history())
 
309
 
 
310
        testament_a = Testament.from_revision(tree_a.branch.repository,
 
311
                                              tree_a.get_parent_ids()[0])
 
312
        testament_b = Testament.from_revision(tree_b.branch.repository,
 
313
                                              tree_b.get_parent_ids()[0])
 
314
        self.assertEqualDiff(testament_a.as_text(),
 
315
                             testament_b.as_text())
 
316
 
 
317
        # it is legal to attempt to pull an already-merged bundle
 
318
        out, err = self.run_bzr('pull', '../bundle')
 
319
        self.assertEqual(err, '')
 
320
        self.assertEqual(out, 'No revisions to pull.\n')