~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: John Arbash Meinel
  • Author(s): Mark Hammond
  • Date: 2008-09-09 17:02:21 UTC
  • mto: This revision was merged to the branch mainline in revision 3697.
  • Revision ID: john@arbash-meinel.com-20080909170221-svim3jw2mrz0amp3
An updated transparent icon for bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2012, 2016 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 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
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
18
18
"""Black-box tests for bzr pull."""
20
20
import os
21
21
import sys
22
22
 
23
 
from bzrlib import (
24
 
    branch,
25
 
    debug,
26
 
    osutils,
27
 
    remote,
28
 
    tests,
29
 
    uncommit,
30
 
    urlutils,
31
 
    workingtree,
32
 
    )
33
 
 
 
23
from bzrlib.branch import Branch
34
24
from bzrlib.directory_service import directories
35
 
from bzrlib.tests import (
36
 
    fixtures,
37
 
    script,
38
 
    )
39
 
 
40
 
 
41
 
class TestPull(tests.TestCaseWithTransport):
 
25
from bzrlib.osutils import pathjoin
 
26
from bzrlib.tests.blackbox import ExternalBase
 
27
from bzrlib.uncommit import uncommit
 
28
from bzrlib.workingtree import WorkingTree
 
29
from bzrlib import urlutils
 
30
 
 
31
 
 
32
class TestPull(ExternalBase):
42
33
 
43
34
    def example_branch(self, path='.'):
44
35
        tree = self.make_branch_and_tree(path)
45
36
        self.build_tree_contents([
46
 
            (osutils.pathjoin(path, 'hello'),   'foo'),
47
 
            (osutils.pathjoin(path, 'goodbye'), 'baz')])
 
37
            (pathjoin(path, 'hello'),   'foo'),
 
38
            (pathjoin(path, 'goodbye'), 'baz')])
48
39
        tree.add('hello')
49
40
        tree.commit(message='setup')
50
41
        tree.add('goodbye')
54
45
    def test_pull(self):
55
46
        """Pull changes from one branch to another."""
56
47
        a_tree = self.example_branch('a')
57
 
        base_rev = a_tree.branch.last_revision()
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')
 
48
        os.chdir('a')
 
49
        self.run_bzr('pull', retcode=3)
 
50
        self.run_bzr('missing', retcode=3)
 
51
        self.run_bzr('missing .')
 
52
        self.run_bzr('missing')
62
53
        # this will work on windows because we check for the same branch
63
54
        # in pull - if it fails, it is a regression
64
 
        self.run_bzr('pull', working_dir='a')
65
 
        self.run_bzr('pull /', retcode=3, working_dir='a')
 
55
        self.run_bzr('pull')
 
56
        self.run_bzr('pull /', retcode=3)
66
57
        if sys.platform not in ('win32', 'cygwin'):
67
 
            self.run_bzr('pull', working_dir='a')
 
58
            self.run_bzr('pull')
68
59
 
 
60
        os.chdir('..')
69
61
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
70
 
        self.run_bzr('pull', working_dir='b')
71
 
        os.mkdir('b/subdir')
 
62
        os.chdir('b')
 
63
        self.run_bzr('pull')
 
64
        os.mkdir('subdir')
72
65
        b_tree.add('subdir')
73
 
        new_rev = b_tree.commit(message='blah', allow_pointless=True)
74
 
 
75
 
        a = branch.Branch.open('a')
76
 
        b = branch.Branch.open('b')
77
 
        self.assertEqual(a.last_revision(), base_rev)
78
 
        self.assertEqual(b.last_revision(), new_rev)
79
 
 
80
 
        self.run_bzr('pull ../b', working_dir='a')
81
 
        self.assertEqual(a.last_revision(), b.last_revision())
 
66
        b_tree.commit(message='blah', allow_pointless=True)
 
67
 
 
68
        os.chdir('..')
 
69
        a = Branch.open('a')
 
70
        b = Branch.open('b')
 
71
        self.assertEqual(a.revision_history(), b.revision_history()[:-1])
 
72
 
 
73
        os.chdir('a')
 
74
        self.run_bzr('pull ../b')
 
75
        self.assertEqual(a.revision_history(), b.revision_history())
82
76
        a_tree.commit(message='blah2', allow_pointless=True)
83
77
        b_tree.commit(message='blah3', allow_pointless=True)
84
78
        # no overwrite
