/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: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2012, 2016 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
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
 
18
 
"""Black-box tests for brz pull."""
 
18
"""Black-box tests for bzr pull."""
19
19
 
20
20
import os
21
21
import sys
22
22
 
23
 
from breezy import (
 
23
from bzrlib import (
24
24
    branch,
25
25
    debug,
26
26
    osutils,
 
27
    remote,
27
28
    tests,
28
29
    uncommit,
29
30
    urlutils,
30
31
    workingtree,
31
32
    )
32
 
from breezy.bzr import (
33
 
    remote,
34
 
    )
35
33
 
36
 
from breezy.directory_service import directories
37
 
from breezy.tests import (
 
34
from bzrlib.directory_service import directories
 
35
from bzrlib.tests import (
38
36
    fixtures,
39
37
    script,
40
38
    )
45
43
    def example_branch(self, path='.'):
46
44
        tree = self.make_branch_and_tree(path)
47
45
        self.build_tree_contents([
48
 
            (osutils.pathjoin(path, 'hello'),   b'foo'),
49
 
            (osutils.pathjoin(path, 'goodbye'), b'baz')])
 
46
            (osutils.pathjoin(path, 'hello'),   'foo'),
 
47
            (osutils.pathjoin(path, 'goodbye'), 'baz')])
50
48
        tree.add('hello')
51
49
        tree.commit(message='setup')
52
50
        tree.add('goodbye')
68
66
        if sys.platform not in ('win32', 'cygwin'):
69
67
            self.run_bzr('pull', working_dir='a')
70
68
 
71
 
        b_tree = a_tree.controldir.sprout('b').open_workingtree()
 
69
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
72
70
        self.run_bzr('pull', working_dir='b')
73
71
        os.mkdir('b/subdir')
74
72
        b_tree.add('subdir')
85
83
        b_tree.commit(message='blah3', allow_pointless=True)
86
84
        # no overwrite
87
85
        self.run_bzr('pull ../a', retcode=3, working_dir='b')
88
 
        b_tree.controldir.sprout('overwriteme')
 
86
        b_tree.bzrdir.sprout('overwriteme')
89
87
        self.run_bzr('pull --overwrite ../a', working_dir='overwriteme')
90
88
        overwritten = branch.Branch.open('overwriteme')
91
89
        self.assertEqual(overwritten.last_revision(),
120
118
        """Pull some changes from one branch to another."""
121
119
        a_tree = self.example_branch('a')
122
120
        self.build_tree_contents([
123
 
            ('a/hello2',   b'foo'),
124
 
            ('a/goodbye2', b'baz')])
 
121
            ('a/hello2',   'foo'),
 
122
            ('a/goodbye2', 'baz')])
125
123
        a_tree.add('hello2')
126
124
        a_tree.commit(message="setup")
127
125
        a_tree.add('goodbye2')
128
126
        a_tree.commit(message="setup")
129
127
 
130
 
        b_tree = a_tree.controldir.sprout(
131
 
                'b', revision_id=a_tree.branch.get_rev_id(1)).open_workingtree()
 
128
        b_tree = a_tree.bzrdir.sprout('b',
 
129
                   revision_id=a_tree.branch.get_rev_id(1)).open_workingtree()
132
130
        self.run_bzr('pull -r 2', working_dir='b')
133
131
        a = branch.Branch.open('a')
134
132
        b = branch.Branch.open('b')
135
 
        self.assertEqual(a.revno(), 4)
136
 
        self.assertEqual(b.revno(), 2)
 
133
        self.assertEqual(a.revno(),4)
 
134
        self.assertEqual(b.revno(),2)
137
135
        self.run_bzr('pull -r 3', working_dir='b')
138
 
        self.assertEqual(b.revno(), 3)
 
136
        self.assertEqual(b.revno(),3)
139
137
        self.run_bzr('pull -r 4', working_dir='b')
140
138
        self.assertEqual(a.last_revision(), b.last_revision())
141
139
 
