/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: Vincent Ladeuil
  • Date: 2012-01-05 17:56:30 UTC
  • mfrom: (6434 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6468.
  • Revision ID: v.ladeuil+lp@free.fr-20120105175630-kp0kt0el27s40q0x
Merge trunk resolving conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
from bzrlib import (
24
24
    branch,
25
25
    debug,
 
26
    osutils,
26
27
    remote,
27
28
    tests,
 
29
    uncommit,
28
30
    urlutils,
 
31
    workingtree,
29
32
    )
30
33
 
31
 
from bzrlib.branch import Branch
32
34
from bzrlib.directory_service import directories
33
 
from bzrlib.osutils import pathjoin
34
35
from bzrlib.tests import (
35
36
    fixtures,
36
37
    script,
37
38
    )
38
 
from bzrlib.uncommit import uncommit
39
 
from bzrlib.workingtree import WorkingTree
40
39
 
41
40
 
42
41
class TestPull(tests.TestCaseWithTransport):
44
43
    def example_branch(self, path='.'):
45
44
        tree = self.make_branch_and_tree(path)
46
45
        self.build_tree_contents([
47
 
            (pathjoin(path, 'hello'),   'foo'),
48
 
            (pathjoin(path, 'goodbye'), 'baz')])
 
46
            (osutils.pathjoin(path, 'hello'),   'foo'),
 
47
            (osutils.pathjoin(path, 'goodbye'), 'baz')])
49
48
        tree.add('hello')
50
49
        tree.commit(message='setup')
51
50
        tree.add('goodbye')
56
55
        """Pull changes from one branch to another."""
57
56
        a_tree = self.example_branch('a')
58
57
        base_rev = a_tree.branch.last_revision()
59
 
        os.chdir('a')
60
 
        self.run_bzr('pull', retcode=3)
61
 
        self.run_bzr('missing', retcode=3)
62
 
        self.run_bzr('missing .')
63
 
        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')
64
62
        # this will work on windows because we check for the same branch
65
63
        # in pull - if it fails, it is a regression
66
 
        self.run_bzr('pull')
67
 
        self.run_bzr('pull /', retcode=3)
 
64
        self.run_bzr('pull', working_dir='a')
 
65
        self.run_bzr('pull /', retcode=3, working_dir='a')
68
66
        if sys.platform not in ('win32', 'cygwin'):
69
 
            self.run_bzr('pull')
 
67
            self.run_bzr('pull', working_dir='a')
70
68
 
71
 
        os.chdir('..')
72
69
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
73
 
        os.chdir('b')
74
 
        self.run_bzr('pull')
75
 
        os.mkdir('subdir')
 
70
        self.run_bzr('pull', working_dir='b')
 
71
        os.mkdir('b/subdir')
76
72
        b_tree.add('subdir')
77
73
        new_rev = b_tree.commit(message='blah', allow_pointless=True)
78
74
 
79
 
        os.chdir('..')
80
 
        a = Branch.open('a')
81
 
        b = Branch.open('b')
 
75
        a = branch.Branch.open('a')
 
76
        b = branch.Branch.open('b')
82
77
        self.assertEqual(a.last_revision(), base_rev)
83
78
        self.assertEqual(b.last_revision(), new_rev)
84
79
 
85
 
        os.chdir('a')
86
 
        self.run_bzr('pull ../b')
 
80
        self.run_bzr('pull ../b', working_dir='a')
87
81
        self.assertEqual(a.last_revision(), b.last_revision())
88
82
        a_tree.commit(message='blah2', allow_pointless=True)
89
83
        b_tree.commit(message='blah3', allow_pointless=True)
90
84
        # no overwrite
91
 
        os.chdir('../b')
92
 
        self.run_bzr('pull ../a', retcode=3)
93
 
        os.chdir('..')
 
85
        self.run_bzr('pull ../a', retcode=3, working_dir='b')
94
86
        b_tree.bzrdir.sprout('overwriteme')
95
 
        os.chdir('overwriteme')
96
 
        self.run_bzr('pull --overwrite ../a')
97
 
        overwritten = Branch.open('.')
 
87
        self.run_bzr('pull --overwrite ../a', working_dir='overwriteme')
 
88
        overwritten = branch.Branch.open('overwriteme')
98
89
        self.assertEqual(overwritten.last_revision(),
99
90
                         a.last_revision())
100
91
        a_tree.merge_from_branch(b_tree.branch)
