~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Andrew Bennetts
  • Date: 2010-10-08 08:15:14 UTC
  • mto: This revision was merged to the branch mainline in revision 5498.
  • Revision ID: andrew.bennetts@canonical.com-20101008081514-dviqzrdfwyzsqbz2
Split NEWS into per-release doc/en/release-notes/bzr-*.txt

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2012, 2016 Canonical Ltd
 
1
# Copyright (C) 2006-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
22
22
from bzrlib import (
23
23
    branch,
24
24
    bzrdir,
25
 
    controldir,
26
25
    errors,
27
26
    osutils,
28
27
    tests,
33
32
    )
34
33
from bzrlib.repofmt import knitrepo
35
34
from bzrlib.tests import (
 
35
    blackbox,
36
36
    http_server,
37
 
    scenarios,
38
 
    script,
39
37
    test_foreign,
 
38
    test_server,
40
39
    )
41
 
from bzrlib.tests.matchers import ContainsNoVfsCalls
42
40
from bzrlib.transport import memory
43
41
 
44
42
 
45
 
load_tests = scenarios.load_tests_apply_scenarios
 
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
46
65
 
47
66
 
48
67
class TestPush(tests.TestCaseWithTransport):
57
76
                           ['push', public_url],
58
77
                           working_dir='source')