145
143
        """
146
144
        # Make a source, sprout a target off it
147
145
        builder = self.make_branch_builder('source')
148
 
        source, rev1, rev2 = fixtures.build_branch_with_non_ancestral_rev(builder)
 
146
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
149
147
        source.get_config_stack().set('branch.fetch_tags', True)
150
 
        target_bzrdir = source.controldir.sprout('target')
151
 
        source.tags.set_tag('tag-a', rev2)
 
148
        target_bzrdir = source.bzrdir.sprout('target')
 
149
        source.tags.set_tag('tag-a', 'rev-2')
152
150
        # Pull from source
153
151
        self.run_bzr('pull -d target source')
154
152
        target = target_bzrdir.open_branch()
155
153
        # The tag is present, and so is its revision.
156
 
        self.assertEqual(rev2, target.tags.lookup_tag('tag-a'))
157
 
        target.repository.get_revision(rev2)
 
154
        self.assertEqual('rev-2', target.tags.lookup_tag('tag-a'))
 
155
        target.repository.get_revision('rev-2')
158
156
 
159
157
    def test_overwrite_uptodate(self):
160
158
        # Make sure pull --overwrite overwrites
161
159
        # even if the target branch has merged
162
160
        # everything already.
163
161
        a_tree = self.make_branch_and_tree('a')
164
 
        self.build_tree_contents([('a/foo', b'original\n')])
 
162
        self.build_tree_contents([('a/foo', 'original\n')])
165
163
        a_tree.add('foo')
166
164
        a_tree.commit(message='initial commit')
167
165
 
168
 
        b_tree = a_tree.controldir.sprout('b').open_workingtree()
 
166
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
169
167
 
170
 
        self.build_tree_contents([('a/foo', b'changed\n')])
 
168
        self.build_tree_contents([('a/foo', 'changed\n')])
171
169
        a_tree.commit(message='later change')
172
170
 
173
 
        self.build_tree_contents([('a/foo', b'a third change')])
 
171
        self.build_tree_contents([('a/foo', 'a third change')])
174
172
        a_tree.commit(message='a third change')
175
173
 
176
174
        self.assertEqual(a_tree.branch.last_revision_info()[0], 3)
189
187
        # Make sure pull --overwrite sets the revision-history
190
188
        # to be identical to the pull source, even if we have convergence
191
189
        a_tree = self.make_branch_and_tree('a')
192
 
        self.build_tree_contents([('a/foo', b'original\n')])
 
190
        self.build_tree_contents([('a/foo', 'original\n')])
193
191
        a_tree.add('foo')
194
192
        a_tree.commit(message='initial commit')
195
193
 
196
 
        b_tree = a_tree.controldir.sprout('b').open_workingtree()
 
194
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
197
195
 
198
 
        self.build_tree_contents([('a/foo', b'changed\n')])
 
196
        self.build_tree_contents([('a/foo', 'changed\n')])
199
197
        a_tree.commit(message='later change')
200
198
 
201
 
        self.build_tree_contents([('a/foo', b'a third change')])
 
199
        self.build_tree_contents([('a/foo', 'a third change')])
202
200
        a_tree.commit(message='a third change')
203
201
 
204
202
        self.assertEqual(a_tree.branch.last_revision_info()[0], 3)
208
206
 
209
207
        self.assertEqual(b_tree.branch.last_revision_info()[0], 2)
210
208
 
211
 
        self.build_tree_contents([('a/foo', b'a fourth change\n')])
 
209
        self.build_tree_contents([('a/foo', 'a fourth change\n')])
212
210
        a_tree.commit(message='a fourth change')
213
211
 
214
212
        rev_info_a = a_tree.branch.last_revision_info()
229
227
        self.build_tree(['branch_a/a'])
230
228
        tree_a.add('a')
231
229
        tree_a.commit('commit a')
232
 
        tree_b = branch_a.controldir.sprout('branch_b').open_workingtree()
 
230
        tree_b = branch_a.bzrdir.sprout('branch_b').open_workingtree()
233
231
        branch_b = tree_b.branch
234
 
        tree_c = branch_a.controldir.sprout('branch_c').open_workingtree()
 
232
        tree_c = branch_a.bzrdir.sprout('branch_c').open_workingtree()
235
233
        branch_c = tree_c.branch
236
234
        self.build_tree(['branch_a/b'])
237
235
        tree_a.add('b')
244
242
        # test pull for failure without parent set
245
243
        out = self.run_bzr('pull', retcode=3, working_dir='branch_b')
246
244
        self.assertEqual(out,
247
 
                ('', 'brz: ERROR: No pull location known or specified.\n'))
 
245
                ('','bzr: ERROR: No pull location known or specified.\n'))
248
246
        # test implicit --remember when no parent set, this pull conflicts
249
247
        self.build_tree(['branch_b/d'])
250
248
        tree_b.add('d')
252
250
        out = self.run_bzr('pull ../branch_a', retcode=3,
253
251
                           working_dir='branch_b')
254
252
        self.assertEqual(out,
255
 
                ('', 'brz: ERROR: These branches have diverged.'
 
253
                ('','bzr: ERROR: These branches have diverged.'
256
254
                    ' Use the missing command to see how.\n'
257
255
                    'Use the merge command to reconcile them.\n'))
258
 
        tree_b = tree_b.controldir.open_workingtree()
 
256
        tree_b = tree_b.bzrdir.open_workingtree()
259
257
        branch_b = tree_b.branch
260
258
        self.assertEqual(parent, branch_b.get_parent())
261
259
        # test implicit --remember after resolving previous failure
263
261
        t.delete('branch_b/d')
264
262
        self.run_bzr('pull', working_dir='branch_b')
265
263
        # Refresh the branch object as 'pull' modified it
266
 
        branch_b = branch_b.controldir.open_branch()
 
264
        branch_b = branch_b.bzrdir.open_branch()
267
265
        self.assertEqual(branch_b.get_parent(), parent)
268
266
        # test explicit --remember
269
267
        self.run_bzr('pull ../branch_c --remember', working_dir='branch_b')
270
268
        # Refresh the branch object as 'pull' modified it
271
 
        branch_b = branch_b.controldir.open_branch()
272
 
        self.assertEqual(branch_c.controldir.root_transport.base,
 
269
        branch_b = branch_b.bzrdir.open_branch()
 
270
        self.assertEqual(branch_c.bzrdir.root_transport.base,
273
271
                         branch_b.get_parent())
274
272
 
275
273
    def test_pull_bundle(self):
276
 
        from breezy.testament import Testament
 
274
        from bzrlib.testament import Testament
277
275
        # Build up 2 trees and prepare for a pull
278
276
        tree_a = self.make_branch_and_tree('branch_a')
279
277
        with open('branch_a/a', 'wb') as f:
281
279
        tree_a.add('a')
282
280
        tree_a.commit('message')
283
281
 
284
 
        tree_b = tree_a.controldir.sprout('branch_b').open_workingtree()
 
282
        tree_b = tree_a.bzrdir.sprout('branch_b').open_workingtree()
285
283
 
286
284
        # Make a change to 'a' that 'b' can pull
287
285
        with open('branch_a/a', 'wb') as f:
325
323
        self.assertNotContainsRe(out, 'foo')
326
324
 
327
325
    def test_pull_quiet(self):
328
 
        """Check that brz pull --quiet does not print anything"""
 
326
        """Check that bzr pull --quiet does not print anything"""
329
327
        tree_a = self.make_branch_and_tree('tree_a')
330
328
        self.build_tree(['tree_a/foo'])
331
329
        tree_a.add('foo')
332
330
        revision_id = tree_a.commit('bar')
333
 
        tree_b = tree_a.controldir.sprout('tree_b').open_workingtree()
 
331
        tree_b = tree_a.bzrdir.sprout('tree_b').open_workingtree()
334
332
        out, err = self.run_bzr('pull --quiet -d tree_b')
335
333
        self.assertEqual(out, '')
336
334
        self.assertEqual(err, '')
346
344
    def test_pull_from_directory_service(self):
347
345
        source = self.make_branch_and_tree('source')
348
346
        source.commit('commit 1')
349
 
        target = source.controldir.sprout('target').open_workingtree()
 
347
        target = source.bzrdir.sprout('target').open_workingtree()
350
348
        source_last = source.commit('commit 2')
351
349
        class FooService(object):
352
350
            """A directory service that always returns source"""
379
377
        self.setup_smart_server_with_call_log()
380
378
        parent = self.make_branch_and_tree('parent')
381
379
        parent.commit(message='first commit')
382
 
        child = parent.controldir.sprout('child').open_workingtree()
 
380
        child = parent.bzrdir.sprout('child').open_workingtree()
383
381
        child.commit(message='second commit')
384
382
        checkout = parent.branch.create_checkout('checkout')
385
383
        self.run_bzr(['pull', self.get_url('child')], working_dir='checkout')
386
384
 
387
385
    def test_pull_smart_stacked_streaming_acceptance(self):
388
 
        """'brz pull -r 123' works on stacked, smart branches, even when the
 
