~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Vincent Ladeuil
  • Date: 2013-05-25 17:12:43 UTC
  • mto: (6437.77.1 2.5)
  • mto: This revision was merged to the branch mainline in revision 6577.
  • Revision ID: v.ladeuil+lp@free.fr-20130525171243-au0073fnspecl3kg
Empty arguments in EDITOR are now properly preserved

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2011 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
22
22
from bzrlib import (
23
23
    branch,
24
24
    bzrdir,
 
25
    controldir,
25
26
    errors,
26
27
    osutils,
27
28
    tests,
32
33
    )
33
34
from bzrlib.repofmt import knitrepo
34
35
from bzrlib.tests import (
35
 
    blackbox,
36
36
    http_server,
 
37
    scenarios,
 
38
    script,
37
39
    test_foreign,
38
 
    test_server,
39
40
    )
 
41
from bzrlib.tests.matchers import ContainsNoVfsCalls
40
42
from bzrlib.transport import memory
41
43
 
42
44
 
43
 
def load_tests(standard_tests, module, loader):
44
 
    """Multiply tests for the push command."""
45
 
    result = loader.suiteClass()
46
 
 
47
 
    # one for each king of change
48
 
    changes_tests, remaining_tests = tests.split_suite_by_condition(
49
 
        standard_tests, tests.condition_isinstance((
50
 
                TestPushStrictWithChanges,
51
 
                )))
52
 
    changes_scenarios = [
53
 
        ('uncommitted',
54
 
         dict(_changes_type= '_uncommitted_changes')),
55
 
        ('pending-merges',
56
 
         dict(_changes_type= '_pending_merges')),
57
 
        ('out-of-sync-trees',
58
 
         dict(_changes_type= '_out_of_sync_trees')),
59
 
        ]
60
 
    tests.multiply_tests(changes_tests, changes_scenarios, result)
61
 
    # No parametrization for the remaining tests
62
 
    result.addTests(remaining_tests)
63
 
 
64
 
    return result
 
45
load_tests = scenarios.load_tests_apply_scenarios
65
46
 
66
47
 
67
48
class TestPush(tests.TestCaseWithTransport):
76
57
                           ['push', public_url],
77
58
                           working_dir='source')
78
59
 
 
60
    def test_push_suggests_parent_alias(self):
 
61
        """Push suggests using :parent if there is a known parent branch."""
 
62
        tree_a = self.make_branch_and_tree('a')
 
63
        tree_a.commit('this is a commit')
 
64
        tree_b = self.make_branch_and_tree('b')
 
65
 
 
66
        # If there is no parent location set, :parent isn't mentioned.
 
67
        out = self.run_bzr('push', working_dir='a', retcode=3)
 
68
        self.assertEquals(out,
 
69
                ('','bzr: ERROR: No push location known or specified.\n'))
 
70
 
 
71
        # If there is a parent location set, the error suggests :parent.
 
72
        tree_a.branch.set_parent(tree_b.branch.base)
 
73
        out = self.run_bzr('push', working_dir='a', retcode=3)
 
74
        self.assertEquals(out,
 
75
            ('','bzr: ERROR: No push location known or specified. '
 
76
                'To push to the parent branch '
 
77
                '(at %s), use \'bzr push :parent\'.\n' %
 
78
                urlutils.unescape_for_display(tree_b.branch.base, 'utf-8')))
 
79
 
79
80
    def test_push_remember(self):
80
81
        """Push changes from one branch to another and test push location."""
81
82
        transport = self.get_transport()
124
125
        transport.delete('branch_b/c')
125
126
        out, err = self.run_bzr('push', working_dir='branch_a')
126
127
        path = branch_a.get_push_location()
127
 
        self.assertEquals(out,
128
 
                          'Using saved push location: %s\n'
129
 
                          % urlutils.local_path_from_url(path))
130
128
        self.assertEqual(err,
 
129
                         'Using saved push location: %s\n'
131
130
                         'All changes applied successfully.\n'
132
 
                         'Pushed up to revision 2.\n')
 
131
                         'Pushed up to revision 2.\n'
 
132
                         % urlutils.local_path_from_url(path))
133
133
        self.assertEqual(path,
134
134
                         branch_b.bzrdir.root_transport.base)
135
135
        # test explicit --remember
146
146
        b2 = branch.Branch.open('pushed-location')
147
147
        self.assertEndsWith(b2.base, 'pushed-location/')