59
78
 
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.assertEqual(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.assertEqual(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
 
 
80
79
    def test_push_remember(self):
81
80
        """Push changes from one branch to another and test push location."""
82
81
        transport = self.get_transport()
100
99
 
101
100
        # test push for failure without push location set
102
101
        out = self.run_bzr('push', working_dir='branch_a', retcode=3)
103
 
        self.assertEqual(out,
 
102
        self.assertEquals(out,
104
103
                ('','bzr: ERROR: No push location known or specified.\n'))
105
104
 
106
105
        # test not remembered if cannot actually push
107
106
        self.run_bzr('push path/which/doesnt/exist',
108
107
                     working_dir='branch_a', retcode=3)
109
108
        out = self.run_bzr('push', working_dir='branch_a', retcode=3)
110
 
        self.assertEqual(
 
109
        self.assertEquals(
111
110
                ('', 'bzr: ERROR: No push location known or specified.\n'),
112
111
                out)
113
112
 
114
113
        # test implicit --remember when no push location set, push fails
115
114
        out = self.run_bzr('push ../branch_b',
116
115
                           working_dir='branch_a', retcode=3)
117
 
        self.assertEqual(out,
 
116
        self.assertEquals(out,
118
117
                ('','bzr: ERROR: These branches have diverged.  '
119
118
                 '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()
122
 
        self.assertEqual(osutils.abspath(branch_a.get_push_location()),
 
119
        self.assertEquals(osutils.abspath(branch_a.get_push_location()),
123
120
                          osutils.abspath(branch_b.bzrdir.root_transport.base))
124
121
 
125
122
        # test implicit --remember after resolving previous failure
126
123
        uncommit.uncommit(branch=branch_b, tree=tree_b)
127
124
        transport.delete('branch_b/c')
128
125
        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()
131
126
        path = branch_a.get_push_location()
 
127
        self.assertEquals(out,
 
128
                          'Using saved push location: %s\n'
 
129
                          % urlutils.local_path_from_url(path))
132
130
        self.assertEqual(err,
133
 
                         'Using saved push location: %s\n'
134
131
                         'All changes applied successfully.\n'
135
 
                         'Pushed up to revision 2.\n'
136
 
                         % urlutils.local_path_from_url(path))
 
132
                         'Pushed up to revision 2.\n')
137
133
        self.assertEqual(path,
138
134
                         branch_b.bzrdir.root_transport.base)
139
135
        # test explicit --remember
140
136
        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()
143
 
        self.assertEqual(branch_a.get_push_location(),
 
137
        self.assertEquals(branch_a.get_push_location(),
144
138
                          branch_c.bzrdir.root_transport.base)
145
139
 
146
140
    def test_push_without_tree(self):
152
146
        b2 = branch.Branch.open('pushed-location')
153
147
        self.assertEndsWith(b2.base, 'pushed-location/')
154
148
 
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
 
 
166
149
    def test_push_new_branch_revision_count(self):
167
150
        # bzr push of a branch with revisions to a new location
168
151
        # should print the number of revisions equal to the length of the
175
158
        self.assertEqual('', out)
176
159
        self.assertEqual('Created new branch.\n', err)
177
160
 
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
 
 
195
161
    def test_push_only_pushes_history(self):
196
162
        # Knit branches should only push the history for the current revision.
197
163
        format = bzrdir.BzrDirMetaFormat1()
201
167
 
202
168
        def make_shared_tree(path):
203
169
            shared_repo.bzrdir.root_transport.mkdir(path)
204
 
            controldir.ControlDir.create_branch_convenience('repo/' + path)
 
170
            shared_repo.bzrdir.create_branch_convenience('repo/' + path)
205
171
            return workingtree.WorkingTree.open('repo/' + path)
206
172
        tree_a = make_shared_tree('a')
207
173
        self.build_tree(['repo/a/file'])
242
208
        t.commit(allow_pointless=True,
243
209
                message='first commit')
244
210
        self.run_bzr('push -d from to-one')
245
 
        self.assertPathExists('to-one')
 
211
        self.failUnlessExists('to-one')
246
212
        self.run_bzr('push -d %s %s'
247
213
            % tuple(map(urlutils.local_path_to_url, ['from', '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()))
 
214
        self.failUnlessExists('to-two')
265
215
 
266
216
    def test_push_smart_non_stacked_streaming_acceptance(self):
267
217
        self.setup_smart_server_with_call_log()
275
225
        # become necessary for this use case. Please do not adjust this number
276
226
        # upwards without agreement from bzr's network support maintainers.
277
227
        self.assertLength(9, self.hpss_calls)
278
 
        self.assertLength(1, self.hpss_connections)
279
 
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
280
228
 
281
229
    def test_push_smart_stacked_streaming_acceptance(self):
282
230
        self.setup_smart_server_with_call_log()
292
240
        # being too low. If rpc_count increases, more network roundtrips have
293
241
        # become necessary for this use case. Please do not adjust this number
294
242
        # upwards without agreement from bzr's network support maintainers.
295
 
        self.assertLength(15, self.hpss_calls)
296
 
        self.assertLength(1, self.hpss_connections)
297
 
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
 
243
        self.assertLength(14, self.hpss_calls)
298
244
        remote = branch.Branch.open('public')
299
245
        self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
300
246
 
311
257
        # become necessary for this use case. Please do not adjust this number
312
258
        # upwards without agreement from bzr's network support maintainers.
313
259
        self.assertLength(11, self.hpss_calls)
314
 
        self.assertLength(1, self.hpss_connections)
315
 
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
316
260
 
317
261
    def test_push_smart_incremental_acceptance(self):
318
262
        self.setup_smart_server_with_call_log()
329
273
        # become necessary for this use case. Please do not adjust this number
330
274
        # upwards without agreement from bzr's network support maintainers.
331
275
        self.assertLength(11, self.hpss_calls)
332
 
        self.assertLength(1, self.hpss_connections)
333
 
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
334
276
 
335
277
    def test_push_smart_with_default_stacking_url_path_segment(self):
336
278
        # If the default stacked-on location is a path element then branches
375
317
                     working_dir='tree')
376
318
        new_tree = workingtree.WorkingTree.open('new/tree')
377
319
        self.assertEqual(tree.last_revision(), new_tree.last_revision())
378
 
        self.assertPathExists('new/tree/a')
 
320
        self.failUnlessExists('new/tree/a')
379
321
 
380
322
    def test_push_use_existing(self):
381
323
        """'bzr push --use-existing-dir' can push into an existing dir.
396
338
        new_tree = workingtree.WorkingTree.open('target')
397
339
        self.assertEqual(tree.last_revision(), new_tree.last_revision())
398
340
        # The push should have created target/a
399
 
        self.assertPathExists('target/a')
 
341
        self.failUnlessExists('target/a')
400
342
 
401
343
    def test_push_use_existing_into_empty_bzrdir(self):
402
344
        """'bzr push --use-existing-dir' into a dir with an empty .bzr dir
452
394
        self.assertTrue(repo_to.has_revision('from-1'))
453
395
        self.assertFalse(repo_to.has_revision('from-2'))
454
396
        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())
457
397
 
458
398
        self.run_bzr_error(
459
399
            ['bzr: ERROR: bzr push --revision '
515
455
        trunk_public = self.make_branch('public_trunk', format='1.9')
516
456
        trunk_public.pull(trunk_tree.branch)
517
457
        trunk_public_url = self.get_readonly_url('public_trunk')
518
 
        br = trunk_tree.branch
519
 
        br.set_public_branch(trunk_public_url)
 
458
        trunk_tree.branch.set_public_branch(trunk_public_url)
520
459
        # now we do a stacked push, which should determine the public location
521
460
        # for us.
522
461
        out, err = self.run_bzr(['push', '--stacked',
615
554
        self.assertEqual('', out)
616
555
        self.assertEqual('Created new branch.\n', err)
617
556
 
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.assertEqual(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.assertEqual(out, ('', '1 tag updated.\n'))
630
 
        self.assertEqual(to_tree.branch.tags.lookup_tag('mytag'),
631
 
                          'somerevid')
632
 
        self.assertEqual(to_tree.branch.last_revision(), revid1)
633
 
 
634
557
 
635
558
class RedirectingMemoryTransport(memory.MemoryTransport):
636
559
 
683
606
class TestPushRedirect(tests.TestCaseWithTransport):
684
607
 
685
608
    def setUp(self):
686
 
        super(TestPushRedirect, self).setUp()
 
609
        tests.TestCaseWithTransport.setUp(self)
687
610
        self.memory_server = RedirectingMemoryServer()
688
611
        self.start_server(self.memory_server)
689
612
        # Make the branch and tree that we'll be pushing.
729
652
        self.tree.commit('modify file', rev_id='modified')
730
653
 
731
654
    def set_config_push_strict(self, value):
732
 
        br = branch.Branch.open('local')
733
 
        br.get_config_stack().set('push_strict', 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)
734
659
 
735
660
    _default_command = ['push', '../to']
736
661
    _default_wd = 'local'
793
718
        self.assertPushSucceeds([])
794
719
 
795
720
 
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
 
 
806
721
class TestPushStrictWithChanges(tests.TestCaseWithTransport,
807
722
                                TestPushStrictMixin):
808
723
 
809
 
    scenarios = strict_push_change_scenarios 
810
724
    _changes_type = None # Set by load_tests
811
725
 
812
726
    def setUp(self):
892
806
        target_branch = self.make_dummy_builder('dp').get_branch()
893
807
        source_tree = self.make_branch_and_tree("dc")
894
808
        output, error = self.run_bzr("push -d dc dp", retcode=3)
895
 
        self.assertEqual("", output)
896
 
        self.assertEqual(error, "bzr: ERROR: It is not possible to losslessly"
 
809
        self.assertEquals("", output)
 
810
        self.assertEquals(error, "bzr: ERROR: It is not possible to losslessly"
897
811
            " 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
 
            """)