386
        """'bzr pull -r 123' works on stacked, smart branches, even when the
389
387
        revision specified by the revno is only present in the fallback
390
388
        repository.
391
389
 
398
396
        parent = self.make_branch_and_tree('parent', format='1.9')
399
397
        parent.commit(message='first commit')
400
398
        parent.commit(message='second commit')
401
 
        local = parent.controldir.sprout('local').open_workingtree()
 
399
        local = parent.bzrdir.sprout('local').open_workingtree()
402
400
        local.commit(message='local commit')
403
401
        local.branch.create_clone_on_transport(
404
402
            self.get_transport('stacked'), stacked_on=self.get_url('parent'))
450
448
        self.assertIsInstance(from_tree.branch, remote.RemoteBranch)
451
449
        from_tree.commit(message='first commit')
452
450
        out, err = self.run_bzr(['pull', '-d', 'to',
453
 
            from_tree.branch.controldir.root_transport.base])
 
451
            from_tree.branch.bzrdir.root_transport.base])
454
452
        self.assertContainsRe(err,
455
453
            "(?m)Doing on-the-fly conversion")
456
454
 
475
473
            "(?m)Fetching into experimental format")
476
474
 
477
475
    def test_pull_show_base(self):
478
 
        """brz pull supports --show-base
 