101
92
        a_tree.commit(message="blah4", allow_pointless=True)
102
 
        os.chdir('../b/subdir')
103
 
        self.run_bzr('pull ../../a')
 
93
 
 
94
        self.run_bzr('pull ../../a', working_dir='b/subdir')
104
95
        self.assertEqual(a.last_revision(), b.last_revision())
105
 
        sub_tree = WorkingTree.open_containing('.')[0]
 
96
        sub_tree = workingtree.WorkingTree.open_containing('b/subdir')[0]
106
97
        sub_tree.commit(message="blah5", allow_pointless=True)
107
98
        sub_tree.commit(message="blah6", allow_pointless=True)
108
 
        os.chdir('..')
109
 
        self.run_bzr('pull ../a')
110
 
        os.chdir('../a')
 
99
        self.run_bzr('pull ../a', working_dir='b')
111
100
        a_tree.commit(message="blah7", allow_pointless=True)
112
101
        a_tree.merge_from_branch(b_tree.branch)
113
102
        a_tree.commit(message="blah8", allow_pointless=True)
114
 
        self.run_bzr('pull ../b')
115
 
        self.run_bzr('pull ../b')
 
103
        self.run_bzr('pull ../b', working_dir='a')
 
104
        self.run_bzr('pull ../b', working_dir='a')
116
105
 
117
106
    def test_pull_dash_d(self):
118
107
        self.example_branch('a')
138
127
 
139
128
        b_tree = a_tree.bzrdir.sprout('b',
140
129
                   revision_id=a_tree.branch.get_rev_id(1)).open_workingtree()
141
 
        os.chdir('b')
142
 
        self.run_bzr('pull -r 2')
143
 
        a = Branch.open('../a')
144
 
        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')
145
133
        self.assertEqual(a.revno(),4)
146
134
        self.assertEqual(b.revno(),2)
147
 
        self.run_bzr('pull -r 3')
 
135
        self.run_bzr('pull -r 3', working_dir='b')
148
136
        self.assertEqual(b.revno(),3)
149
 
        self.run_bzr('pull -r 4')
 
137
        self.run_bzr('pull -r 4', working_dir='b')
150
138
        self.assertEqual(a.last_revision(), b.last_revision())
151
139
 
152
140
    def test_pull_tags(self):
190
178
 
191
179
        self.assertEqual(b_tree.branch.last_revision_info()[0], 2)
192
180
 
193
 
        os.chdir('b')
194
 
        self.run_bzr('pull --overwrite ../a')
 
181
        self.run_bzr('pull --overwrite ../a', working_dir='b')
195
182
        (last_revinfo_b) = b_tree.branch.last_revision_info()
196
183
        self.assertEqual(last_revinfo_b[0], 3)
197
184
        self.assertEqual(last_revinfo_b[1], a_tree.branch.last_revision())
227
214
 
228
215
        # With convergence, we could just pull over the
229
216
        # new change, but with --overwrite, we want to switch our history
230
 
        os.chdir('b')
231
 
        self.run_bzr('pull --overwrite ../a')
 
217
        self.run_bzr('pull --overwrite ../a', working_dir='b')
232
218
        rev_info_b = b_tree.branch.last_revision_info()
233
219
        self.assertEqual(rev_info_b[0], 4)
234
220
        self.assertEqual(rev_info_b, rev_info_a)
235
221
 
236
222
    def test_pull_remember(self):
237
223
        """Pull changes from one branch to another and test parent location."""
238
 
        transport = self.get_transport()
 
224
        t = self.get_transport()
239
225
        tree_a = self.make_branch_and_tree('branch_a')
240
226
        branch_a = tree_a.branch
241
227
        self.build_tree(['branch_a/a'])
272
258
        branch_b = branch.Branch.open('branch_b')
273
259
        self.assertEqual(parent, branch_b.get_parent())
274
260
        # test implicit --remember after resolving previous failure
275
 
        uncommit(branch=tree_b.branch, tree=tree_b)
276
 
        transport.delete('branch_b/d')
 
261
        uncommit.uncommit(branch=branch_b, tree=tree_b)
 
262
        t.delete('branch_b/d')
277
263
        self.run_bzr('pull', working_dir='branch_b')
278
264
        branch_b = branch.Branch.open('branch_b')
279
265
        self.assertEqual(branch_b.get_parent(), parent)
287
273
        from bzrlib.testament import Testament
