~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

(vila) Fix bzrlib.tests.test_gpg.TestVerify.test_verify_revoked_signature
 with recent versions of gpg. (Vincent Ladeuil)

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
#
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()
116
117
        self.assertEquals(out,
117
118
                ('','bzr: ERROR: These branches have diverged.  '
118
119
                 'See "bzr help diverged-branches" for more information.\n'))
 
120
        # Refresh the branch as 'push' modified it
 
121
        branch_a = branch_a.bzrdir.open_branch()
119
122
        self.assertEquals(osutils.abspath(branch_a.get_push_location()),
120
123
                          osutils.abspath(branch_b.bzrdir.root_transport.base))
121
124
 
123
126
        uncommit.uncommit(branch=branch_b, tree=tree_b)
124
127
        transport.delete('branch_b/c')
125
128
        out, err = self.run_bzr('push', working_dir='branch_a')
 
129
        # Refresh the branch as 'push' modified it
 
130
        branch_a = branch_a.bzrdir.open_branch()
126
131
        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
132
        self.assertEqual(err,
 
133
                         'Using saved push location: %s\n'
131
134
                         'All changes applied successfully.\n'
132
 
                         'Pushed up to revision 2.\n')
 
135
                         'Pushed up to revision 2.\n'
 
136
                         % urlutils.local_path_from_url(path))
133
137
        self.assertEqual(path,
134
138
                         branch_b.bzrdir.root_transport.base)
135
139
        # test explicit --remember
136
140
        self.run_bzr('push ../branch_c --remember', working_dir='branch_a')
 
141
        # Refresh the branch as 'push' modified it
 
142
        branch_a = branch_a.bzrdir.open_branch()
137
143
        self.assertEquals(branch_a.get_push_location(),
138
144
                          branch_c.bzrdir.root_transport.base)
139
145
 
146
152
        b2 = branch.Branch.open('pushed-location')
147
153
        self.assertEndsWith(b2.base, 'pushed-location/')
148
154
 
 
155
    def test_push_no_tree(self):
 
156
        # bzr push --no-tree of a branch with working trees
 
157
        b = self.make_branch_and_tree('push-from')
 
158
        self.build_tree(['push-from/file'])
 
159
        b.add('file')
 
160
        b.commit('commit 1')
 
161
        out, err = self.run_bzr('push --no-tree -d push-from push-to')
 
162
        self.assertEqual('', out)
 
163
        self.assertEqual('Created new branch.\n', err)
 
164
        self.assertPathDoesNotExist('push-to/file')
 
165
 
149
166
    def test_push_new_branch_revision_count(self):
150
167
        # bzr push of a branch with revisions to a new location
151
168
        # should print the number of revisions equal to the length of the
158
175
        self.assertEqual('', out)
159
176
        self.assertEqual('Created new branch.\n', err)
160
177
 
 
178
    def test_push_quiet(self):
 
179
        # test that using -q makes output quiet
 
180
        t = self.make_branch_and_tree('tree')
 
181
        self.build_tree(['tree/file'])
 
182
        t.add('file')
 
183
        t.commit('commit 1')
 
184
        self.run_bzr('push -d tree pushed-to')
 
185
        # Refresh the branch as 'push' modified it and get the push location
 
186
        push_loc = t.branch.bzrdir.open_branch().get_push_location()
 
187
        out, err = self.run_bzr('push', working_dir="tree")
 
188
        self.assertEqual('Using saved push location: %s\n'
 
189
                         'No new revisions or tags to push.\n' %
 
190
                         urlutils.local_path_from_url(push_loc), err)
 
191
        out, err = self.run_bzr('push -q', working_dir="tree")
 
192
        self.assertEqual('', out)
 
193
        self.assertEqual('', err)
 
194
 
161
195
    def test_push_only_pushes_history(self):
162
196
        # Knit branches should only push the history for the current revision.
163
197
        format = bzrdir.BzrDirMetaFormat1()
167
201
 
168
202
        def make_shared_tree(path):
169
203
            shared_repo.bzrdir.root_transport.mkdir(path)
170
 
            shared_repo.bzrdir.create_branch_convenience('repo/' + path)
 
204
            controldir.ControlDir.create_branch_convenience('repo/' + path)
171
205
            return workingtree.WorkingTree.open('repo/' + path)
172
206
        tree_a = make_shared_tree('a')
173
207
        self.build_tree(['repo/a/file'])
208
242
        t.commit(allow_pointless=True,
209
243
                message='first commit')
210
244
        self.run_bzr('push -d from to-one')
211
 
        self.failUnlessExists('to-one')
 
245
        self.assertPathExists('to-one')
212
246
        self.run_bzr('push -d %s %s'
213
247
            % tuple(map(urlutils.local_path_to_url, ['from', 'to-two'])))
214
 
        self.failUnlessExists('to-two')
 
248
        self.assertPathExists('to-two')
 