85
 
        self.run_bzr('pull ../a', retcode=3, working_dir='b')
 
79
        os.chdir('../b')
 
80
        self.run_bzr('pull ../a', retcode=3)
 
81
        os.chdir('..')
86
82
        b_tree.bzrdir.sprout('overwriteme')
87
 
        self.run_bzr('pull --overwrite ../a', working_dir='overwriteme')
88
 
        overwritten = branch.Branch.open('overwriteme')
89
 
        self.assertEqual(overwritten.last_revision(),
90
 
                         a.last_revision())
 
83
        os.chdir('overwriteme')
 
84
        self.run_bzr('pull --overwrite ../a')
 
85
        overwritten = Branch.open('.')
 
86
        self.assertEqual(overwritten.revision_history(),
 
87
                         a.revision_history())
91
88
        a_tree.merge_from_branch(b_tree.branch)
92
89
        a_tree.commit(message="blah4", allow_pointless=True)
93
 
 
94
 
        self.run_bzr('pull ../../a', working_dir='b/subdir')
95
 
        self.assertEqual(a.last_revision(), b.last_revision())
96
 
        sub_tree = workingtree.WorkingTree.open_containing('b/subdir')[0]
 
90
        os.chdir('../b/subdir')
 
91
        self.run_bzr('pull ../../a')
 
92
        self.assertEqual(a.revision_history()[-1], b.revision_history()[-1])
 
93
        sub_tree = WorkingTree.open_containing('.')[0]
97
94
        sub_tree.commit(message="blah5", allow_pointless=True)
98
95
        sub_tree.commit(message="blah6", allow_pointless=True)
99
 
        self.run_bzr('pull ../a', working_dir='b')
 
96
        os.chdir('..')
 
97
        self.run_bzr('pull ../a')
 
98
        os.chdir('../a')
100
99
        a_tree.commit(message="blah7", allow_pointless=True)
101
100
        a_tree.merge_from_branch(b_tree.branch)
102
101
        a_tree.commit(message="blah8", allow_pointless=True)
103
 
        self.run_bzr('pull ../b', working_dir='a')
104
 
        self.run_bzr('pull ../b', working_dir='a')
 
102
        self.run_bzr('pull ../b')
 
103
        self.run_bzr('pull ../b')
105
104
 
106
105
    def test_pull_dash_d(self):
107
106
        self.example_branch('a')
127
126
 
128
127
        b_tree = a_tree.bzrdir.sprout('b',
129
128
                   revision_id=a_tree.branch.get_rev_id(1)).open_workingtree()
130
 
        self.run_bzr('pull -r 2', working_dir='b')
131
 
        a = branch.Branch.open('a')
132
 
        b = branch.Branch.open('b')
 
129
        os.chdir('b')
 
130
        self.run_bzr('pull -r 2')
 
131
        a = Branch.open('../a')
 
132
        b = Branch.open('.')
133
133
        self.assertEqual(a.revno(),4)
134
134
        self.assertEqual(b.revno(),2)
135
 
        self.run_bzr('pull -r 3', working_dir='b')
 
135
        self.run_bzr('pull -r 3')
136
136
        self.assertEqual(b.revno(),3)
137
 
        self.run_bzr('pull -r 4', working_dir='b')
138
 
        self.assertEqual(a.last_revision(), b.last_revision())
 
137
        self.run_bzr('pull -r 4')
 
138
        self.assertEqual(a.revision_history(), b.revision_history())
139
139
 
140
 
    def test_pull_tags(self):
141
 
        """Tags are updated by pull, and revisions named in those tags are
142
 
        fetched.
143
 
        """
144
 
        # Make a source, sprout a target off it
145
 
        builder = self.make_branch_builder('source')
146
 
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
147
 
        source.get_config_stack().set('branch.fetch_tags', True)
148
 
        target_bzrdir = source.bzrdir.sprout('target')
149
 
        source.tags.set_tag('tag-a', 'rev-2')
150
 
        # Pull from source
151
 
        self.run_bzr('pull -d target source')
152
 
        target = target_bzrdir.open_branch()
153
 
        # The tag is present, and so is its revision.
154
 
        self.assertEqual('rev-2', target.tags.lookup_tag('tag-a'))
155
 
        target.repository.get_revision('rev-2')
156
140
 
157
141
    def test_overwrite_uptodate(self):
158
142
        # Make sure pull --overwrite overwrites
171
155
        self.build_tree_contents([('a/foo', 'a third change')])
