~bzr-pqm/bzr/bzr.dev

« 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:
 
1
# Copyright (C) 2005-2012 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
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
 
16
 
 
17
 
 
18
"""Black-box tests for bzr pull."""
 
19
 
 
20
import os
 
21
import sys
 
22
 
 
23
from bzrlib import (
 
24
    branch,
 
25
    debug,
 
26
    osutils,
 
27
    remote,
 
28
    tests,
 
29
    uncommit,
 
30
    urlutils,
 
31
    workingtree,
 
32
    )
 
33
 
 
34
from bzrlib.directory_service import directories
 
35
from bzrlib.tests import (
 
36
    fixtures,
 
37
    script,
 
38
    )
 
39
 
 
40
 
 
41
class TestPull(tests.TestCaseWithTransport):
 
42
 
 
43
    def example_branch(self, path='.'):
 
44
        tree = self.make_branch_and_tree(path)
 
45
        self.build_tree_contents([
 
46
            (osutils.pathjoin(path, 'hello'),   'foo'),
 
47
            (osutils.pathjoin(path, 'goodbye'), 'baz')])
 
48
        tree.add('hello')
 
49
        tree.commit(message='setup')
 
50
        tree.add('goodbye')
 
51
        tree.commit(message='setup')
 
52
        return tree
 
53
 
 
54
    def test_pull(self):
 
55
        """Pull changes from one branch to another."""
 
56
        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')
 
62
        # this will work on windows because we check for the same branch
 
63
        # 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')
 
66
        if sys.platform not in ('win32', 'cygwin'):
 
67
            self.run_bzr('pull', working_dir='a')
 
68
 
 
69
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
 
70
        self.run_bzr('pull', working_dir='b')
 
71
        os.mkdir('b/subdir')
 
72
        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())
 
82
        a_tree.commit(message='blah2', allow_pointless=True)
 
83
        b_tree.commit(message='blah3', allow_pointless=True)
 
84
        # no overwrite
 
85
        self.run_bzr('pull ../a', retcode=3, working_dir='b')
 
86
        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())
 
91
        a_tree.merge_from_branch(b_tree.branch)
 
92
        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]
 
97
        sub_tree.commit(message="blah5", allow_pointless=True)
 
98
        sub_tree.commit(message="blah6", allow_pointless=True)
 
99
        self.run_bzr('pull ../a', working_dir='b')
 
100
        a_tree.commit(message="blah7", allow_pointless=True)
 
101
        a_tree.merge_from_branch(b_tree.branch)
 
102
        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')
 
105
 
 
106
    def test_pull_dash_d(self):
 
107
        self.example_branch('a')
 
108
        self.make_branch_and_tree('b')
 
109
        self.make_branch_and_tree('c')
 
110
        # pull into that branch
 
111
        self.run_bzr('pull -d b a')
 
112
        # pull into a branch specified by a url
 
113
        c_url = urlutils.local_path_to_url('c')
 
114
        self.assertStartsWith(c_url, 'file://')
 
115
        self.run_bzr(['pull', '-d', c_url, 'a'])
 
116
 
 
117
    def test_pull_revision(self):
 
118
        """Pull some changes from one branch to another."""
 
119
        a_tree = self.example_branch('a')
 
120
        self.build_tree_contents([
 
121
            ('a/hello2',   'foo'),
 
122
            ('a/goodbye2', 'baz')])
 
123
        a_tree.add('hello2')
 
124
        a_tree.commit(message="setup")
 
125
        a_tree.add('goodbye2')
 
126
        a_tree.commit(message="setup")
 
127
 
 
128
        b_tree = a_tree.bzrdir.sprout('b',
 
129
                   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')
 
133
        self.assertEqual(a.revno(),4)
 
134
        self.assertEqual(b.revno(),2)
 
135
        self.run_bzr('pull -r 3', working_dir='b')
 
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())
 
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
 
 
157
    def test_overwrite_uptodate(self):
 
158
        # Make sure pull --overwrite overwrites
 
159
        # even if the target branch has merged
 
160
        # everything already.
 
161
        a_tree = self.make_branch_and_tree('a')
 
162
        self.build_tree_contents([('a/foo', 'original\n')])
 