249
 
 
250
    def test_push_repository_no_branch_doesnt_fetch_all_revs(self):
 
251
        # See https://bugs.launchpad.net/bzr/+bug/465517
 
252
        target_repo = self.make_repository('target')
 
253
        source = self.make_branch_builder('source')
 
254
        source.start_series()
 
255
        source.build_snapshot('A', None, [
 
256
            ('add', ('', 'root-id', 'directory', None))])
 
257
        source.build_snapshot('B', ['A'], [])
 
258
        source.build_snapshot('C', ['A'], [])
 
259
        source.finish_series()
 
260
        self.run_bzr('push target -d source')
 
261
        self.addCleanup(target_repo.lock_read().unlock)
 
262
        # We should have pushed 'C', but not 'B', since it isn't in the
 
263
        # ancestry
 
264
        self.assertEqual([('A',), ('C',)], sorted(target_repo.revisions.keys()))
215
265
 
216
266
    def test_push_smart_non_stacked_streaming_acceptance(self):
217
267
        self.setup_smart_server_with_call_log()
225
275
        # become necessary for this use case. Please do not adjust this number
226
276
        # upwards without agreement from bzr's network support maintainers.
227
277
        self.assertLength(9, self.hpss_calls)
 
278
        self.assertLength(1, self.hpss_connections)
 
279
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
228
280
 
229
281
    def test_push_smart_stacked_streaming_acceptance(self):
230
282
        self.setup_smart_server_with_call_log()
240
292
        # being too low. If rpc_count increases, more network roundtrips have
241
293
        # become necessary for this use case. Please do not adjust this number
242
294
        # upwards without agreement from bzr's network support maintainers.
243
 
        self.assertLength(14, self.hpss_calls)
 
295
        self.assertLength(15, self.hpss_calls)
 
296
        self.assertLength(1, self.hpss_connections)
 
297
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
244
298
        remote = branch.Branch.open('public')
245
299
        self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
246
300
 
257
311
        # become necessary for this use case. Please do not adjust this number
258
312
        # upwards without agreement from bzr's network support maintainers.
259
313
        self.assertLength(11, self.hpss_calls)
 
314
        self.assertLength(1, self.hpss_connections)
 
315
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
260
316
 
261
317
    def test_push_smart_incremental_acceptance(self):
262
318
        self.setup_smart_server_with_call_log()
273
329
        # become necessary for this use case. Please do not adjust this number
274
330
        # upwards without agreement from bzr's network support maintainers.
275
331
        self.assertLength(11, self.hpss_calls)
 
332
        self.assertLength(1, self.hpss_connections)
 
333
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
276
334
 
277
335
    def test_push_smart_with_default_stacking_url_path_segment(self):
278
336
        # If the default stacked-on location is a path element then branches
317
375
                     working_dir='tree')
318
376
        new_tree = workingtree.WorkingTree.open('new/tree')
319
377
        self.assertEqual(tree.last_revision(), new_tree.last_revision())
320
 
        self.failUnlessExists('new/tree/a')
 
378
        self.assertPathExists('new/tree/a')
321
379
 
322
380
    def test_push_use_existing(self):
323
381
        """'bzr push --use-existing-dir' can push into an existing dir.
338
396
        new_tree = workingtree.WorkingTree.open('target')
339
397
        self.assertEqual(tree.last_revision(), new_tree.last_revision())
340
398
        # The push should have created target/a
341
 
        self.failUnlessExists('target/a')
 
399
        self.assertPathExists('target/a')
342
400
 
343
401
    def test_push_use_existing_into_empty_bzrdir(self):
344
402
        """'bzr push --use-existing-dir' into a dir with an empty .bzr dir
394
452
        self.assertTrue(repo_to.has_revision('from-1'))
395
453
        self.assertFalse(repo_to.has_revision('from-2'))
396
454
        self.assertEqual(tree_to.branch.last_revision_info()[1], 'from-1')
 
455
        self.assertFalse(
 
456
            tree_to.changes_from(tree_to.basis_tree()).has_changed())
397
457
 
