~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Patch Queue Manager
  • Date: 2015-09-30 16:43:21 UTC
  • mfrom: (6603.2.2 fix-keep-dirty)
  • Revision ID: pqm@pqm.ubuntu.com-20150930164321-ct2v2qnmvimqt8qf
(vila) Avoid associating dirty patch headers with the previous file in the
 patch. (Colin Watson)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2012 Canonical Ltd
2
2
# Authors: Aaron Bentley
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
16
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
 
18
18
 
19
 
import sys
20
19
from cStringIO import StringIO
21
20
 
22
21
from bzrlib import (
23
22
    branch,
24
 
    bzrdir,
25
23
    merge_directive,
26
24
    tests,
27
25
    )
 
26
from bzrlib.controldir import ControlDir
28
27
from bzrlib.bundle import serializer
29
28
from bzrlib.transport import memory
30
 
from bzrlib.tests.scenarios import load_tests_apply_scenarios
31
 
 
32
 
 
33
 
load_tests = load_tests_apply_scenarios
 
29
from bzrlib.tests import (
 
30
    scenarios,
 
31
    )
 
32
from bzrlib.tests.matchers import ContainsNoVfsCalls
 
33
 
 
34
 
 
35
load_tests = scenarios.load_tests_apply_scenarios
34
36
 
35
37
 
36
38
class TestSendMixin(object):
60
62
 
61
63
    def setUp(self):
62
64
        super(TestSend, self).setUp()