163
        a_tree.add('foo')
 
164
        a_tree.commit(message='initial commit')
 
165
 
 
166
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
 
167
 
 
168
        self.build_tree_contents([('a/foo', 'changed\n')])
 
169
        a_tree.commit(message='later change')
 
170
 
 
171
        self.build_tree_contents([('a/foo', 'a third change')])
 
172
        a_tree.commit(message='a third change')
 
173
 
 
174
        self.assertEqual(a_tree.branch.last_revision_info()[0], 3)
 
175
 
 
176
        b_tree.merge_from_branch(a_tree.branch)
 
177
        b_tree.commit(message='merge')
 
178
 
 
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())
 
185
 
 
186
    def test_overwrite_children(self):
 
187
        # Make sure pull --overwrite sets the revision-history
 
188
        # to be identical to the pull source, even if we have convergence
 
189
        a_tree = self.make_branch_and_tree('a')
 
190
        self.build_tree_contents([('a/foo', 'original\n')])
 
191
        a_tree.add('foo')
 
192
        a_tree.commit(message='initial commit')
 
193
 
 
194
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
 
195
 
 
196
        self.build_tree_contents([('a/foo', 'changed\n')])
 
197
        a_tree.commit(message='later change')
 
198
 
 
199
        self.build_tree_contents([('a/foo', 'a third change')])
 
200
        a_tree.commit(message='a third change')
 
201
 
 
202
        self.assertEqual(a_tree.branch.last_revision_info()[0], 3)
 
203
 
 
204
        b_tree.merge_from_branch(a_tree.branch)
 
205
        b_tree.commit(message='merge')
 
206
 
 
207
        self.assertEqual(b_tree.branch.last_revision_info()[0], 2)
 
208
 
 
209
        self.build_tree_contents([('a/foo', 'a fourth change\n')])
 
210
        a_tree.commit(message='a fourth change')
 
211
 
 
212
        rev_info_a = a_tree.branch.last_revision_info()
 
213
        self.assertEqual(rev_info_a[0], 4)
 
214
 
 
215
        # With convergence, we could just pull over the
 
216
        # 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)
 
221
 
 
222
    def test_pull_remember(self):
 
223
        """Pull changes from one branch to another and test parent location."""
 
224
        t = self.get_transport()
 
225
        tree_a = self.make_branch_and_tree('branch_a')
 
226
        branch_a = tree_a.branch
 
227
        self.build_tree(['branch_a/a'])
 
228
        tree_a.add('a')
 
229
        tree_a.commit('commit a')
 
230
        tree_b = branch_a.bzrdir.sprout('branch_b').open_workingtree()
 
231
        branch_b = tree_b.branch
 
232
        tree_c = branch_a.bzrdir.sprout('branch_c').open_workingtree()
 
233
        branch_c = tree_c.branch
 
234
        self.build_tree(['branch_a/b'])
 
235
        tree_a.add('b')
 
236
        tree_a.commit('commit b')
 
237
        # reset parent
 
238
        parent = branch_b.get_parent()
 
239
        branch_b = branch.Branch.open('branch_b')
 
240
        branch_b.lock_write()
 
241
        branch_b.set_parent(None)
 
242
        branch_b.unlock()
 
243
        self.assertEqual(None, branch_b.get_parent())
 
244
        # test pull for failure without parent set
 
245
        out = self.run_bzr('pull', retcode=3, working_dir='branch_b')
 
246
        self.assertEqual(out,
 
247
                ('','bzr: ERROR: No pull location known or specified.\n'))
 
248
        # test implicit --remember when no parent set, this pull conflicts
 
249
        self.build_tree(['branch_b/d'])
 
250
        tree_b.add('d')
 
251
        tree_b.commit('commit d')
 
252
        out = self.run_bzr('pull ../branch_a', retcode=3,
 
253
                           working_dir='branch_b')
 
254
        self.assertEqual(out,
 
255
                ('','bzr: ERROR: These branches have diverged.'
 
256
                    ' Use the missing command to see how.\n'
 
257
                    'Use the merge command to reconcile them.\n'))
 
258
        branch_b = branch.Branch.open('branch_b')
 
