~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Patch Queue Manager
  • Date: 2012-01-28 16:56:12 UTC
  • mfrom: (6449.2.4 config-registry-option)
  • Revision ID: pqm@pqm.ubuntu.com-20120128165612-ji88oyq3ghpmzy0g
(jelmer) Add bzrlib.config.RegistryOption. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2012 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
21
21
import sys
22
22
 
23
23
from bzrlib import (
 
24
    branch,
24
25
    debug,
 
26
    osutils,
25
27
    remote,
26
28
    tests,
 
29
    uncommit,
27
30
    urlutils,
 
31
    workingtree,
28
32
    )
29
33
 
30
 
from bzrlib.branch import Branch
31
34
from bzrlib.directory_service import directories
32
 
from bzrlib.osutils import pathjoin
33
35
from bzrlib.tests import (
34
36
    fixtures,
35
37
    script,
36
38
    )
37
 
from bzrlib.uncommit import uncommit
38
 
from bzrlib.workingtree import WorkingTree
39
39
 
40
40
 
41
41
class TestPull(tests.TestCaseWithTransport):
43
43
    def example_branch(self, path='.'):
44
44
        tree = self.make_branch_and_tree(path)
45
45
        self.build_tree_contents([
46
 
            (pathjoin(path, 'hello'),   'foo'),
47
 
            (pathjoin(path, 'goodbye'), 'baz')])
 
46
            (osutils.pathjoin(path, 'hello'),   'foo'),
 
47
            (osutils.pathjoin(path, 'goodbye'), 'baz')])
48
48
        tree.add('hello')
49
49
        tree.commit(message='setup')
50
50
        tree.add('goodbye')
55
55
        """Pull changes from one branch to another."""
56
56
        a_tree = self.example_branch('a')
57
57
        base_rev = a_tree.branch.last_revision()
58
 
        os.chdir('a')
59
 
        self.run_bzr('pull', retcode=3)
60
 
        self.run_bzr('missing', retcode=3)
61
 
        self.run_bzr('missing .')
62
 
        self.run_bzr('missing')
 
58
        self.run_bzr('pull', retcode=3, working_dir='a')
 
59
        self.run_bzr('missing', retcode=3, working_dir='a')
 
60
        self.run_bzr('missing .', working_dir='a')
 
61
        self.run_bzr('missing', working_dir='a')
63
62
        # this will work on windows because we check for the same branch
64
63
        # in pull - if it fails, it is a regression
65
 
        self.run_bzr('pull')
66
 
        self.run_bzr('pull /', retcode=3)
 
64
        self.run_bzr('pull', working_dir='a')
 
65
        self.run_bzr('pull /', retcode=3, working_dir='a')
67
66
        if sys.platform not in ('win32', 'cygwin'):
68
 
            self.run_bzr('pull')
 
67
            self.run_bzr('pull', working_dir='a')
69
68
 
70
 
        os.chdir('..')
71
69
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
72
 
        os.chdir('b')
73
 
        self.run_bzr('pull')
74
 
        os.mkdir('subdir')
 
70
        self.run_bzr('pull', working_dir='b')
 
71
        os.mkdir('b/subdir')
75
72
        b_tree.add('subdir')
76
73
        new_rev = b_tree.commit(message='blah', allow_pointless=True)
77
74
 
78
 
        os.chdir('..')
79
 
        a = Branch.open('a')
80
 
        b = Branch.open('b')
 
75
        a = branch.Branch.open('a')
 
76
        b = branch.Branch.open('b')
81
77
        self.assertEqual(a.last_revision(), base_rev)
82
78
        self.assertEqual(b.last_revision(), new_rev)
83
79
 
84
 
        os.chdir('a')
85
 
        self.run_bzr('pull ../b')
 
80
        self.run_bzr('pull ../b', working_dir='a')
86
81
        self.assertEqual(a.last_revision(), b.last_revision())
87
82
        a_tree.commit(message='blah2', allow_pointless=True)
88
83
        b_tree.commit(message='blah3', allow_pointless=True)
89
84
        # no overwrite
90
 
        os.chdir('../b')
