~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: 2016-01-21 17:48:07 UTC
  • mto: This revision was merged to the branch mainline in revision 6613.
  • Revision ID: v.ladeuil+lp@free.fr-20160121174807-g4ybpaij9ln5wj6a
Make all transport put_bytes() raises TypeError when given unicode strings rather than bytes.

There was a mix of AssertionError or UnicodeEncodeError.

Also deleted test_put_file_unicode() which was bogus, files contain bytes not unicode strings.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2011 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
37
    scenarios,
 
38
    script,
38
39
    test_foreign,
39
 
    test_server,
40
40
    )
 
41
from bzrlib.tests.matchers import ContainsNoVfsCalls
41
42
from bzrlib.transport import memory
42
43
 
43
44
 
56
57
                           ['push', public_url],
57
58
                           working_dir='source')
58
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
 
59
80
    def test_push_remember(self):
60
81
        """Push changes from one branch to another and test push location."""
61
82
        transport = self.get_transport()
96
117
        self.assertEquals(out,
97
118
                ('','bzr: ERROR: These branches have diverged.  '
98
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()
99
122
        self.assertEquals(osutils.abspath(branch_a.get_push_location()),
100
123
                          osutils.abspath(branch_b.bzrdir.root_transport.base))
101
124
 
103
126
        uncommit.uncommit(branch=branch_b, tree=tree_b)
104
127
        transport.delete('branch_b/c')
105
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()
106
131
        path = branch_a.get_push_location()
107
 
        self.assertEquals(out,
108
 
                          'Using saved push location: %s\n'
109
 
                          % urlutils.local_path_from_url(path))
110
132
        self.assertEqual(err,
 
133
                         'Using saved push location: %s\n'
111
134
                         'All changes applied successfully.\n'
112
 
                         'Pushed up to revision 2.\n')
 
135
                         'Pushed up to revision 2.\n'
 
136
                         % urlutils.local_path_from_url(path))
113
137
        self.assertEqual(path,
114
138
                         branch_b.bzrdir.root_transport.base)
115
139
        # test explicit --remember
116
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()
117
143
        self.assertEquals(branch_a.get_push_location(),
118
144
                          branch_c.bzrdir.root_transport.base)
119
145
 
149
175
        self.assertEqual('', out)
150
176
        self.assertEqual('Created new branch.\n', err)
151
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
 
152
195
    def test_push_only_pushes_history(self):
153
196
        # Knit branches should only push the history for the current revision.
154
197
        format = bzrdir.BzrDirMetaFormat1()
158
201
 
159
202
        def make_shared_tree(path):
160
203
            shared_repo.bzrdir.root_transport.mkdir(path)
161
 
            shared_repo.bzrdir.create_branch_convenience('repo/' + path)
 
204
            controldir.ControlDir.create_branch_convenience('repo/' + path)
162
205
            return workingtree.WorkingTree.open('repo/' + path)
163
206
        tree_a = make_shared_tree('a')
164
207
        self.build_tree(['repo/a/file'])
232
275
        # become necessary for this use case. Please do not adjust this number
233
276
        # upwards without agreement from bzr's network support maintainers.
234
277
        self.assertLength(9, self.hpss_calls)
 
278
        self.assertLength(1, self.hpss_connections)
 
279
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
235
280
 
236
281
    def test_push_smart_stacked_streaming_acceptance(self):
237
282
        self.setup_smart_server_with_call_log()
247
292
        # being too low. If rpc_count increases, more network roundtrips have
248
293
        # become necessary for this use case. Please do not adjust this number
249
294
        # upwards without agreement from bzr's network support maintainers.
250
 
        self.assertLength(13, self.hpss_calls)
 
295
        self.assertLength(15, self.hpss_calls)
 
296
        self.assertLength(1, self.hpss_connections)
 
297
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
251
298
        remote = branch.Branch.open('public')
252
299
        self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
253
300
 
264
311
        # become necessary for this use case. Please do not adjust this number
265
312
        # upwards without agreement from bzr's network support maintainers.
266
313
        self.assertLength(11, self.hpss_calls)
 
314
        self.assertLength(1, self.hpss_connections)
 
315
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
267
316
 
268
317
    def test_push_smart_incremental_acceptance(self):
269
318
        self.setup_smart_server_with_call_log()
280
329
        # become necessary for this use case. Please do not adjust this number
281
330
        # upwards without agreement from bzr's network support maintainers.
282
331
        self.assertLength(11, self.hpss_calls)
 
332
        self.assertLength(1, self.hpss_connections)
 
333
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
283
334
 
284
335
    def test_push_smart_with_default_stacking_url_path_segment(self):
285
336
        # If the default stacked-on location is a path element then branches
401
452
        self.assertTrue(repo_to.has_revision('from-1'))
402
453
        self.assertFalse(repo_to.has_revision('from-2'))
403
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())
404
457
 
405
458
        self.run_bzr_error(
406
459
            ['bzr: ERROR: bzr push --revision '
462
515
        trunk_public = self.make_branch('public_trunk', format='1.9')
463
516
        trunk_public.pull(trunk_tree.branch)
464
517
        trunk_public_url = self.get_readonly_url('public_trunk')
465
 
        trunk_tree.branch.set_public_branch(trunk_public_url)
 
518
        br = trunk_tree.branch
 
519
        br.set_public_branch(trunk_public_url)
466
520
        # now we do a stacked push, which should determine the public location
467
521
        # for us.
468
522
        out, err = self.run_bzr(['push', '--stacked',
561
615
        self.assertEqual('', out)
562
616
        self.assertEqual('Created new branch.\n', err)
563
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
 
564
634
 
565
635
class RedirectingMemoryTransport(memory.MemoryTransport):
566
636
 
613
683
class TestPushRedirect(tests.TestCaseWithTransport):
614
684
 
615
685
    def setUp(self):
616
 
        tests.TestCaseWithTransport.setUp(self)
 
686
        super(TestPushRedirect, self).setUp()
617
687
        self.memory_server = RedirectingMemoryServer()
618
688
        self.start_server(self.memory_server)
619
689
        # Make the branch and tree that we'll be pushing.
659
729
        self.tree.commit('modify file', rev_id='modified')
660
730
 
661
731
    def set_config_push_strict(self, value):
662
 
        # set config var (any of bazaar.conf, locations.conf, branch.conf
663
 
        # should do)
664
 
        conf = self.tree.branch.get_config()
665
 
        conf.set_user_option('push_strict', value)
 
732
        br = branch.Branch.open('local')
 
733
        br.get_config_stack().set('push_strict', value)
666
734
 
667
735
    _default_command = ['push', '../to']
668
736
    _default_wd = 'local'
827
895
        self.assertEquals("", output)
828
896
        self.assertEquals(error, "bzr: ERROR: It is not possible to losslessly"
829
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
            """)