259
        self.assertEqual(parent, branch_b.get_parent())
 
260
        # test implicit --remember after resolving previous failure
 
261
        uncommit.uncommit(branch=branch_b, tree=tree_b)
 
262
        t.delete('branch_b/d')
 
263
        self.run_bzr('pull', working_dir='branch_b')
 
264
        branch_b = branch.Branch.open('branch_b')
 
265
        self.assertEqual(branch_b.get_parent(), parent)
 
266
        # test explicit --remember
 
267
        self.run_bzr('pull ../branch_c --remember', working_dir='branch_b')
 
268
        branch_b = branch.Branch.open('branch_b')
 
269
        self.assertEqual(branch_c.bzrdir.root_transport.base,
 
270
                         branch_b.get_parent())
 
271
 
 
272
    def test_pull_bundle(self):
 
273
        from bzrlib.testament import Testament
 
274
        # Build up 2 trees and prepare for a pull
 
275
        tree_a = self.make_branch_and_tree('branch_a')
 
276
        with open('branch_a/a', 'wb') as f:
 
277
            f.write('hello')
 
278
        tree_a.add('a')
 
279
        tree_a.commit('message')
 
280
 
 
281
        tree_b = tree_a.bzrdir.sprout('branch_b').open_workingtree()
 
282
 
 
283
        # Make a change to 'a' that 'b' can pull
 
284
        with open('branch_a/a', 'wb') as f:
 
285
            f.write('hey there')
 
286
        tree_a.commit('message')
 
287
 
 
288
        # Create the bundle for 'b' to pull
 
289
        self.run_bzr('bundle ../branch_b -o ../bundle', working_dir='branch_a')
 
290
 
 
291
        out, err = self.run_bzr('pull ../bundle', working_dir='branch_b')
 
292
        self.assertEqual(out,
 
293
                         'Now on revision 2.\n')
 
294
        self.assertEqual(err,
 
295
                ' M  a\nAll changes applied successfully.\n')
 
296
 
 
297
        self.assertEqualDiff(tree_a.branch.last_revision(),
 
298
                             tree_b.branch.last_revision())
 
299
 
 
300
        testament_a = Testament.from_revision(tree_a.branch.repository,
 
301
                                              tree_a.get_parent_ids()[0])
 
302
        testament_b = Testament.from_revision(tree_b.branch.repository,
 
303
                                              tree_b.get_parent_ids()[0])
 
304
        self.assertEqualDiff(testament_a.as_text(),
 
305
                             testament_b.as_text())
 
306
 
 
307
        # it is legal to attempt to pull an already-merged bundle
 
308
        out, err = self.run_bzr('pull ../bundle', working_dir='branch_b')
 
309
        self.assertEqual(err, '')
 
310
        self.assertEqual(out, 'No revisions or tags to pull.\n')
 
311
 
 
312
    def test_pull_verbose_no_files(self):
 
313
        """Pull --verbose should not list modified files"""
 
314
        tree_a = self.make_branch_and_tree('tree_a')
 
315
        self.build_tree(['tree_a/foo'])
 
316
        tree_a.add('foo')
 
317
        tree_a.commit('bar')
 
318
        tree_b = self.make_branch_and_tree('tree_b')
 
319
        out = self.run_bzr('pull --verbose -d tree_b tree_a')[0]
 
320
        self.assertContainsRe(out, 'bar')
 
321
        self.assertNotContainsRe(out, 'added:')
 
322
        self.assertNotContainsRe(out, 'foo')
 
323
 
 
324
    def test_pull_quiet(self):
 
325
        """Check that bzr pull --quiet does not print anything"""
 
326
        tree_a = self.make_branch_and_tree('tree_a')
 
327
        self.build_tree(['tree_a/foo'])
 
328
        tree_a.add('foo')
 
329
        revision_id = tree_a.commit('bar')
 
330
        tree_b = tree_a.bzrdir.sprout('tree_b').open_workingtree()
 
331
        out, err = self.run_bzr('pull --quiet -d tree_b')
 
332
        self.assertEqual(out, '')
 
333
        self.assertEqual(err, '')
 
334
        self.assertEqual(tree_b.last_revision(), revision_id)
 