91
 
        self.run_bzr('pull ../a', retcode=3)
92
 
        os.chdir('..')
 
85
        self.run_bzr('pull ../a', retcode=3, working_dir='b')
93
86
        b_tree.bzrdir.sprout('overwriteme')
94
 
        os.chdir('overwriteme')
95
 
        self.run_bzr('pull --overwrite ../a')
96
 
        overwritten = Branch.open('.')
 
87
        self.run_bzr('pull --overwrite ../a', working_dir='overwriteme')
 
88
        overwritten = branch.Branch.open('overwriteme')
97
89
        self.assertEqual(overwritten.last_revision(),
98
90
                         a.last_revision())
99
91
        a_tree.merge_from_branch(b_tree.branch)
100
92
        a_tree.commit(message="blah4", allow_pointless=True)
101
 
        os.chdir('../b/subdir')
102
 
        self.run_bzr('pull ../../a')
 
93
 
 
94
        self.run_bzr('pull ../../a', working_dir='b/subdir')
103
95
        self.assertEqual(a.last_revision(), b.last_revision())
104
 
        sub_tree = WorkingTree.open_containing('.')[0]
 
96
        sub_tree = workingtree.WorkingTree.open_containing('b/subdir')[0]
105
97
        sub_tree.commit(message="blah5", allow_pointless=True)
106
98
        sub_tree.commit(message="blah6", allow_pointless=True)
107
 
        os.chdir('..')
108
 
        self.run_bzr('pull ../a')
109
 
        os.chdir('../a')
 
99
        self.run_bzr('pull ../a', working_dir='b')
110
100
        a_tree.commit(message="blah7", allow_pointless=True)
111
101
        a_tree.merge_from_branch(b_tree.branch)
112
102
        a_tree.commit(message="blah8", allow_pointless=True)
113
 
        self.run_bzr('pull ../b')
114
 
        self.run_bzr('pull ../b')
 
103
        self.run_bzr('pull ../b', working_dir='a')
 
104
        self.run_bzr('pull ../b', working_dir='a')
115
105
 
116
106
    def test_pull_dash_d(self):
117
107
        self.example_branch('a')
137
127
 
138
128
        b_tree = a_tree.bzrdir.sprout('b',
139
129
                   revision_id=a_tree.branch.get_rev_id(1)).open_workingtree()
140
 
        os.chdir('b')
141
 
        self.run_bzr('pull -r 2')
142
 
        a = Branch.open('../a')
143
 
        b = Branch.open('.')
 
130
        self.run_bzr('pull -r 2', working_dir='b')
 
131
        a = branch.Branch.open('a')
 
132
        b = branch.Branch.open('b')
144
133
        self.assertEqual(a.revno(),4)
145
134
        self.assertEqual(b.revno(),2)
146
 
        self.run_bzr('pull -r 3')
 
135
        self.run_bzr('pull -r 3', working_dir='b')
147
136
        self.assertEqual(b.revno(),3)
148
 
        self.run_bzr('pull -r 4')
 
137
        self.run_bzr('pull -r 4', working_dir='b')
149
138
        self.assertEqual(a.last_revision(), b.last_revision())
150
139
 
151
140
    def test_pull_tags(self):
155
144
        # Make a source, sprout a target off it
156
145
        builder = self.make_branch_builder('source')
157
146
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
158
 
        source.get_config().set_user_option('branch.fetch_tags', 'True')
 
147
        source.get_config_stack().set('branch.fetch_tags', True)
159
148
        target_bzrdir = source.bzrdir.sprout('target')
160
149
        source.tags.set_tag('tag-a', 'rev-2')
161
150
        # Pull from source
189
178
 
190
179
        self.assertEqual(b_tree.branch.last_revision_info()[0], 2)
191
180
 
192
 
        os.chdir('b')
193
 
        self.run_bzr('pull --overwrite ../a')
 
181
        self.run_bzr('pull --overwrite ../a', working_dir='b')
194
182
        (last_revinfo_b) = b_tree.branch.last_revision_info()
195
183
        self.assertEqual(last_revinfo_b[0], 3)