398
458
        self.run_bzr_error(
399
459
            ['bzr: ERROR: bzr push --revision '
455
515
        trunk_public = self.make_branch('public_trunk', format='1.9')
456
516
        trunk_public.pull(trunk_tree.branch)
457
517
        trunk_public_url = self.get_readonly_url('public_trunk')
458
 
        trunk_tree.branch.set_public_branch(trunk_public_url)
 
518
        br = trunk_tree.branch
 
519
        br.set_public_branch(trunk_public_url)
459
520
        # now we do a stacked push, which should determine the public location
460
521
        # for us.
461
522
        out, err = self.run_bzr(['push', '--stacked',
554
615
        self.assertEqual('', out)
555
616
        self.assertEqual('Created new branch.\n', err)
556
617
 
 
618
    def test_overwrite_tags(self):
 
619
        """--overwrite-tags only overwrites tags, not revisions."""
 
620
        from_tree = self.make_branch_and_tree('from')
 
621
        from_tree.branch.tags.set_tag("mytag", "somerevid")
 
622
        to_tree = self.make_branch_and_tree('to')
 
623
        to_tree.branch.tags.set_tag("mytag", "anotherrevid")
 
624
        revid1 = to_tree.commit('my commit')
 
625
        out = self.run_bzr(['push', '-d', 'from', 'to'])
 
626
        self.assertEquals(out,
 
627
            ('Conflicting tags:\n    mytag\n', 'No new revisions to push.\n'))
 
628
        out = self.run_bzr(['push', '-d', 'from', '--overwrite-tags', 'to'])
 
629
        self.assertEquals(out, ('', '1 tag updated.\n'))
 
630
        self.assertEquals(to_tree.branch.tags.lookup_tag('mytag'),
 
631
                          'somerevid')
 
632
        self.assertEquals(to_tree.branch.last_revision(), revid1)
 
633
 
557
634
 
558
635
class RedirectingMemoryTransport(memory.MemoryTransport):
559
636
 
606
683
class TestPushRedirect(tests.TestCaseWithTransport):
607
684
 
608
685
    def setUp(self):
609
 
        tests.TestCaseWithTransport.setUp(self)
 
686
        super(TestPushRedirect, self).setUp()
610
687
        self.memory_server = RedirectingMemoryServer()
611
688
        self.start_server(self.memory_server)
612
689
        # Make the branch and tree that we'll be pushing.
652
729
        self.tree.commit('modify file', rev_id='modified')
653
730
 
654
731
    def set_config_push_strict(self, value):
655
 
        # set config var (any of bazaar.conf, locations.conf, branch.conf
656
 
        # should do)
657
 
        conf = self.tree.branch.get_config()
658
 
        conf.set_user_option('push_strict', value)
 
732
        br = branch.Branch.open('local')
 
733
        br.get_config_stack().set('push_strict', value)
659
734
 
660
735
    _default_command = ['push', '../to']
661
736
    _default_wd = 'local'
718
793
        self.assertPushSucceeds([])
719
794
 
720
795
 
 
796
strict_push_change_scenarios = [
 
797
    ('uncommitted',
 
798
        dict(_changes_type= '_uncommitted_changes')),
 
799
    ('pending-merges',
 
800
        dict(_changes_type= '_pending_merges')),
 
801
    ('out-of-sync-trees',
 
802
        dict(_changes_type= '_out_of_sync_trees')),
 
803
    ]
 
804
 
 
805
 
721
806
class TestPushStrictWithChanges(tests.TestCaseWithTransport,
722
807
                                TestPushStrictMixin):
723
808
 
 
809
    scenarios = strict_push_change_scenarios 
724
810
    _changes_type = None # Set by load_tests
725
811
 
726
812
    def setUp(self):
809
895
        self.assertEquals("", output)
810
896
        self.assertEquals(error, "bzr: ERROR: It is not possible to losslessly"
811
897
            " push to dummy. You may want to use dpush instead.\n")
 
898
 
 
899
 
 
900
class TestPushOutput(script.TestCaseWithTransportAndScript):
 
901
 
 
902
    def test_push_log_format(self):
 
903
        self.run_script("""
 
904
            $ bzr init trunk
 
905
            Created a standalone tree (format: 2a)
 
906
            $ cd trunk
 
907
            $ echo foo > file
 
908
            $ bzr add
 
909
            adding file
 
910
            $ bzr commit -m 'we need some foo'
 
911
            2>Committing to:...trunk/
 
912
            2>added file
 
913
            2>Committed revision 1.
 
914
            $ bzr init ../feature
 
915
            Created a standalone tree (format: 2a)
 
916
            $ bzr push -v ../feature -Olog_format=line
 
917
            Added Revisions:
 
918
            1: jrandom@example.com ...we need some foo
 
919
            2>All changes applied successfully.
 
920
            2>Pushed up to revision 1.
 
921
            """)
 
922
 
 
923
    def test_push_with_revspec(self):
 
924
        self.run_script("""
 
925
            $ bzr init-repo .
 
926
            Shared repository with trees (format: 2a)
 
927
            Location:
 
928
              shared repository: .
 
929
            $ bzr init trunk
 
930
            Created a repository tree (format: 2a)
 
931
            Using shared repository...
 
932
            $ cd trunk
 
933
            $ bzr commit -m 'first rev' --unchanged
 
934
            2>Committing to:...trunk/
 
935
            2>Committed revision 1.
 
936
            $ echo foo > file
 
937
            $ bzr add
 
938
            adding file
 
939
            $ bzr commit -m 'we need some foo'
 
940
            2>Committing to:...trunk/
 
941
            2>added file
 
942
            2>Committed revision 2.
 
943
            $ bzr push -r 1 ../other
 
944
            2>Created new branch.
 
945
            $ bzr st ../other # checking that file is not created (#484516)
 
946
            """)