172
156
        a_tree.commit(message='a third change')
173
157
 
174
 
        self.assertEqual(a_tree.branch.last_revision_info()[0], 3)
 
158
        rev_history_a = a_tree.branch.revision_history()
 
159
        self.assertEqual(len(rev_history_a), 3)
175
160
 
176
161
        b_tree.merge_from_branch(a_tree.branch)
177
162
        b_tree.commit(message='merge')
178
163
 
179
 
        self.assertEqual(b_tree.branch.last_revision_info()[0], 2)
180
 
 
181
 
        self.run_bzr('pull --overwrite ../a', working_dir='b')
182
 
        (last_revinfo_b) = b_tree.branch.last_revision_info()
183
 
        self.assertEqual(last_revinfo_b[0], 3)
184
 
        self.assertEqual(last_revinfo_b[1], a_tree.branch.last_revision())
 
164
        self.assertEqual(len(b_tree.branch.revision_history()), 2)
 
165
 
 
166
        os.chdir('b')
 
167
        self.run_bzr('pull --overwrite ../a')
 
168
        rev_history_b = b_tree.branch.revision_history()
 
169
        self.assertEqual(len(rev_history_b), 3)
 
170
 
 
171
        self.assertEqual(rev_history_b, rev_history_a)
185
172
 
186
173
    def test_overwrite_children(self):
187
174
        # Make sure pull --overwrite sets the revision-history
199
186
        self.build_tree_contents([('a/foo', 'a third change')])
200
187
        a_tree.commit(message='a third change')
201
188
 
202
 
        self.assertEqual(a_tree.branch.last_revision_info()[0], 3)
 
189
        self.assertEqual(len(a_tree.branch.revision_history()), 3)
203
190
 
204
191
        b_tree.merge_from_branch(a_tree.branch)
205
192
        b_tree.commit(message='merge')
206
193
 
207
 
        self.assertEqual(b_tree.branch.last_revision_info()[0], 2)
 
194
        self.assertEqual(len(b_tree.branch.revision_history()), 2)
208
195
 
209
196
        self.build_tree_contents([('a/foo', 'a fourth change\n')])
210
197
        a_tree.commit(message='a fourth change')
211
198
 
212
 
        rev_info_a = a_tree.branch.last_revision_info()
213
 
        self.assertEqual(rev_info_a[0], 4)
 
199
        rev_history_a = a_tree.branch.revision_history()
 
200
        self.assertEqual(len(rev_history_a), 4)
214
201
 
215
202
        # With convergence, we could just pull over the
216
203
        # new change, but with --overwrite, we want to switch our history
217
 
        self.run_bzr('pull --overwrite ../a', working_dir='b')
218
 
        rev_info_b = b_tree.branch.last_revision_info()
219
 
        self.assertEqual(rev_info_b[0], 4)
220
 
        self.assertEqual(rev_info_b, rev_info_a)
 
204
        os.chdir('b')
 
205
        self.run_bzr('pull --overwrite ../a')
 
206
        rev_history_b = b_tree.branch.revision_history()
 
207
        self.assertEqual(len(rev_history_b), 4)
 
208
 
 
209
        self.assertEqual(rev_history_b, rev_history_a)
221
210
 
222
211
    def test_pull_remember(self):
223
212
        """Pull changes from one branch to another and test parent location."""
224
 
        t = self.get_transport()
 
213
        transport = self.get_transport()
225
214
        tree_a = self.make_branch_and_tree('branch_a')
226
215
        branch_a = tree_a.branch
227
216
        self.build_tree(['branch_a/a'])
236
225
        tree_a.commit('commit b')
237
226
        # reset parent
238
227
        parent = branch_b.get_parent()
239
 
        branch_b = branch.Branch.open('branch_b')
240
228
        branch_b.set_parent(None)
241
229
        self.assertEqual(None, branch_b.get_parent())
242
230
        # test pull for failure without parent set
243
 
        out = self.run_bzr('pull', retcode=3, working_dir='branch_b')
 
231
        os.chdir('branch_b')
 
232
        out = self.run_bzr('pull', retcode=3)
244
233
        self.assertEqual(out,
245
234
                ('','bzr: ERROR: No pull location known or specified.\n'))
246
235
        # test implicit --remember when no parent set, this pull conflicts
247
 
        self.build_tree(['branch_b/d'])
 
236
        self.build_tree(['d'])