196
184
        self.assertEqual(last_revinfo_b[1], a_tree.branch.last_revision())
226
214
 
227
215
        # With convergence, we could just pull over the
228
216
        # new change, but with --overwrite, we want to switch our history
229
 
        os.chdir('b')
230
 
        self.run_bzr('pull --overwrite ../a')
 
217
        self.run_bzr('pull --overwrite ../a', working_dir='b')
231
218
        rev_info_b = b_tree.branch.last_revision_info()
232
219
        self.assertEqual(rev_info_b[0], 4)
233
220
        self.assertEqual(rev_info_b, rev_info_a)
234
221
 
235
222
    def test_pull_remember(self):
236
223
        """Pull changes from one branch to another and test parent location."""
237
 
        transport = self.get_transport()
 
224
        t = self.get_transport()
238
225
        tree_a = self.make_branch_and_tree('branch_a')
239
226
        branch_a = tree_a.branch
240
227
        self.build_tree(['branch_a/a'])
252
239
        branch_b.set_parent(None)
253
240
        self.assertEqual(None, branch_b.get_parent())
254
241
        # test pull for failure without parent set
255
 
        os.chdir('branch_b')
256
 
        out = self.run_bzr('pull', retcode=3)
 
242
        out = self.run_bzr('pull', retcode=3, working_dir='branch_b')
257
243
        self.assertEqual(out,
258
244
                ('','bzr: ERROR: No pull location known or specified.\n'))
259
245
        # test implicit --remember when no parent set, this pull conflicts
260
 
        self.build_tree(['d'])
 
246
        self.build_tree(['branch_b/d'])
261
247
        tree_b.add('d')
262
248
        tree_b.commit('commit d')
263
 
        out = self.run_bzr('pull ../branch_a', retcode=3)
 
249
        out = self.run_bzr('pull ../branch_a', retcode=3,
 
250
                           working_dir='branch_b')
264
251
        self.assertEqual(out,
265
252
                ('','bzr: ERROR: These branches have diverged.'
266
253
                    ' Use the missing command to see how.\n'
267
254
                    'Use the merge command to reconcile them.\n'))
268
255
        self.assertEqual(branch_b.get_parent(), parent)
269
256
        # test implicit --remember after resolving previous failure
270
 
        uncommit(branch=branch_b, tree=tree_b)
271
 
        transport.delete('branch_b/d')
272
 
        self.run_bzr('pull')
 
257
        uncommit.uncommit(branch=branch_b, tree=tree_b)
 
258
        t.delete('branch_b/d')
 
259
        self.run_bzr('pull', working_dir='branch_b')
273
260
        self.assertEqual(branch_b.get_parent(), parent)
274
261
        # test explicit --remember
275
 
        self.run_bzr('pull ../branch_c --remember')
 
262
        self.run_bzr('pull ../branch_c --remember', working_dir='branch_b')
276
263
        self.assertEqual(branch_b.get_parent(),
277
264
                          branch_c.bzrdir.root_transport.base)
278
265
 
280
267
        from bzrlib.testament import Testament
281
268
        # Build up 2 trees and prepare for a pull
282
269
        tree_a = self.make_branch_and_tree('branch_a')
283
 
        f = open('branch_a/a', 'wb')
284
 
        f.write('hello')
285
 
        f.close()
 
270
        with open('branch_a/a', 'wb') as f:
 
271
            f.write('hello')
286
272
        tree_a.add('a')
287
273
        tree_a.commit('message')
288
274
 
289
275
        tree_b = tree_a.bzrdir.sprout('branch_b').open_workingtree()
290
276
 
291
277
        # Make a change to 'a' that 'b' can pull
292
 
        f = open('branch_a/a', 'wb')
293
 
        f.write('hey there')
294
 
        f.close()
 
278
        with open('branch_a/a', 'wb') as f:
 
279
            f.write('hey there')
295
280
        tree_a.commit('message')
296
281
 
297
282
        # Create the bundle for 'b' to pull
298
 
        os.chdir('branch_a')
299
 
        self.run_bzr('bundle ../branch_b -o ../bundle')
 