335
        self.build_tree(['tree_a/moo'])
 
336
        tree_a.add('moo')
 
337
        revision_id = tree_a.commit('quack')
 
338
        out, err = self.run_bzr('pull --quiet -d tree_b')
 
339
        self.assertEqual(out, '')
 
340
        self.assertEqual(err, '')
 
341
        self.assertEqual(tree_b.last_revision(), revision_id)
 
342
 
 
343
    def test_pull_from_directory_service(self):
 
344
        source = self.make_branch_and_tree('source')
 
345
        source.commit('commit 1')
 
346
        target = source.bzrdir.sprout('target').open_workingtree()
 
347
        source_last = source.commit('commit 2')
 
348
        class FooService(object):
 
349
            """A directory service that always returns source"""
 
350
 
 
351
            def look_up(self, name, url):
 
352
                return 'source'
 
353
        directories.register('foo:', FooService, 'Testing directory service')
 
354
        self.addCleanup(directories.remove, 'foo:')
 
355
        self.run_bzr('pull foo:bar -d target')
 
356
        self.assertEqual(source_last, target.last_revision())
 
357
 
 
358
    def test_pull_verbose_defaults_to_long(self):
 
359
        tree = self.example_branch('source')
 
360
        target = self.make_branch_and_tree('target')
 
361
        out = self.run_bzr('pull -v source -d target')[0]
 
362
        self.assertContainsRe(out,
 
363
                              r'revno: 1\ncommitter: .*\nbranch nick: source')
 
364
        self.assertNotContainsRe(out, r'\n {4}1 .*\n {6}setup\n')
 
365
 
 
366
    def test_pull_verbose_uses_default_log(self):
 
367
        tree = self.example_branch('source')
 
368
        target = self.make_branch_and_tree('target')
 
369
        target.branch.lock_write()
 
370
        try:
 
371
            target.branch.get_config_stack().set('log_format', 'short')
 
372
        finally:
 
373
            target.branch.unlock()
 
374
        out = self.run_bzr('pull -v source -d target')[0]
 
375
        self.assertContainsRe(out, r'\n {4}1 .*\n {6}setup\n')
 
376
        self.assertNotContainsRe(
 
377
            out, r'revno: 1\ncommitter: .*\nbranch nick: source')
 
378
 
 
379
    def test_pull_smart_bound_branch(self):
 
380
        self.setup_smart_server_with_call_log()
 
381
        parent = self.make_branch_and_tree('parent')
 
382
        parent.commit(message='first commit')
 
383
        child = parent.bzrdir.sprout('child').open_workingtree()
 
384
        child.commit(message='second commit')
 
385
        checkout = parent.branch.create_checkout('checkout')
 
386
        self.run_bzr(['pull', self.get_url('child')], working_dir='checkout')
 
387
 
 
388
    def test_pull_smart_stacked_streaming_acceptance(self):
 
389
        """'bzr pull -r 123' works on stacked, smart branches, even when the
 
390
        revision specified by the revno is only present in the fallback
 
391
        repository.
 
392
 
 
393
        See <https://launchpad.net/bugs/380314>
 
394
        """
 
395
        self.setup_smart_server_with_call_log()
 
396
        # Make a stacked-on branch with two commits so that the
 
397
        # revision-history can't be determined just by looking at the parent
 
398
        # field in the revision in the stacked repo.
 
399
        parent = self.make_branch_and_tree('parent', format='1.9')
 
400
        parent.commit(message='first commit')
 
401
        parent.commit(message='second commit')
 
402
        local = parent.bzrdir.sprout('local').open_workingtree()
 
403
        local.commit(message='local commit')
 
404
        local.branch.create_clone_on_transport(
 
405
            self.get_transport('stacked'), stacked_on=self.get_url('parent'))
 
406
        empty = self.make_branch_and_tree('empty', format='1.9')
 
407
        self.reset_smart_call_log()
 
408
        self.run_bzr(['pull', '-r', '1', self.get_url('stacked')],
 
409
            working_dir='empty')
 
410
        # This figure represent the amount of work to perform this use case. It
 
411
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
412
        # being too low. If rpc_count increases, more network roundtrips have
 
413
        # become necessary for this use case. Please do not adjust this number
 