248
237
        tree_b.add('d')
249
238
        tree_b.commit('commit d')
250
 
        out = self.run_bzr('pull ../branch_a', retcode=3,
251
 
                           working_dir='branch_b')
 
239
        out = self.run_bzr('pull ../branch_a', retcode=3)
252
240
        self.assertEqual(out,
253
241
                ('','bzr: ERROR: These branches have diverged.'
254
 
                    ' Use the missing command to see how.\n'
255
 
                    'Use the merge command to reconcile them.\n'))
256
 
        tree_b = tree_b.bzrdir.open_workingtree()
257
 
        branch_b = tree_b.branch
258
 
        self.assertEqual(parent, branch_b.get_parent())
 
242
                    ' Use the merge command to reconcile them.\n'))
 
243
        self.assertEqual(branch_b.get_parent(), parent)
259
244
        # test implicit --remember after resolving previous failure
260
 
        uncommit.uncommit(branch=branch_b, tree=tree_b)
261
 
        t.delete('branch_b/d')
262
 
        self.run_bzr('pull', working_dir='branch_b')
263
 
        # Refresh the branch object as 'pull' modified it
264
 
        branch_b = branch_b.bzrdir.open_branch()
 
245
        uncommit(branch=branch_b, tree=tree_b)
 
246
        transport.delete('branch_b/d')
 
247
        self.run_bzr('pull')
265
248
        self.assertEqual(branch_b.get_parent(), parent)
266
249
        # test explicit --remember
267
 
        self.run_bzr('pull ../branch_c --remember', working_dir='branch_b')
268
 
        # Refresh the branch object as 'pull' modified it
269
 
        branch_b = branch_b.bzrdir.open_branch()
270
 
        self.assertEqual(branch_c.bzrdir.root_transport.base,
271
 
                         branch_b.get_parent())
 
250
        self.run_bzr('pull ../branch_c --remember')
 
251
        self.assertEqual(branch_b.get_parent(),
 
252
                          branch_c.bzrdir.root_transport.base)
272
253
 
273
254
    def test_pull_bundle(self):
274
255
        from bzrlib.testament import Testament
275
256
        # Build up 2 trees and prepare for a pull
276
257
        tree_a = self.make_branch_and_tree('branch_a')
277
 
        with open('branch_a/a', 'wb') as f:
278
 
            f.write('hello')
 
258
        f = open('branch_a/a', 'wb')
 
259
        f.write('hello')
 
260
        f.close()
279
261
        tree_a.add('a')
280
262
        tree_a.commit('message')
281
263
 
282
264
        tree_b = tree_a.bzrdir.sprout('branch_b').open_workingtree()
283
265
 
284
266
        # Make a change to 'a' that 'b' can pull
285
 
        with open('branch_a/a', 'wb') as f:
286
 
            f.write('hey there')
 
267
        f = open('branch_a/a', 'wb')
 
268
        f.write('hey there')
 
269
        f.close()
287
270
        tree_a.commit('message')
288
271
 
289
272
        # Create the bundle for 'b' to pull
290
 
        self.run_bzr('bundle ../branch_b -o ../bundle', working_dir='branch_a')
 
273
        os.chdir('branch_a')
 
274
        self.run_bzr('bundle ../branch_b -o ../bundle')
291
275
 
292
 
        out, err = self.run_bzr('pull ../bundle', working_dir='branch_b')
 
276
        os.chdir('../branch_b')
 
277
        out, err = self.run_bzr('pull ../bundle')
293
278
        self.assertEqual(out,
294
279
                         'Now on revision 2.\n')
295
280
        self.assertEqual(err,
296
281
                ' M  a\nAll changes applied successfully.\n')
297
282
 
298
 
        self.assertEqualDiff(tree_a.branch.last_revision(),
299
 
                             tree_b.branch.last_revision())
 
283
        self.assertEqualDiff(tree_a.branch.revision_history(),
 
284
                             tree_b.branch.revision_history())
300
285
 
301
286
        testament_a = Testament.from_revision(tree_a.branch.repository,
302
287
                                              tree_a.get_parent_ids()[0])
306
291
                             testament_b.as_text())
307
292
 
308
293
        # it is legal to attempt to pull an already-merged bundle
309
 
        out, err = self.run_bzr('pull ../bundle', working_dir='branch_b')
 
294
        out, err = self.run_bzr('pull ../bundle')
310
295
        self.assertEqual(err, '')