476
        """bzr pull supports --show-base
479
477
 
480
478
        see https://bugs.launchpad.net/bzr/+bug/202374"""
481
479
        # create two trees with conflicts, setup conflict, check that
482
480
        # conflicted file looks correct
483
481
        a_tree = self.example_branch('a')
484
 
        b_tree = a_tree.controldir.sprout('b').open_workingtree()
 
482
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
485
483
 
486
 
        with open(osutils.pathjoin('a', 'hello'), 'wt') as f:
 
484
        with open(osutils.pathjoin('a', 'hello'),'wt') as f:
487
485
            f.write('fee')
488
486
        a_tree.commit('fee')
489
487
 
490
 
        with open(osutils.pathjoin('b', 'hello'), 'wt') as f:
 
488
        with open(osutils.pathjoin('b', 'hello'),'wt') as f:
491
489
            f.write('fie')
492
490
 
493
 
        out, err=self.run_bzr(['pull', '-d', 'b', 'a', '--show-base'])
 
491
        out,err=self.run_bzr(['pull','-d','b','a','--show-base'])
494
492
 
495
493
        # check for message here
496
494
        self.assertEqual(
509
507
        see https://bugs.launchpad.net/bzr/+bug/1022160"""
510
508
        self.make_branch('from')
511
509
        self.make_branch('to')
512
 
        out = self.run_bzr(['pull', '-d', 'to', 'from', '--show-base'])
 
510
        out = self.run_bzr(['pull','-d','to','from','--show-base'])
513
511
        self.assertEqual(out, ('No revisions or tags to pull.\n',
514
512
                               'No working tree, ignoring --show-base\n'))
515
513
 
520
518
        from_tree.branch.tags.set_tag("mytag", "somerevid")
521
519
        to_tree = self.make_branch_and_tree('to')
522
520
        to_tree.branch.tags.set_tag("mytag", "anotherrevid")
523
 
        out = self.run_bzr(['pull', '-d', 'to', 'from'], retcode=1)
 
521
        out = self.run_bzr(['pull','-d','to','from'],retcode=1)
524
522
        self.assertEqual(out,
525
523
            ('No revisions to pull.\nConflicting tags:\n    mytag\n', ''))
526
524
 
542
540
        to_tree.branch.tags.set_tag("mytag", "anotherrevid")
543
541
        revid1 = to_tree.commit('my commit')
544
542
        out = self.run_bzr(['pull', '-d', 'to', 'from'], retcode=1)
545
 
        self.assertEqual(out,
 
543
        self.assertEquals(out,
546
544
            ('No revisions to pull.\nConflicting tags:\n    mytag\n', ''))
547
545
        out = self.run_bzr(['pull', '-d', 'to', '--overwrite-tags', 'from'])
548
 
        self.assertEqual(out, ('1 tag(s) updated.\n', ''))
 
546
        self.assertEquals(out, ('1 tag(s) updated.\n', ''))
549
547
 
550
 
        self.assertEqual(to_tree.branch.tags.lookup_tag('mytag'),
 
548
        self.assertEquals(to_tree.branch.tags.lookup_tag('mytag'),
551
549
                          'somerevid')
552
 
        self.assertEqual(to_tree.branch.last_revision(), revid1)
 
550
        self.assertEquals(to_tree.branch.last_revision(), revid1)
553
551
 
554
552
    def test_pull_tag_overwrite(self):
555
553
        """pulling tags with --overwrite only reports changed tags."""
567
565
 
568
566
    def test_pull_log_format(self):
569
567
        self.run_script("""
570
 
            $ brz init trunk
 
568
            $ bzr init trunk
571
569
            Created a standalone tree (format: 2a)
572
570
            $ cd trunk
573
571
            $ echo foo > file
574
 
            $ brz add
 
572
            $ bzr add
575
573
            adding file
576
 
            $ brz commit -m 'we need some foo'
 
574
            $ bzr commit -m 'we need some foo'
577
575
            2>Committing to:...trunk/
578
576
            2>added file
579
577
            2>Committed revision 1.
580
578
            $ cd ..
581
 
            $ brz init feature
 
579
            $ bzr init feature
582
580
            Created a standalone tree (format: 2a)
583
581
            $ cd feature
584
 
            $ brz pull -v ../trunk -Olog_format=line
 
582
            $ bzr pull -v ../trunk -Olog_format=line
585
583
            Now on revision 1.
586
584
            Added Revisions:
587
585
            1: jrandom@example.com ...we need some foo