414
        # upwards without agreement from bzr's network support maintainers.
 
415
        self.assertLength(19, self.hpss_calls)
 
416
        self.assertLength(1, self.hpss_connections)
 
417
        remote = branch.Branch.open('stacked')
 
418
        self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
 
419
 
 
420
    def test_pull_cross_format_warning(self):
 
421
        """You get a warning for probably slow cross-format pulls.
 
422
        """
 
423
        # this is assumed to be going through InterDifferingSerializer
 
424
        from_tree = self.make_branch_and_tree('from', format='2a')
 
425
        to_tree = self.make_branch_and_tree('to', format='1.14-rich-root')
 
426
        from_tree.commit(message='first commit')
 
427
        out, err = self.run_bzr(['pull', '-d', 'to', 'from'])
 
428
        self.assertContainsRe(err,
 
429
            "(?m)Doing on-the-fly conversion")
 
430
 
 
431
    def test_pull_cross_format_warning_no_IDS(self):
 
432
        """You get a warning for probably slow cross-format pulls.
 
433
        """
 
434
        # this simulates what would happen across the network, where
 
435
        # interdifferingserializer is not active
 
436
 
 
437
        debug.debug_flags.add('IDS_never')
 
438
        # TestCase take care of restoring them
 
439
 
 
440
        from_tree = self.make_branch_and_tree('from', format='2a')
 
441
        to_tree = self.make_branch_and_tree('to', format='1.14-rich-root')
 
442
        from_tree.commit(message='first commit')
 
443
        out, err = self.run_bzr(['pull', '-d', 'to', 'from'])
 
444
        self.assertContainsRe(err,
 
445
            "(?m)Doing on-the-fly conversion")
 
446
 
 
447
    def test_pull_cross_format_from_network(self):
 
448
        self.setup_smart_server_with_call_log()
 
449
        from_tree = self.make_branch_and_tree('from', format='2a')
 
450
        to_tree = self.make_branch_and_tree('to', format='1.14-rich-root')
 
451
        self.assertIsInstance(from_tree.branch, remote.RemoteBranch)
 
452
        from_tree.commit(message='first commit')
 
453
        out, err = self.run_bzr(['pull', '-d', 'to',
 
454
            from_tree.branch.bzrdir.root_transport.base])
 
455
        self.assertContainsRe(err,
 
456
            "(?m)Doing on-the-fly conversion")
 
457
 
 
458
    def test_pull_to_experimental_format_warning(self):
 
459
        """You get a warning for pulling into experimental formats.
 
460
        """
 
461
        from_tree = self.make_branch_and_tree('from', format='development-subtree')
 
462
        to_tree = self.make_branch_and_tree('to', format='development-subtree')
 
463
        from_tree.commit(message='first commit')
 
464
        out, err = self.run_bzr(['pull', '-d', 'to', 'from'])
 
465
        self.assertContainsRe(err,
 
466
            "(?m)Fetching into experimental format")
 
467
 
 
468
    def test_pull_cross_to_experimental_format_warning(self):
 
469
        """You get a warning for pulling into experimental formats.
 
470
        """
 
471
        from_tree = self.make_branch_and_tree('from', format='2a')
 
472
        to_tree = self.make_branch_and_tree('to', format='development-subtree')
 
473
        from_tree.commit(message='first commit')
 
474
        out, err = self.run_bzr(['pull', '-d', 'to', 'from'])
 
475
        self.assertContainsRe(err,
 
476
            "(?m)Fetching into experimental format")
 
477
 
 
478
    def test_pull_show_base(self):
 
479
        """bzr pull supports --show-base
 
480
 
 
481
        see https://bugs.launchpad.net/bzr/+bug/202374"""
 
482
        # create two trees with conflicts, setup conflict, check that
 
483
        # conflicted file looks correct
 
484
        a_tree = self.example_branch('a')
 
485
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
 
486
 
 
487
        with open(osutils.pathjoin('a', 'hello'),'wt') as f:
 
488
            f.write('fee')
 
489
        a_tree.commit('fee')
 
490
 
 
491
        with open(osutils.pathjoin('b', 'hello'),'wt') as f:
 
492
            f.write('fie')
 