311
 
        self.assertEqual(out, 'No revisions or tags to pull.\n')
 
296
        self.assertEqual(out, 'No revisions to pull.\n')
312
297
 
313
298
    def test_pull_verbose_no_files(self):
314
299
        """Pull --verbose should not list modified files"""
352
337
            def look_up(self, name, url):
353
338
                return 'source'
354
339
        directories.register('foo:', FooService, 'Testing directory service')
355
 
        self.addCleanup(directories.remove, 'foo:')
 
340
        self.addCleanup(lambda: directories.remove('foo:'))
356
341
        self.run_bzr('pull foo:bar -d target')
357
342
        self.assertEqual(source_last, target.last_revision())
358
 
 
359
 
    def test_pull_verbose_defaults_to_long(self):
360
 
        tree = self.example_branch('source')
361
 
        target = self.make_branch_and_tree('target')
362
 
        out = self.run_bzr('pull -v source -d target')[0]
363
 
        self.assertContainsRe(out,
364
 
                              r'revno: 1\ncommitter: .*\nbranch nick: source')
365
 
        self.assertNotContainsRe(out, r'\n {4}1 .*\n {6}setup\n')
366
 
 
367
 
    def test_pull_verbose_uses_default_log(self):
368
 
        tree = self.example_branch('source')
369
 
        target = self.make_branch_and_tree('target')
370
 
        target.branch.get_config_stack().set('log_format', 'short')
371
 
        out = self.run_bzr('pull -v source -d target')[0]
372
 
        self.assertContainsRe(out, r'\n {4}1 .*\n {6}setup\n')
373
 
        self.assertNotContainsRe(
374
 
            out, r'revno: 1\ncommitter: .*\nbranch nick: source')
375
 
 
376
 
    def test_pull_smart_bound_branch(self):
377
 
        self.setup_smart_server_with_call_log()
378
 
        parent = self.make_branch_and_tree('parent')
379
 
        parent.commit(message='first commit')
380
 
        child = parent.bzrdir.sprout('child').open_workingtree()
381
 
        child.commit(message='second commit')
382
 
        checkout = parent.branch.create_checkout('checkout')
383
 
        self.run_bzr(['pull', self.get_url('child')], working_dir='checkout')
384
 
 
385
 
    def test_pull_smart_stacked_streaming_acceptance(self):
386
 
        """'bzr pull -r 123' works on stacked, smart branches, even when the
387
 
        revision specified by the revno is only present in the fallback
388
 
        repository.
389
 
 
390
 
        See <https://launchpad.net/bugs/380314>
391
 
        """
392
 
        self.setup_smart_server_with_call_log()
393
 
        # Make a stacked-on branch with two commits so that the
394
 
        # revision-history can't be determined just by looking at the parent
395
 
        # field in the revision in the stacked repo.
396
 
        parent = self.make_branch_and_tree('parent', format='1.9')
397
 
        parent.commit(message='first commit')
398
 
        parent.commit(message='second commit')
399
 
        local = parent.bzrdir.sprout('local').open_workingtree()
400
 
        local.commit(message='local commit')
401
 
        local.branch.create_clone_on_transport(
402
 
            self.get_transport('stacked'), stacked_on=self.get_url('parent'))
403
 
        empty = self.make_branch_and_tree('empty', format='1.9')
404
 
        self.reset_smart_call_log()
405
 
        self.run_bzr(['pull', '-r', '1', self.get_url('stacked')],
406
 
            working_dir='empty')
407
 
        # This figure represent the amount of work to perform this use case. It
408
 
        # is entirely ok to reduce this number if a test fails due to rpc_count
409
 
        # being too low. If rpc_count increases, more network roundtrips have
410
 
        # become necessary for this use case. Please do not adjust this number
411
 
        # upwards without agreement from bzr's network support maintainers.
412
 
        self.assertLength(19, self.hpss_calls)
413
 
        self.assertLength(1, self.hpss_connections)
414
 
        remote = branch.Branch.open('stacked')
415
 
        self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
416
 
 
417
 
    def test_pull_cross_format_warning(self):
418
 
        """You get a warning for probably slow cross-format pulls.
419
 
        """
420
 
        # this is assumed to be going through InterDifferingSerializer
421
 
        from_tree = self.make_branch_and_tree('from', format='2a')
422
 
        to_tree = self.make_branch_and_tree('to', format='1.14-rich-root')