288
274
        # Build up 2 trees and prepare for a pull
289
275
        tree_a = self.make_branch_and_tree('branch_a')
290
 
        f = open('branch_a/a', 'wb')
291
 
        f.write('hello')
292
 
        f.close()
 
276
        with open('branch_a/a', 'wb') as f:
 
277
            f.write('hello')
293
278
        tree_a.add('a')
294
279
        tree_a.commit('message')
295
280
 
296
281
        tree_b = tree_a.bzrdir.sprout('branch_b').open_workingtree()
297
282
 
298
283
        # Make a change to 'a' that 'b' can pull
299
 
        f = open('branch_a/a', 'wb')
300
 
        f.write('hey there')
301
 
        f.close()
 
284
        with open('branch_a/a', 'wb') as f:
 
285
            f.write('hey there')
302
286
        tree_a.commit('message')
303
287
 
304
288
        # Create the bundle for 'b' to pull
305
 
        os.chdir('branch_a')
306
 
        self.run_bzr('bundle ../branch_b -o ../bundle')
 
289
        self.run_bzr('bundle ../branch_b -o ../bundle', working_dir='branch_a')
307
290
 
308
 
        os.chdir('../branch_b')
309
 
        out, err = self.run_bzr('pull ../bundle')
 
291
        out, err = self.run_bzr('pull ../bundle', working_dir='branch_b')
310
292
        self.assertEqual(out,
311
293
                         'Now on revision 2.\n')
312
294
        self.assertEqual(err,
323
305
                             testament_b.as_text())
324
306
 
325
307
        # it is legal to attempt to pull an already-merged bundle
326
 
        out, err = self.run_bzr('pull ../bundle')
 
308
        out, err = self.run_bzr('pull ../bundle', working_dir='branch_b')
327
309
        self.assertEqual(err, '')
328
310
        self.assertEqual(out, 'No revisions or tags to pull.\n')
329
311
 
432
414
        # upwards without agreement from bzr's network support maintainers.
433
415
        self.assertLength(19, self.hpss_calls)
434
416
        self.assertLength(1, self.hpss_connections)
435
 
        remote = Branch.open('stacked')
 
417
        remote = branch.Branch.open('stacked')
436
418
        self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
437
419
 
438
420
    def test_pull_cross_format_warning(self):
502
484
        a_tree = self.example_branch('a')
503
485
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
504
486
 
505
 
        f = open(pathjoin('a', 'hello'),'wt')
506
 
        f.write('fee')
507
 
        f.close()
 
487
        with open(osutils.pathjoin('a', 'hello'),'wt') as f:
 
488
            f.write('fee')
508
489
        a_tree.commit('fee')
509
490
 
510
 
        f = open(pathjoin('b', 'hello'),'wt')
511
 
        f.write('fie')
512
 
        f.close()
 
491
        with open(osutils.pathjoin('b', 'hello'),'wt') as f:
 
492
            f.write('fie')
513
493
 
514
494
        out,err=self.run_bzr(['pull','-d','b','a','--show-base'])
515
495
 
516
496
        # check for message here
517
 
        self.assertEqual(err,
518
 
                         ' M  hello\nText conflict in hello\n1 conflicts encountered.\n')
 
497
        self.assertEqual(
 
498
            err,
 
499
            ' M  hello\nText conflict in hello\n1 conflicts encountered.\n')
519
500
 
520
501
        self.assertEqualDiff('<<<<<<< TREE\n'
521
502
                             'fie||||||| BASE-REVISION\n'
522
503
                             'foo=======\n'
523
504
                             'fee>>>>>>> MERGE-SOURCE\n',
524
 
                             open(pathjoin('b', 'hello')).read())
 
505
                             open(osutils.pathjoin('b', 'hello')).read())
525
506
 
526
507
    def test_pull_show_base_working_tree_only(self):
527
508
        """--show-base only allowed if there's a working tree
531
512
        self.make_branch('from')
532
513
        self.make_branch('to')
533
514
        out=self.run_bzr(['pull','-d','to','from','--show-base'],retcode=3)
534
 
        self.assertEqual(out,
535
 
                         ('','bzr: ERROR: Need working tree for --show-base.\n'))
 
515
        self.assertEqual(
 
516
            out, ('','bzr: ERROR: Need working tree for --show-base.\n'))
536
517
 
537
518
    def test_pull_tag_conflicts(self):
538
519
        """pulling tags with conflicts will change the exit code"""