63
 
        grandparent_tree = bzrdir.BzrDir.create_standalone_workingtree(
 
65
        grandparent_tree = ControlDir.create_standalone_workingtree(
64
66
            'grandparent')
65
67
        self.build_tree_contents([('grandparent/file1', 'grandparent')])
66
68
        grandparent_tree.add('file1')
186
188
 
187
189
    def test_note_revisions(self):
188
190
        stderr = self.run_send([])[1]
189
 
        self.assertEndsWith(stderr, '\nBundling 1 revision(s).\n')
 
191
        self.assertEndsWith(stderr, '\nBundling 1 revision.\n')
190
192
 
191
193
    def test_mailto_option(self):
192
194
        b = branch.Branch.open('branch')
193
 
        b.get_config().set_user_option('mail_client', 'editor')
 
195
        b.get_config_stack().set('mail_client', 'editor')
194
196
        self.run_bzr_error(
195
197
            ('No mail-to address \\(--mail-to\\) or output \\(-o\\) specified',
196
198
            ), 'send -f branch')
197
 
        b.get_config().set_user_option('mail_client', 'bogus')
 
199
        b.get_config_stack().set('mail_client', 'bogus')
198
200
        self.run_send([])
199
 
        self.run_bzr_error(('Unknown mail client: bogus',),
 
201
        self.run_bzr_error(('Bad value "bogus" for option "mail_client"',),
200
202
                           'send -f branch --mail-to jrandom@example.org')
201
 
        b.get_config().set_user_option('submit_to', 'jrandom@example.org')
202
 
        self.run_bzr_error(('Unknown mail client: bogus',),
 
203
        b.get_config_stack().set('submit_to', 'jrandom@example.org')
 
204
        self.run_bzr_error(('Bad value "bogus" for option "mail_client"',),
203
205
                           'send -f branch')
204
206
 
205
207
    def test_mailto_child_option(self):
206
208
        """Make sure that child_submit_to is used."""
207
209
        b = branch.Branch.open('branch')
208
 
        b.get_config().set_user_option('mail_client', 'bogus')
 
210
        b.get_config_stack().set('mail_client', 'bogus')
209
211
        parent = branch.Branch.open('parent')
210
 
        parent.get_config().set_user_option('child_submit_to',
211
 
                           'somebody@example.org')
212
 
        self.run_bzr_error(('Unknown mail client: bogus',),
213
 
                           'send -f branch')
 
212
        parent.get_config_stack().set('child_submit_to', 'somebody@example.org')
 
213
        self.run_bzr_error(('Bad value "bogus" for option "mail_client"',),
 
214
                'send -f branch')
214
215
 
215
216
    def test_format(self):
216
217
        md = self.get_MD(['--format=4'])
228
229
                            'send -f branch -o- --format=0.999')[0]
229
230
 
230
231
    def test_format_child_option(self):
231
 
        parent_config = branch.Branch.open('parent').get_config()
232
 
        parent_config.set_user_option('child_submit_format', '4')
 
232
        br = branch.Branch.open('parent')
 
233
        conf = br.get_config_stack()
 
234
        conf.set('child_submit_format', '4')
233
235
        md = self.get_MD([])
234
236
        self.assertIs(merge_directive.MergeDirective2, md.__class__)
235
237
 
236
 
        parent_config.set_user_option('child_submit_format', '0.9')
 
238
        conf.set('child_submit_format', '0.9')
237
239
        md = self.get_MD([])
238
240
        self.assertFormatIs('# Bazaar revision bundle v0.9', md)
239
241
 
241
243
        self.assertFormatIs('# Bazaar revision bundle v0.9', md)
242
244
        self.assertIs(merge_directive.MergeDirective, md.__class__)
243
245
 
244
 
        parent_config.set_user_option('child_submit_format', '0.999')
 
246
        conf.set('child_submit_format', '0.999')
245
247
        self.run_bzr_error(["No such send format '0.999'"],
246
248
                            'send -f branch -o-')[0]
247
249
 
272
274
 
273
275
    def make_parent_and_local_branches(self):
274
276
        # Create a 'parent' branch as the base
275
 
        self.parent_tree = bzrdir.BzrDir.create_standalone_workingtree('parent')
 
277
        self.parent_tree = ControlDir.create_standalone_workingtree('parent')
276
278
        self.build_tree_contents([('parent/file', 'parent')])
277
279
        self.parent_tree.add('file')
278
280
        self.parent_tree.commit('first commit', rev_id='parent')
291
293
    _default_additional_warning = 'Uncommitted changes will not be sent.'
292
294
 
293
295
    def set_config_send_strict(self, value):
294
 
        # set config var (any of bazaar.conf, locations.conf, branch.conf
295
 
        # should do)
296
 
        conf = self.local_tree.branch.get_config()
297
 
        conf.set_user_option('send_strict', value)
 
296
        br = branch.Branch.open('local')
 
297
        br.get_config_stack().set('send_strict', value)
298
298
 
299
299
    def assertSendFails(self, args):
300
300
        out, err = self.run_send(args, rc=3, err_re=self._default_errors)
308
308
        if revs is None:
309
309
            revs = self._default_sent_revs
310
310
        out, err = self.run_send(args, err_re=err_re)
311
 
        bundling_revs = 'Bundling %d revision(s).\n' % len(revs)
 
311
        if len(revs) == 1:
 
312
            bundling_revs = 'Bundling %d revision.\n'% len(revs)
 
313
        else:
 
314
            bundling_revs = 'Bundling %d revisions.\n' % len(revs)
312
315
        if with_warning:
313
316
            self.assertContainsRe(err, self._default_additional_warning)
314
317
            self.assertEndsWith(err, bundling_revs)
327
330
        super(TestSendStrictWithoutChanges, self).setUp()
328
331
        self.make_parent_and_local_branches()
329
332
 
 
333
    def test_send_without_workingtree(self):
 
334
        ControlDir.open("local").destroy_workingtree()
 
335
        self.assertSendSucceeds([])
 
336
 
330
337
    def test_send_default(self):
331
338
        self.assertSendSucceeds([])
332
339
 
346
353
 
347
354
 
348
355
class TestSendStrictWithChanges(tests.TestCaseWithTransport,
349
 
                                   TestSendStrictMixin):
 
356
                                TestSendStrictMixin):
350
357
 
351
358
    # These are textually the same as test_push.strict_push_change_scenarios,
352
359
    # but since the functions are reimplemented here, the definitions are left
433
440
class TestBundleStrictWithoutChanges(TestSendStrictWithoutChanges):
434
441
 
435
442
    _default_command = ['bundle-revisions', '../parent']
 
443
 
 
444
 
 
445
class TestSmartServerSend(tests.TestCaseWithTransport):
 
446
 
 
447
    def test_send(self):
 
448
        self.setup_smart_server_with_call_log()
 
449
        t = self.make_branch_and_tree('branch')
 
450
        self.build_tree_contents([('branch/foo', 'thecontents')])
 
451
        t.add("foo")
 
452
        t.commit("message")
 
453
        local = t.bzrdir.sprout('local-branch').open_workingtree()
 
454
        self.build_tree_contents([('branch/foo', 'thenewcontents')])
 
455
        local.commit("anothermessage")
 
456
        self.reset_smart_call_log()
 
457
        out, err = self.run_bzr(
 
458
            ['send', '-o', 'x.diff', self.get_url('branch')], working_dir='local-branch')
 
459
        # This figure represent the amount of work to perform this use case. It
 
460
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
461
        # being too low. If rpc_count increases, more network roundtrips have
 
462
        # become necessary for this use case. Please do not adjust this number
 
463
        # upwards without agreement from bzr's network support maintainers.
 
464
        self.assertLength(7, self.hpss_calls)
 
465
        self.assertLength(1, self.hpss_connections)
 
466
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)