423
 
        from_tree.commit(message='first commit')
424
 
        out, err = self.run_bzr(['pull', '-d', 'to', 'from'])
425
 
        self.assertContainsRe(err,
426
 
            "(?m)Doing on-the-fly conversion")
427
 
 
428
 
    def test_pull_cross_format_warning_no_IDS(self):
429
 
        """You get a warning for probably slow cross-format pulls.
430
 
        """
431
 
        # this simulates what would happen across the network, where
432
 
        # interdifferingserializer is not active
433
 
 
434
 
        debug.debug_flags.add('IDS_never')
435
 
        # TestCase take care of restoring them
436
 
 
437
 
        from_tree = self.make_branch_and_tree('from', format='2a')
438
 
        to_tree = self.make_branch_and_tree('to', format='1.14-rich-root')
439
 
        from_tree.commit(message='first commit')
440
 
        out, err = self.run_bzr(['pull', '-d', 'to', 'from'])
441
 
        self.assertContainsRe(err,
442
 
            "(?m)Doing on-the-fly conversion")
443
 
 
444
 
    def test_pull_cross_format_from_network(self):
445
 
        self.setup_smart_server_with_call_log()
446
 
        from_tree = self.make_branch_and_tree('from', format='2a')
447
 
        to_tree = self.make_branch_and_tree('to', format='1.14-rich-root')
448
 
        self.assertIsInstance(from_tree.branch, remote.RemoteBranch)
449
 
        from_tree.commit(message='first commit')
450
 
        out, err = self.run_bzr(['pull', '-d', 'to',
451
 
            from_tree.branch.bzrdir.root_transport.base])
452
 
        self.assertContainsRe(err,
453
 
            "(?m)Doing on-the-fly conversion")
454
 
 
455
 
    def test_pull_to_experimental_format_warning(self):
456
 
        """You get a warning for pulling into experimental formats.
457
 
        """
458
 
        from_tree = self.make_branch_and_tree('from', format='development-subtree')
459
 
        to_tree = self.make_branch_and_tree('to', format='development-subtree')
460
 
        from_tree.commit(message='first commit')
461
 
        out, err = self.run_bzr(['pull', '-d', 'to', 'from'])
462
 
        self.assertContainsRe(err,
463
 
            "(?m)Fetching into experimental format")
464
 
 
465
 
    def test_pull_cross_to_experimental_format_warning(self):
466
 
        """You get a warning for pulling into experimental formats.
467
 
        """
468
 
        from_tree = self.make_branch_and_tree('from', format='2a')
469
 
        to_tree = self.make_branch_and_tree('to', format='development-subtree')
470
 
        from_tree.commit(message='first commit')
471
 
        out, err = self.run_bzr(['pull', '-d', 'to', 'from'])
472
 
        self.assertContainsRe(err,
473
 
            "(?m)Fetching into experimental format")
474
 
 
475
 
    def test_pull_show_base(self):
476
 
        """bzr pull supports --show-base
477
 
 
478
 
        see https://bugs.launchpad.net/bzr/+bug/202374"""
479
 
        # create two trees with conflicts, setup conflict, check that
480
 
        # conflicted file looks correct
481
 
        a_tree = self.example_branch('a')
482
 
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
483
 
 
484
 
        with open(osutils.pathjoin('a', 'hello'),'wt') as f:
485
 
            f.write('fee')
486
 
        a_tree.commit('fee')
487
 
 
488
 
        with open(osutils.pathjoin('b', 'hello'),'wt') as f:
489
 
            f.write('fie')
490
 
 
491
 
        out,err=self.run_bzr(['pull','-d','b','a','--show-base'])
492
 
 
493
 
        # check for message here
494
 
        self.assertEqual(
495
 
            err,
496
 
            ' M  hello\nText conflict in hello\n1 conflicts encountered.\n')
497
 
 
498
 
        self.assertEqualDiff('<<<<<<< TREE\n'
499
 
                             'fie||||||| BASE-REVISION\n'
500
 
                             'foo=======\n'
501
 
                             'fee>>>>>>> MERGE-SOURCE\n',
502
 
                             open(osutils.pathjoin('b', 'hello')).read())
503
 
 
504
 
    def test_pull_warns_about_show_base_when_no_working_tree(self):
505
 
        """--show-base is useless if there's no working tree
506
 
 
507
 
        see https://bugs.launchpad.net/bzr/+bug/1022160"""