283
        self.run_bzr('bundle ../branch_b -o ../bundle', working_dir='branch_a')
300
284
 
301
 
        os.chdir('../branch_b')
302
 
        out, err = self.run_bzr('pull ../bundle')
 
285
        out, err = self.run_bzr('pull ../bundle', working_dir='branch_b')
303
286
        self.assertEqual(out,
304
287
                         'Now on revision 2.\n')
305
288
        self.assertEqual(err,
316
299
                             testament_b.as_text())
317
300
 
318
301
        # it is legal to attempt to pull an already-merged bundle
319
 
        out, err = self.run_bzr('pull ../bundle')
 
302
        out, err = self.run_bzr('pull ../bundle', working_dir='branch_b')
320
303
        self.assertEqual(err, '')
321
304
        self.assertEqual(out, 'No revisions or tags to pull.\n')
322
305
 
377
360
    def test_pull_verbose_uses_default_log(self):
378
361
        tree = self.example_branch('source')
379
362
        target = self.make_branch_and_tree('target')
380
 
        target_config = target.branch.get_config()
381
 
        target_config.set_user_option('log_format', 'short')
 
363
        target_config = target.branch.get_config_stack()
 
364
        target_config.set('log_format', 'short')
382
365
        out = self.run_bzr('pull -v source -d target')[0]
383
366
        self.assertContainsRe(out, r'\n {4}1 .*\n {6}setup\n')
384
367
        self.assertNotContainsRe(
421
404
        # become necessary for this use case. Please do not adjust this number
422
405
        # upwards without agreement from bzr's network support maintainers.
423
406
        self.assertLength(19, self.hpss_calls)
424
 
        remote = Branch.open('stacked')
 
407
        self.assertLength(1, self.hpss_connections)
 
408
        remote = branch.Branch.open('stacked')
425
409
        self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
426
410
 
427
411
    def test_pull_cross_format_warning(self):
491
475
        a_tree = self.example_branch('a')
492
476
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
493
477
 
494
 
        f = open(pathjoin('a', 'hello'),'wt')
495
 
        f.write('fee')
496
 
        f.close()
 
478
        with open(osutils.pathjoin('a', 'hello'),'wt') as f:
 
479
            f.write('fee')
497
480
        a_tree.commit('fee')
498
481
 
499
 
        f = open(pathjoin('b', 'hello'),'wt')
500
 
        f.write('fie')
501
 
        f.close()
 
482
        with open(osutils.pathjoin('b', 'hello'),'wt') as f:
 
483
            f.write('fie')
502
484
 
503
485
        out,err=self.run_bzr(['pull','-d','b','a','--show-base'])
504
486
 
505
487
        # check for message here
506
 
        self.assertEqual(err,
507
 
                         ' M  hello\nText conflict in hello\n1 conflicts encountered.\n')
 
488
        self.assertEqual(
 
489
            err,
 
490
            ' M  hello\nText conflict in hello\n1 conflicts encountered.\n')
508
491
 
509
492
        self.assertEqualDiff('<<<<<<< TREE\n'
510
493
                             'fie||||||| BASE-REVISION\n'
511
494
                             'foo=======\n'
512
495
                             'fee>>>>>>> MERGE-SOURCE\n',
513
 
                             open(pathjoin('b', 'hello')).read())
 
496
                             open(osutils.pathjoin('b', 'hello')).read())
514
497
 
515
498
    def test_pull_show_base_working_tree_only(self):
516
499
        """--show-base only allowed if there's a working tree
520
503
        self.make_branch('from')
521
504
        self.make_branch('to')
522
505
        out=self.run_bzr(['pull','-d','to','from','--show-base'],retcode=3)
523
 
        self.assertEqual(out,
524
 
                         ('','bzr: ERROR: Need working tree for --show-base.\n'))
 
506
        self.assertEqual(
 
507
            out, ('','bzr: ERROR: Need working tree for --show-base.\n'))
525
508
 
526
509
    def test_pull_tag_conflicts(self):
527
510
        """pulling tags with conflicts will change the exit code"""