~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Jelmer Vernooij
  • Date: 2012-01-27 19:05:43 UTC
  • mto: This revision was merged to the branch mainline in revision 6450.
  • Revision ID: jelmer@samba.org-20120127190543-vk350mv4a0c7aug2
Fix weave test.

Show diffs side-by-side

added added

removed removed

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