508
 
        self.make_branch('from')
509
 
        self.make_branch('to')
510
 
        out = self.run_bzr(['pull','-d','to','from','--show-base'])
511
 
        self.assertEqual(out, ('No revisions or tags to pull.\n',
512
 
                               'No working tree, ignoring --show-base\n'))
513
 
 
514
 
    def test_pull_tag_conflicts(self):
515
 
        """pulling tags with conflicts will change the exit code"""
516
 
        # create a branch, see that --show-base fails
517
 
        from_tree = self.make_branch_and_tree('from')
518
 
        from_tree.branch.tags.set_tag("mytag", "somerevid")
519
 
        to_tree = self.make_branch_and_tree('to')
520
 
        to_tree.branch.tags.set_tag("mytag", "anotherrevid")
521
 
        out = self.run_bzr(['pull','-d','to','from'],retcode=1)
522
 
        self.assertEqual(out,
523
 
            ('No revisions to pull.\nConflicting tags:\n    mytag\n', ''))
524
 
 
525
 
    def test_pull_tag_notification(self):
526
 
        """pulling tags with conflicts will change the exit code"""
527
 
        # create a branch, see that --show-base fails
528
 
        from_tree = self.make_branch_and_tree('from')
529
 
        from_tree.branch.tags.set_tag("mytag", "somerevid")
530
 
        to_tree = self.make_branch_and_tree('to')
531
 
        out = self.run_bzr(['pull', '-d', 'to', 'from'])
532
 
        self.assertEqual(out,
533
 
            ('1 tag(s) updated.\n', ''))
534
 
 
535
 
    def test_overwrite_tags(self):
536
 
        """--overwrite-tags only overwrites tags, not revisions."""
537
 
        from_tree = self.make_branch_and_tree('from')
538
 
        from_tree.branch.tags.set_tag("mytag", "somerevid")
539
 
        to_tree = self.make_branch_and_tree('to')
540
 
        to_tree.branch.tags.set_tag("mytag", "anotherrevid")
541
 
        revid1 = to_tree.commit('my commit')
542
 
        out = self.run_bzr(['pull', '-d', 'to', 'from'], retcode=1)
543
 
        self.assertEqual(out,
544
 
            ('No revisions to pull.\nConflicting tags:\n    mytag\n', ''))
545
 
        out = self.run_bzr(['pull', '-d', 'to', '--overwrite-tags', 'from'])
546
 
        self.assertEqual(out, ('1 tag(s) updated.\n', ''))
547
 
 
548
 
        self.assertEqual(to_tree.branch.tags.lookup_tag('mytag'),
549
 
                          'somerevid')
550
 
        self.assertEqual(to_tree.branch.last_revision(), revid1)
551
 
 
552
 
    def test_pull_tag_overwrite(self):
553
 
        """pulling tags with --overwrite only reports changed tags."""
554
 
        # create a branch, see that --show-base fails
555
 
        from_tree = self.make_branch_and_tree('from')
556
 
        from_tree.branch.tags.set_tag("mytag", "somerevid")
557
 
        to_tree = self.make_branch_and_tree('to')
558
 
        to_tree.branch.tags.set_tag("mytag", "somerevid")
559
 
        out = self.run_bzr(['pull', '--overwrite', '-d', 'to', 'from'])
560
 
        self.assertEqual(out,
561
 
            ('No revisions or tags to pull.\n', ''))
562
 
 
563
 
 
564
 
class TestPullOutput(script.TestCaseWithTransportAndScript):
565
 
 
566
 
    def test_pull_log_format(self):
567
 
        self.run_script("""
568
 
            $ bzr init trunk
569
 
            Created a standalone tree (format: 2a)
570
 
            $ cd trunk
571
 
            $ echo foo > file
572
 
            $ bzr add
573
 
            adding file
574
 
            $ bzr commit -m 'we need some foo'
575
 
            2>Committing to:...trunk/
576
 
            2>added file
577
 
            2>Committed revision 1.
578
 
            $ cd ..
579
 
            $ bzr init feature
580
 
            Created a standalone tree (format: 2a)
581
 
            $ cd feature
582
 
            $ bzr pull -v ../trunk -Olog_format=line
583
 
            Now on revision 1.
584
 
            Added Revisions:
585
 
            1: jrandom@example.com ...we need some foo
586
 
            2>+N  file
587
 
            2>All changes applied successfully.
588
 
            """)