/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: Robert Collins
  • Date: 2010-05-05 00:05:29 UTC
  • mto: This revision was merged to the branch mainline in revision 5206.
  • Revision ID: robertc@robertcollins.net-20100505000529-ltmllyms5watqj5u
Make 'pydoc bzrlib.tests.build_tree_shape' useful.

Show diffs side-by-side

added added

removed removed

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