493
 
 
494
        out,err=self.run_bzr(['pull','-d','b','a','--show-base'])
 
495
 
 
496
        # check for message here
 
497
        self.assertEqual(
 
498
            err,
 
499
            ' M  hello\nText conflict in hello\n1 conflicts encountered.\n')
 
500
 
 
501
        self.assertEqualDiff('<<<<<<< TREE\n'
 
502
                             'fie||||||| BASE-REVISION\n'
 
503
                             'foo=======\n'
 
504
                             'fee>>>>>>> MERGE-SOURCE\n',
 
505
                             open(osutils.pathjoin('b', 'hello')).read())
 
506
 
 
507
    def test_pull_show_base_working_tree_only(self):
 
508
        """--show-base only allowed if there's a working tree
 
509
 
 
510
        see https://bugs.launchpad.net/bzr/+bug/202374"""
 
511
        # create a branch, see that --show-base fails
 
512
        self.make_branch('from')
 
513
        self.make_branch('to')
 
514
        out=self.run_bzr(['pull','-d','to','from','--show-base'],retcode=3)
 
515
        self.assertEqual(
 
516
            out, ('','bzr: ERROR: Need working tree for --show-base.\n'))
 
517
 
 
518
    def test_pull_tag_conflicts(self):
 
519
        """pulling tags with conflicts will change the exit code"""
 
520
        # create a branch, see that --show-base fails
 
521
        from_tree = self.make_branch_and_tree('from')
 
522
        from_tree.branch.tags.set_tag("mytag", "somerevid")
 
523
        to_tree = self.make_branch_and_tree('to')
 
524
        to_tree.branch.tags.set_tag("mytag", "anotherrevid")
 
525
        out = self.run_bzr(['pull','-d','to','from'],retcode=1)
 
526
        self.assertEqual(out,
 
527
            ('No revisions to pull.\nConflicting tags:\n    mytag\n', ''))
 
528
 
 
529
    def test_pull_tag_notification(self):
 
530
        """pulling tags with conflicts will change the exit code"""
 
531
        # create a branch, see that --show-base fails
 
532
        from_tree = self.make_branch_and_tree('from')
 
533
        from_tree.branch.tags.set_tag("mytag", "somerevid")
 
534
        to_tree = self.make_branch_and_tree('to')
 
535
        out = self.run_bzr(['pull', '-d', 'to', 'from'])
 
536
        self.assertEqual(out,
 
537
            ('1 tag(s) updated.\n', ''))
 
538
 
 
539
    def test_pull_tag_overwrite(self):
 
540
        """pulling tags with --overwrite only reports changed tags."""
 
541
        # create a branch, see that --show-base fails
 
542
        from_tree = self.make_branch_and_tree('from')
 
543
        from_tree.branch.tags.set_tag("mytag", "somerevid")
 
544
        to_tree = self.make_branch_and_tree('to')
 
545
        to_tree.branch.tags.set_tag("mytag", "somerevid")
 
546
        out = self.run_bzr(['pull', '--overwrite', '-d', 'to', 'from'])
 
547
        self.assertEqual(out,
 
548
            ('No revisions or tags to pull.\n', ''))
 
549
 
 
550
 
 
551
class TestPullOutput(script.TestCaseWithTransportAndScript):
 
552
 
 
553
    def test_pull_log_format(self):
 
554
        self.run_script("""
 
555
            $ bzr init trunk
 
556
            Created a standalone tree (format: 2a)
 
557
            $ cd trunk
 
558
            $ echo foo > file
 
559
            $ bzr add
 
560
            adding file
 
561
            $ bzr commit -m 'we need some foo'
 
562
            2>Committing to:...trunk/
 
563
            2>added file
 
564
            2>Committed revision 1.
 
565
            $ cd ..
 
566
            $ bzr init feature
 
567
            Created a standalone tree (format: 2a)
 
568
            $ cd feature
 
569
            $ bzr pull -v ../trunk -Olog_format=line
 
570
            Now on revision 1.
 
571
            Added Revisions:
 
572
            1: jrandom@example.com ...we need some foo
 
573
            2>+N  file
 
574
            2>All changes applied successfully.
 
575
            """)