148
148
 
 
149
    def test_push_no_tree(self):
 
150
        # bzr push --no-tree of a branch with working trees
 
151
        b = self.make_branch_and_tree('push-from')
 
152
        self.build_tree(['push-from/file'])
 
153
        b.add('file')
 
154
        b.commit('commit 1')
 
155
        out, err = self.run_bzr('push --no-tree -d push-from push-to')
 
156
        self.assertEqual('', out)
 
157
        self.assertEqual('Created new branch.\n', err)
 
158
        self.assertPathDoesNotExist('push-to/file')
 
159
 
149
160
    def test_push_new_branch_revision_count(self):
150
161
        # bzr push of a branch with revisions to a new location
151
162
        # should print the number of revisions equal to the length of the
158
169
        self.assertEqual('', out)
159
170
        self.assertEqual('Created new branch.\n', err)
160
171
 
 
172
    def test_push_quiet(self):
 
173
        # test that using -q makes output quiet
 
174
        t = self.make_branch_and_tree('tree')
 
175
        self.build_tree(['tree/file'])
 
176
        t.add('file')
 
177
        t.commit('commit 1')
 
178
        self.run_bzr('push -d tree pushed-to')
 
179
        path = t.branch.get_push_location()
 
180
        out, err = self.run_bzr('push', working_dir="tree")
 
181
        self.assertEqual('Using saved push location: %s\n'
 
182
                         'No new revisions or tags to push.\n' %
 
183
                         urlutils.local_path_from_url(path), err)
 
184
        out, err = self.run_bzr('push -q', working_dir="tree")
 
185
        self.assertEqual('', out)
 
186
        self.assertEqual('', err)
 
187
 
161
188
    def test_push_only_pushes_history(self):
162
189
        # Knit branches should only push the history for the current revision.
163
190
        format = bzrdir.BzrDirMetaFormat1()
167
194
 
168
195
        def make_shared_tree(path):
169
196
            shared_repo.bzrdir.root_transport.mkdir(path)
170
 
            shared_repo.bzrdir.create_branch_convenience('repo/' + path)
 
197
            controldir.ControlDir.create_branch_convenience('repo/' + path)
171
198
            return workingtree.WorkingTree.open('repo/' + path)
172
199
        tree_a = make_shared_tree('a')
173
200
        self.build_tree(['repo/a/file'])
208
235
        t.commit(allow_pointless=True,
209
236
                message='first commit')
210
237
        self.run_bzr('push -d from to-one')
211
 
        self.failUnlessExists('to-one')
 
238
        self.assertPathExists('to-one')
212
239
        self.run_bzr('push -d %s %s'
213
240
            % tuple(map(urlutils.local_path_to_url, ['from', 'to-two'])))
214
 
        self.failUnlessExists('to-two')
 
241
        self.assertPathExists('to-two')
 
242
 
 
243
    def test_push_repository_no_branch_doesnt_fetch_all_revs(self):
 
244
        # See https://bugs.launchpad.net/bzr/+bug/465517
 
245
        target_repo = self.make_repository('target')
 
246
        source = self.make_branch_builder('source')
 
247
        source.start_series()
 
248
        source.build_snapshot('A', None, [
 
249
            ('add', ('', 'root-id', 'directory', None))])
 
250
        source.build_snapshot('B', ['A'], [])
 
251
        source.build_snapshot('C', ['A'], [])
 
252
        source.finish_series()
 
253
        self.run_bzr('push target -d source')
 
254
        self.addCleanup(target_repo.lock_read().unlock)
 
255
        # We should have pushed 'C', but not 'B', since it isn't in the
 
256
        # ancestry
 
257
        self.assertEqual([('A',), ('C',)], sorted(target_repo.revisions.keys()))
215
258
 
216
259
    def test_push_smart_non_stacked_streaming_acceptance(self):
217
260
        self.setup_smart_server_with_call_log()
225
268
        # become necessary for this use case. Please do not adjust this number
226
269
        # upwards without agreement from bzr's network support maintainers.
227
270
        self.assertLength(9, self.hpss_calls)
 
271
        self.assertLength(1, self.hpss_connections)
 
272
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
228
273
 
229
274
    def test_push_smart_stacked_streaming_acceptance(self):
230
275
        self.setup_smart_server_with_call_log()
241
286
        # become necessary for this use case. Please do not adjust this number
242
287
        # upwards without agreement from bzr's network support maintainers.
243
288
        self.assertLength(14, self.hpss_calls)
 
289
        self.assertLength(1, self.hpss_connections)
 
290
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
244
291
        remote = branch.Branch.open('public')
245
292
        self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
246
293
 
257
304
        # become necessary for this use case. Please do not adjust this number
258
305
        # upwards without agreement from bzr's network support maintainers.
259
306
        self.assertLength(11, self.hpss_calls)
 
307
        self.assertLength(1, self.hpss_connections)
 
308
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
260
309
 
261
310
    def test_push_smart_incremental_acceptance(self):
262
311
        self.setup_smart_server_with_call_log()
273
322
        # become necessary for this use case. Please do not adjust this number
274
323
        # upwards without agreement from bzr's network support maintainers.
275
324
        self.assertLength(11, self.hpss_calls)
 
325
        self.assertLength(1, self.hpss_connections)
 
326
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
276
327
 
277
328
    def test_push_smart_with_default_stacking_url_path_segment(self):
278
329
        # If the default stacked-on location is a path element then branches
317
368
                     working_dir='tree')
318
369
        new_tree = workingtree.WorkingTree.open('new/tree')
319
370
        self.assertEqual(tree.last_revision(), new_tree.last_revision())
320
 
        self.failUnlessExists('new/tree/a')
 
371
        self.assertPathExists('new/tree/a')
321
372
 
322
373
    def test_push_use_existing(self):
323
374
        """'bzr push --use-existing-dir' can push into an existing dir.
338
389
        new_tree = workingtree.WorkingTree.open('target')
339
390
        self.assertEqual(tree.last_revision(), new_tree.last_revision())
340
391
        # The push should have created target/a
341
 
        self.failUnlessExists('target/a')
 
392
        self.assertPathExists('target/a')
342
393
 
343
394
    def test_push_use_existing_into_empty_bzrdir(self):
344
395
        """'bzr push --use-existing-dir' into a dir with an empty .bzr dir
654
705
    def set_config_push_strict(self, value):
655
706
        # set config var (any of bazaar.conf, locations.conf, branch.conf
656
707
        # should do)
657
 
        conf = self.tree.branch.get_config()
658
 
        conf.set_user_option('push_strict', value)
 
708
        conf = self.tree.branch.get_config_stack()
 
709
        conf.set('push_strict', value)
659
710
 
660
711
    _default_command = ['push', '../to']
661
712
    _default_wd = 'local'
718
769
        self.assertPushSucceeds([])
719
770
 
720
771
 
 
772
strict_push_change_scenarios = [
 
773
    ('uncommitted',
 
774
        dict(_changes_type= '_uncommitted_changes')),
 
775
    ('pending-merges',
 
776
        dict(_changes_type= '_pending_merges')),
 
777
    ('out-of-sync-trees',
 
778
        dict(_changes_type= '_out_of_sync_trees')),
 
779
    ]
 
780
 
 
781
 
721
782
class TestPushStrictWithChanges(tests.TestCaseWithTransport,
722
783
                                TestPushStrictMixin):
723
784
 
 
785
    scenarios = strict_push_change_scenarios 
724
786
    _changes_type = None # Set by load_tests
725
787
 
726
788
    def setUp(self):
809
871
        self.assertEquals("", output)
810
872
        self.assertEquals(error, "bzr: ERROR: It is not possible to losslessly"
811
873
            " push to dummy. You may want to use dpush instead.\n")
 
874
 
 
875
 
 
876
class TestPushOutput(script.TestCaseWithTransportAndScript):
 
877
 
 
878
    def test_push_log_format(self):
 
879
        self.run_script("""
 
880
            $ bzr init trunk
 
881
            Created a standalone tree (format: 2a)
 
882
            $ cd trunk
 
883
            $ echo foo > file
 
884
            $ bzr add
 
885
            adding file
 
886
            $ bzr commit -m 'we need some foo'
 
887
            2>Committing to:...trunk/
 
888
            2>added file
 
889
            2>Committed revision 1.
 
890
            $ bzr init ../feature
 
891
            Created a standalone tree (format: 2a)
 
892
            $ bzr push -v ../feature -Olog_format=line
 
893
            Added Revisions:
 
894
            1: jrandom@example.com ...we need some foo
 
895
            2>All changes applied successfully.
 
896
            2>Pushed up to revision 1.
 
897
            """)