/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2006-2012, 2016 Canonical Ltd
1185.84.4 by Aaron Bentley
Use parent branch as default base branch
2
# Authors: Aaron Bentley
3
#
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1185.84.4 by Aaron Bentley
Use parent branch as default base branch
17
7479.2.1 by Jelmer Vernooij
Drop python2 support.
18
from io import (
19
    BytesIO,
20
    )
1185.84.4 by Aaron Bentley
Use parent branch as default base branch
21
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
22
from ... import (
4464.3.1 by Vincent Ladeuil
Fix more imports.
23
    branch,
2681.1.13 by Aaron Bentley
Add support for submit_to config option
24
    merge_directive,
4464.3.1 by Vincent Ladeuil
Fix more imports.
25
    tests,
2681.1.13 by Aaron Bentley
Add support for submit_to config option
26
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
27
from ...controldir import ControlDir
7358.12.2 by Jelmer Vernooij
Fix tests.
28
from ...bzr.bundle import serializer
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
29
from ...transport import memory
30
from .. import (
5861.1.5 by Vincent Ladeuil
Just use scripts, we don't care about the internal trees.
31
    scenarios,
32
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
33
from ..matchers import ContainsNoVfsCalls
5861.1.5 by Vincent Ladeuil
Just use scripts, we don't care about the internal trees.
34
35
36
load_tests = scenarios.load_tests_apply_scenarios
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
37
38
4464.3.7 by Vincent Ladeuil
Use mixins as suggested by Martin on IRC.
39
class TestSendMixin(object):
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
40
4464.3.6 by Vincent Ladeuil
bundle-revisions should support --strict too.
41
    _default_command = ['send', '-o-']
42
    _default_wd = 'branch'
43
44
    def run_send(self, args, cmd=None, rc=0, wd=None, err_re=None):
7143.15.2 by Jelmer Vernooij
Run autopep8.
45
        if cmd is None:
46
            cmd = self._default_command
47
        if wd is None:
48
            wd = self._default_wd
49
        if err_re is None:
50
            err_re = []
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
51
        return self.run_bzr(cmd + args, retcode=rc,
52
                            working_dir=wd,
53
                            error_regexes=err_re)
54
55
    def get_MD(self, args, cmd=None, wd='branch'):
7045.1.13 by Jelmer Vernooij
Fix a few more tests.
56
        md = self.run_send(args, cmd=cmd, wd=wd)[0]
57
        out = BytesIO(md.encode('utf-8'))
4792.7.3 by Martin
MergeDirective.from_lines claims to want an iterable but currently requires a list, rewrite so it really wants an iterable
58
        return merge_directive.MergeDirective.from_lines(out)
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
59
60
    def assertBundleContains(self, revs, args, cmd=None, wd='branch'):
61
        md = self.get_MD(args, cmd=cmd, wd=wd)
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
62
        br = serializer.read_bundle(BytesIO(md.get_raw_bundle()))
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
63
        self.assertEqual(set(revs), set(r.revision_id for r in br.revisions))
64
65
4464.3.7 by Vincent Ladeuil
Use mixins as suggested by Martin on IRC.
66
class TestSend(tests.TestCaseWithTransport, TestSendMixin):
1185.84.4 by Aaron Bentley
Use parent branch as default base branch
67
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
68
    def setUp(self):
69
        super(TestSend, self).setUp()
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
70
        grandparent_tree = ControlDir.create_standalone_workingtree(
4464.3.1 by Vincent Ladeuil
Fix more imports.
71
            'grandparent')
6855.4.1 by Jelmer Vernooij
Yet more bees.
72
        self.build_tree_contents([('grandparent/file1', b'grandparent')])
2681.1.2 by Aaron Bentley
Add support for selecting bundle format
73
        grandparent_tree.add('file1')
6855.4.1 by Jelmer Vernooij
Yet more bees.
74
        grandparent_tree.commit('initial commit', rev_id=b'rev1')
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
75
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
76
        parent_bzrdir = grandparent_tree.controldir.sprout('parent')
1793.2.13 by Aaron Bentley
Use single make function for tests
77
        parent_tree = parent_bzrdir.open_workingtree()
6855.4.1 by Jelmer Vernooij
Yet more bees.
78
        parent_tree.commit('next commit', rev_id=b'rev2')
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
79
7143.15.2 by Jelmer Vernooij
Run autopep8.
80
        branch_tree = parent_tree.controldir.sprout(
81
            'branch').open_workingtree()
6855.4.1 by Jelmer Vernooij
Yet more bees.
82
        self.build_tree_contents([('branch/file1', b'branch')])
83
        branch_tree.commit('last commit', rev_id=b'rev3')
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
84
85
    def assertFormatIs(self, fmt_string, md):
86
        self.assertEqual(fmt_string, md.get_raw_bundle().splitlines()[0])
1793.2.13 by Aaron Bentley
Use single make function for tests
87
1185.84.4 by Aaron Bentley
Use parent branch as default base branch
88
    def test_uses_parent(self):
89
        """Parent location is used as a basis by default"""
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
90
        errmsg = self.run_send([], rc=3, wd='grandparent')[1]
2520.5.4 by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command
91
        self.assertContainsRe(errmsg, 'No submit branch known or specified')
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
92
        stdout, stderr = self.run_send([])
3596.3.1 by James Westby
Give the user a bit more information about which saved location is being used.
93
        self.assertEqual(stderr.count('Using saved parent location'), 1)
7045.1.13 by Jelmer Vernooij
Fix a few more tests.
94
        self.assertBundleContains([b'rev3'], [])
1793.2.14 by Aaron Bentley
Clean up bundle revision specification
95
2681.1.1 by Aaron Bentley
Split 'send' into 'send' and 'bundle'.
96
    def test_bundle(self):
97
        """Bundle works like send, except -o is not required"""
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
98
        errmsg = self.run_send([], cmd=['bundle'], rc=3, wd='grandparent')[1]
2681.1.1 by Aaron Bentley
Split 'send' into 'send' and 'bundle'.
99
        self.assertContainsRe(errmsg, 'No submit branch known or specified')
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
100
        stdout, stderr = self.run_send([], cmd=['bundle'])
3596.3.1 by James Westby
Give the user a bit more information about which saved location is being used.
101
        self.assertEqual(stderr.count('Using saved parent location'), 1)
7045.1.13 by Jelmer Vernooij
Fix a few more tests.
102
        self.assertBundleContains([b'rev3'], [], cmd=['bundle'])
1804.1.1 by Aaron Bentley
Add support for submit location to bundles
103
104
    def test_uses_submit(self):
105
        """Submit location can be used and set"""
7045.1.13 by Jelmer Vernooij
Fix a few more tests.
106
        self.assertBundleContains([b'rev3'], [])
107
        self.assertBundleContains([b'rev3', b'rev2'], ['../grandparent'])
1804.1.1 by Aaron Bentley
Add support for submit location to bundles
108
        # submit location should be auto-remembered
7045.1.13 by Jelmer Vernooij
Fix a few more tests.
109
        self.assertBundleContains([b'rev3', b'rev2'], [])
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
110
111
        self.run_send(['../parent'])
112
        # We still point to ../grandparent
7045.1.13 by Jelmer Vernooij
Fix a few more tests.
113
        self.assertBundleContains([b'rev3', b'rev2'], [])
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
114
        # Remember parent now
115
        self.run_send(['../parent', '--remember'])
116
        # Now we point to parent
7045.1.13 by Jelmer Vernooij
Fix a few more tests.
117
        self.assertBundleContains([b'rev3'], [])
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
118
119
        err = self.run_send(['--remember'], rc=3)[1]
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
120
        self.assertContainsRe(err,
7045.1.13 by Jelmer Vernooij
Fix a few more tests.
121
                              '--remember requires a branch to be specified.')
1793.2.14 by Aaron Bentley
Clean up bundle revision specification
122
123
    def test_revision_branch_interaction(self):
7045.1.13 by Jelmer Vernooij
Fix a few more tests.
124
        self.assertBundleContains([b'rev3', b'rev2'], ['../grandparent'])
125
        self.assertBundleContains([b'rev2'], ['../grandparent', '-r-2'])
126
        self.assertBundleContains([b'rev3', b'rev2'],
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
127
                                  ['../grandparent', '-r-2..-1'])
128
        md = self.get_MD(['-r-2..-1'])
7045.1.13 by Jelmer Vernooij
Fix a few more tests.
129
        self.assertEqual(b'rev2', md.base_revision_id)
130
        self.assertEqual(b'rev3', md.revision_id)
2178.4.1 by Alexander Belchenko
Provide tests to illustrate bug #55276 on win32.
131
132
    def test_output(self):
133
        # check output for consistency
2178.4.5 by Alexander Belchenko
Spell-checking (thanks to Aaron)
134
        # win32 stdout converts LF to CRLF,
2520.5.4 by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command
135
        # which would break patch-based bundles
7045.1.13 by Jelmer Vernooij
Fix a few more tests.
136
        self.assertBundleContains([b'rev3'], [])
2490.2.28 by Aaron Bentley
Fix handling of null revision
137
138
    def test_no_common_ancestor(self):
139
        foo = self.make_branch_and_tree('foo')
2520.5.4 by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command
140
        foo.commit('rev a')
2490.2.28 by Aaron Bentley
Fix handling of null revision
141
        bar = self.make_branch_and_tree('bar')
2520.5.4 by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command
142
        bar.commit('rev b')
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
143
        self.run_send(['--from', 'foo', '../bar'], wd='foo')
2520.4.121 by Aaron Bentley
Polish up submit command
144
145
    def test_content_options(self):
146
        """--no-patch and --no-bundle should work and be independant"""
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
147
        md = self.get_MD([])
148
        self.assertIsNot(None, md.bundle)
149
        self.assertIsNot(None, md.patch)
150
151
        md = self.get_MD(['--format=0.9'])
152
        self.assertIsNot(None, md.bundle)
153
        self.assertIsNot(None, md.patch)
154
155
        md = self.get_MD(['--no-patch'])
2520.4.121 by Aaron Bentley
Polish up submit command
156
        self.assertIsNot(None, md.bundle)
157
        self.assertIs(None, md.patch)
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
158
        self.run_bzr_error(['Format 0.9 does not permit bundle with no patch'],
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
159
                           ['send', '--no-patch', '--format=0.9', '-o-'],
160
                           working_dir='branch')
161
        md = self.get_MD(['--no-bundle', '.', '.'])
2520.4.121 by Aaron Bentley
Polish up submit command
162
        self.assertIs(None, md.bundle)
163
        self.assertIsNot(None, md.patch)
2681.1.2 by Aaron Bentley
Add support for selecting bundle format
164
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
165
        md = self.get_MD(['--no-bundle', '--format=0.9', '../parent',
7143.15.2 by Jelmer Vernooij
Run autopep8.
166
                          '.'])
2681.1.2 by Aaron Bentley
Add support for selecting bundle format
167
        self.assertIs(None, md.bundle)
168
        self.assertIsNot(None, md.patch)
169
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
170
        md = self.get_MD(['--no-bundle', '--no-patch', '.', '.'])
2520.4.121 by Aaron Bentley
Polish up submit command
171
        self.assertIs(None, md.bundle)
172
        self.assertIs(None, md.patch)
173
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
174
        md = self.get_MD(['--no-bundle', '--no-patch', '--format=0.9',
175
                          '../parent', '.'])
2681.1.2 by Aaron Bentley
Add support for selecting bundle format
176
        self.assertIs(None, md.bundle)
177
        self.assertIs(None, md.patch)
178
2520.4.121 by Aaron Bentley
Polish up submit command
179
    def test_from_option(self):
2654.3.1 by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout
180
        self.run_bzr('send', retcode=3)
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
181
        md = self.get_MD(['--from', 'branch'])
7045.1.13 by Jelmer Vernooij
Fix a few more tests.
182
        self.assertEqual(b'rev3', md.revision_id)
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
183
        md = self.get_MD(['-f', 'branch'])
7045.1.13 by Jelmer Vernooij
Fix a few more tests.
184
        self.assertEqual(b'rev3', md.revision_id)
2520.4.121 by Aaron Bentley
Polish up submit command
185
186
    def test_output_option(self):
2654.3.1 by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout
187
        stdout = self.run_bzr('send -f branch --output file1')[0]
2520.4.121 by Aaron Bentley
Polish up submit command
188
        self.assertEqual('', stdout)
189
        md_file = open('file1', 'rb')
190
        self.addCleanup(md_file.close)
7045.1.13 by Jelmer Vernooij
Fix a few more tests.
191
        self.assertContainsRe(md_file.read(), b'rev3')
2654.3.1 by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout
192
        stdout = self.run_bzr('send -f branch --output -')[0]
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
193
        self.assertContainsRe(stdout, 'rev3')
2520.4.132 by Aaron Bentley
Merge from bzr.dev
194
3794.4.3 by Aaron Bentley
Switch to blackbox testing.
195
    def test_note_revisions(self):
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
196
        stderr = self.run_send([])[1]
6143.1.4 by Jonathan Riddell
update tests
197
        self.assertEndsWith(stderr, '\nBundling 1 revision.\n')
3794.4.3 by Aaron Bentley
Switch to blackbox testing.
198
2681.1.13 by Aaron Bentley
Add support for submit_to config option
199
    def test_mailto_option(self):
4464.3.1 by Vincent Ladeuil
Fix more imports.
200
        b = branch.Branch.open('branch')
6449.5.2 by Jelmer Vernooij
Use config stacks in tests, too.
201
        b.get_config_stack().set('mail_client', 'editor')
3984.2.1 by Daniel Watkins
Fixed #198418
202
        self.run_bzr_error(
3986.1.2 by Ian Clatworthy
tweak regex pattern in send test
203
            ('No mail-to address \\(--mail-to\\) or output \\(-o\\) specified',
7143.15.2 by Jelmer Vernooij
Run autopep8.
204
             ), 'send -f branch')
6449.5.2 by Jelmer Vernooij
Use config stacks in tests, too.
205
        b.get_config_stack().set('mail_client', 'bogus')
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
206
        self.run_send([])
6449.5.5 by Jelmer Vernooij
Consider invalid mail clients an error rather than just a warning.
207
        self.run_bzr_error(('Bad value "bogus" for option "mail_client"',),
2681.1.13 by Aaron Bentley
Add support for submit_to config option
208
                           'send -f branch --mail-to jrandom@example.org')
6421.3.1 by Vincent Ladeuil
Migrate more branch options to config stacks.
209
        b.get_config_stack().set('submit_to', 'jrandom@example.org')
6449.5.5 by Jelmer Vernooij
Consider invalid mail clients an error rather than just a warning.
210
        self.run_bzr_error(('Bad value "bogus" for option "mail_client"',),
2681.1.13 by Aaron Bentley
Add support for submit_to config option
211
                           'send -f branch')
2681.1.2 by Aaron Bentley
Add support for selecting bundle format
212
3251.1.2 by Jelmer Vernooij
``bzr send`` now supports new ``child_submit_to`` option in the submit branch
213
    def test_mailto_child_option(self):
214
        """Make sure that child_submit_to is used."""
4464.3.1 by Vincent Ladeuil
Fix more imports.
215
        b = branch.Branch.open('branch')
6449.5.2 by Jelmer Vernooij
Use config stacks in tests, too.
216
        b.get_config_stack().set('mail_client', 'bogus')
4464.3.1 by Vincent Ladeuil
Fix more imports.
217
        parent = branch.Branch.open('parent')
6421.3.1 by Vincent Ladeuil
Migrate more branch options to config stacks.
218
        parent.get_config_stack().set('child_submit_to', 'somebody@example.org')
6449.5.5 by Jelmer Vernooij
Consider invalid mail clients an error rather than just a warning.
219
        self.run_bzr_error(('Bad value "bogus" for option "mail_client"',),
7143.15.2 by Jelmer Vernooij
Run autopep8.
220
                           'send -f branch')
3251.1.2 by Jelmer Vernooij
``bzr send`` now supports new ``child_submit_to`` option in the submit branch
221
2681.1.2 by Aaron Bentley
Add support for selecting bundle format
222
    def test_format(self):
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
223
        md = self.get_MD(['--format=4'])
2681.1.2 by Aaron Bentley
Add support for selecting bundle format
224
        self.assertIs(merge_directive.MergeDirective2, md.__class__)
7045.1.13 by Jelmer Vernooij
Fix a few more tests.
225
        self.assertFormatIs(b'# Bazaar revision bundle v4', md)
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
226
227
        md = self.get_MD(['--format=0.9'])
7045.1.13 by Jelmer Vernooij
Fix a few more tests.
228
        self.assertFormatIs(b'# Bazaar revision bundle v0.9', md)
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
229
230
        md = self.get_MD(['--format=0.9'], cmd=['bundle'])
7045.1.13 by Jelmer Vernooij
Fix a few more tests.
231
        self.assertFormatIs(b'# Bazaar revision bundle v0.9', md)
2681.1.2 by Aaron Bentley
Add support for selecting bundle format
232
        self.assertIs(merge_directive.MergeDirective, md.__class__)
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
233
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
234
        self.run_bzr_error(['Bad value .* for option .format.'],
7143.15.2 by Jelmer Vernooij
Run autopep8.
235
                           'send -f branch -o- --format=0.999')[0]
2681.1.9 by Aaron Bentley
Add support for mail-from-editor
236
4370.2.1 by Jelmer Vernooij
Support ``child_submit_format`` option set in the submit branch in "bzr send".
237
    def test_format_child_option(self):
6404.6.2 by Vincent Ladeuil
Merge trunk resolving conflicts and fixing more test failures related to
238
        br = branch.Branch.open('parent')
239
        conf = br.get_config_stack()
6404.6.7 by Vincent Ladeuil
Change set/remove to require a lock for the branch config files.
240
        conf.set('child_submit_format', '4')
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
241
        md = self.get_MD([])
4370.2.1 by Jelmer Vernooij
Support ``child_submit_format`` option set in the submit branch in "bzr send".
242
        self.assertIs(merge_directive.MergeDirective2, md.__class__)
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
243
6404.6.7 by Vincent Ladeuil
Change set/remove to require a lock for the branch config files.
244
        conf.set('child_submit_format', '0.9')
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
245
        md = self.get_MD([])
7045.1.13 by Jelmer Vernooij
Fix a few more tests.
246
        self.assertFormatIs(b'# Bazaar revision bundle v0.9', md)
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
247
248
        md = self.get_MD([], cmd=['bundle'])
7045.1.13 by Jelmer Vernooij
Fix a few more tests.
249
        self.assertFormatIs(b'# Bazaar revision bundle v0.9', md)
4370.2.1 by Jelmer Vernooij
Support ``child_submit_format`` option set in the submit branch in "bzr send".
250
        self.assertIs(merge_directive.MergeDirective, md.__class__)
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
251
6404.6.7 by Vincent Ladeuil
Change set/remove to require a lock for the branch config files.
252
        conf.set('child_submit_format', '0.999')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
253
        self.run_bzr_error(["No such send format '0.999'"],
7143.15.2 by Jelmer Vernooij
Run autopep8.
254
                           'send -f branch -o-')[0]
4370.2.1 by Jelmer Vernooij
Support ``child_submit_format`` option set in the submit branch in "bzr send".
255
2681.1.9 by Aaron Bentley
Add support for mail-from-editor
256
    def test_message_option(self):
257
        self.run_bzr('send', retcode=3)
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
258
        md = self.get_MD([])
2681.1.9 by Aaron Bentley
Add support for mail-from-editor
259
        self.assertIs(None, md.message)
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
260
        md = self.get_MD(['-m', 'my message'])
2681.1.9 by Aaron Bentley
Add support for mail-from-editor
261
        self.assertEqual('my message', md.message)
2747.3.1 by Aaron Bentley
'send' and 'bundle' now handle partial ranges correctly (#61685)
262
263
    def test_omitted_revision(self):
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
264
        md = self.get_MD(['-r-2..'])
7045.1.13 by Jelmer Vernooij
Fix a few more tests.
265
        self.assertEqual(b'rev2', md.base_revision_id)
266
        self.assertEqual(b'rev3', md.revision_id)
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
267
        md = self.get_MD(['-r..3', '--from', 'branch', 'grandparent'], wd='.')
7045.1.13 by Jelmer Vernooij
Fix a few more tests.
268
        self.assertEqual(b'rev1', md.base_revision_id)
269
        self.assertEqual(b'rev3', md.revision_id)
3060.2.1 by Lukáš Lalinský
Fix misplaced branch lock in cmd_send.
270
271
    def test_nonexistant_branch(self):
5017.3.45 by Vincent Ladeuil
Move MemoryServer back into bzrlib.transport.memory as it's needed as soon as a MemoryTransport is used. Add a NEWS entry.
272
        self.vfs_transport_factory = memory.MemoryServer
4691.2.1 by Robert Collins
Add stronger test isolation by interception BzrDir.open and checking the thing being opened is known to the test suite.
273
        location = self.get_url('absentdir/')
3060.2.1 by Lukáš Lalinský
Fix misplaced branch lock in cmd_send.
274
        out, err = self.run_bzr(["send", "--from", location], retcode=3)
275
        self.assertEqual(out, '')
6622.1.29 by Jelmer Vernooij
Fix some more tests.
276
        self.assertEqual(err, 'brz: ERROR: Not a branch: "%s".\n' % location)
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
277
278
4464.3.7 by Vincent Ladeuil
Use mixins as suggested by Martin on IRC.
279
class TestSendStrictMixin(TestSendMixin):
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
280
281
    def make_parent_and_local_branches(self):
282
        # Create a 'parent' branch as the base
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
283
        self.parent_tree = ControlDir.create_standalone_workingtree('parent')
6855.4.1 by Jelmer Vernooij
Yet more bees.
284
        self.build_tree_contents([('parent/file', b'parent')])
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
285
        self.parent_tree.add('file')
6855.4.1 by Jelmer Vernooij
Yet more bees.
286
        self.parent_tree.commit('first commit', rev_id=b'parent')
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
287
        # Branch 'local' from parent and do a change
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
288
        local_bzrdir = self.parent_tree.controldir.sprout('local')
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
289
        self.local_tree = local_bzrdir.open_workingtree()
6855.4.1 by Jelmer Vernooij
Yet more bees.
290
        self.build_tree_contents([('local/file', b'local')])
291
        self.local_tree.commit('second commit', rev_id=b'local')
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
292
4464.3.11 by Vincent Ladeuil
Add a check for tree/branch sync and tweak help.
293
    _default_command = ['send', '-o-', '../parent']
294
    _default_wd = 'local'
7045.1.13 by Jelmer Vernooij
Fix a few more tests.
295
    _default_sent_revs = [b'local']
296
    _default_errors = ['Working tree ".*/local/" has uncommitted '
7143.15.2 by Jelmer Vernooij
Run autopep8.
297
                       'changes \\(See brz status\\)\\.', ]
7045.1.13 by Jelmer Vernooij
Fix a few more tests.
298
    _default_additional_error = 'Use --no-strict to force the send.\n'
299
    _default_additional_warning = 'Uncommitted changes will not be sent.'
4464.3.11 by Vincent Ladeuil
Add a check for tree/branch sync and tweak help.
300
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
301
    def set_config_send_strict(self, value):
6404.6.1 by Vincent Ladeuil
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made.
302
        br = branch.Branch.open('local')
6404.6.7 by Vincent Ladeuil
Change set/remove to require a lock for the branch config files.
303
        br.get_config_stack().set('send_strict', value)
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
304
305
    def assertSendFails(self, args):
5171.2.3 by Vincent Ladeuil
Fixed as per Andrew's review.
306
        out, err = self.run_send(args, rc=3, err_re=self._default_errors)
307
        self.assertContainsRe(err, self._default_additional_error)
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
308
5147.2.1 by Vincent Ladeuil
Failing tests for bug #519319.
309
    def assertSendSucceeds(self, args, revs=None, with_warning=False):
310
        if with_warning:
311
            err_re = self._default_errors
312
        else:
313
            err_re = []
4464.3.11 by Vincent Ladeuil
Add a check for tree/branch sync and tweak help.
314
        if revs is None:
315
            revs = self._default_sent_revs
5147.2.1 by Vincent Ladeuil
Failing tests for bug #519319.
316
        out, err = self.run_send(args, err_re=err_re)
6143.1.4 by Jonathan Riddell
update tests
317
        if len(revs) == 1:
7143.15.2 by Jelmer Vernooij
Run autopep8.
318
            bundling_revs = 'Bundling %d revision.\n' % len(revs)
6143.1.4 by Jonathan Riddell
update tests
319
        else:
320
            bundling_revs = 'Bundling %d revisions.\n' % len(revs)
5147.2.1 by Vincent Ladeuil
Failing tests for bug #519319.
321
        if with_warning:
5171.2.3 by Vincent Ladeuil
Fixed as per Andrew's review.
322
            self.assertContainsRe(err, self._default_additional_warning)
5147.2.1 by Vincent Ladeuil
Failing tests for bug #519319.
323
            self.assertEndsWith(err, bundling_revs)
324
        else:
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
325
            self.assertEqual(bundling_revs, err)
7143.15.2 by Jelmer Vernooij
Run autopep8.
326
        md = merge_directive.MergeDirective.from_lines(
327
            BytesIO(out.encode('utf-8')))
7045.1.13 by Jelmer Vernooij
Fix a few more tests.
328
        self.assertEqual(b'parent', md.base_revision_id)
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
329
        br = serializer.read_bundle(BytesIO(md.get_raw_bundle()))
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
330
        self.assertEqual(set(revs), set(r.revision_id for r in br.revisions))
331
332
4464.3.7 by Vincent Ladeuil
Use mixins as suggested by Martin on IRC.
333
class TestSendStrictWithoutChanges(tests.TestCaseWithTransport,
334
                                   TestSendStrictMixin):
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
335
336
    def setUp(self):
337
        super(TestSendStrictWithoutChanges, self).setUp()
338
        self.make_parent_and_local_branches()
339
6437.16.1 by Jelmer Vernooij
Fix 'bzr send' in treeless branches.
340
    def test_send_without_workingtree(self):
341
        ControlDir.open("local").destroy_workingtree()
342
        self.assertSendSucceeds([])
343
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
344
    def test_send_default(self):
4464.3.11 by Vincent Ladeuil
Add a check for tree/branch sync and tweak help.
345
        self.assertSendSucceeds([])
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
346
347
    def test_send_strict(self):
4464.3.11 by Vincent Ladeuil
Add a check for tree/branch sync and tweak help.
348
        self.assertSendSucceeds(['--strict'])
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
349
350
    def test_send_no_strict(self):
4464.3.11 by Vincent Ladeuil
Add a check for tree/branch sync and tweak help.
351
        self.assertSendSucceeds(['--no-strict'])
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
352
353
    def test_send_config_var_strict(self):
354
        self.set_config_send_strict('true')
4464.3.11 by Vincent Ladeuil
Add a check for tree/branch sync and tweak help.
355
        self.assertSendSucceeds([])
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
356
357
    def test_send_config_var_no_strict(self):
358
        self.set_config_send_strict('false')
4464.3.11 by Vincent Ladeuil
Add a check for tree/branch sync and tweak help.
359
        self.assertSendSucceeds([])
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
360
361
4464.3.7 by Vincent Ladeuil
Use mixins as suggested by Martin on IRC.
362
class TestSendStrictWithChanges(tests.TestCaseWithTransport,
5861.1.4 by Vincent Ladeuil
Fix send --no-remember when no location is set.
363
                                TestSendStrictMixin):
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
364
5559.2.2 by Martin Pool
Change to using standard load_tests_apply_scenarios.
365
    # These are textually the same as test_push.strict_push_change_scenarios,
366
    # but since the functions are reimplemented here, the definitions are left
367
    # here too.
368
    scenarios = [
369
        ('uncommitted',
370
         dict(_changes_type='_uncommitted_changes')),
371
        ('pending_merges',
372
         dict(_changes_type='_pending_merges')),
373
        ('out-of-sync-trees',
374
         dict(_changes_type='_out_of_sync_trees')),
375
        ]
376
7143.15.2 by Jelmer Vernooij
Run autopep8.
377
    _changes_type = None  # Set by load_tests
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
378
379
    def setUp(self):
380
        super(TestSendStrictWithChanges, self).setUp()
4464.3.14 by Vincent Ladeuil
Fixed as per John's review.
381
        # load tests set _changes_types to the name of the method we want to
382
        # call now
383
        do_changes_func = getattr(self, self._changes_type)
384
        do_changes_func()
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
385
4464.3.5 by Vincent Ladeuil
Fix test parametrization based on IRC feedback.
386
    def _uncommitted_changes(self):
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
387
        self.make_parent_and_local_branches()
388
        # Make a change without committing it
6855.4.1 by Jelmer Vernooij
Yet more bees.
389
        self.build_tree_contents([('local/file', b'modified')])
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
390
4464.3.5 by Vincent Ladeuil
Fix test parametrization based on IRC feedback.
391
    def _pending_merges(self):
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
392
        self.make_parent_and_local_branches()
393
        # Create 'other' branch containing a new file
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
394
        other_bzrdir = self.parent_tree.controldir.sprout('other')
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
395
        other_tree = other_bzrdir.open_workingtree()
6855.4.1 by Jelmer Vernooij
Yet more bees.
396
        self.build_tree_contents([('other/other-file', b'other')])
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
397
        other_tree.add('other-file')
6855.4.1 by Jelmer Vernooij
Yet more bees.
398
        other_tree.commit('other commit', rev_id=b'other')
4464.3.5 by Vincent Ladeuil
Fix test parametrization based on IRC feedback.
399
        # Merge and revert, leaving a pending merge
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
400
        self.local_tree.merge_from_branch(other_tree.branch)
401
        self.local_tree.revert(filenames=['other-file'], backups=False)
402
4464.3.11 by Vincent Ladeuil
Add a check for tree/branch sync and tweak help.
403
    def _out_of_sync_trees(self):
404
        self.make_parent_and_local_branches()
405
        self.run_bzr(['checkout', '--lightweight', 'local', 'checkout'])
406
        # Make a change and commit it
6855.4.1 by Jelmer Vernooij
Yet more bees.
407
        self.build_tree_contents([('local/file', b'modified in local')])
408
        self.local_tree.commit('modify file', rev_id=b'modified-in-local')
4464.3.11 by Vincent Ladeuil
Add a check for tree/branch sync and tweak help.
409
        # Exercise commands from the checkout directory
410
        self._default_wd = 'checkout'
411
        self._default_errors = ["Working tree is out of date, please run"
7143.15.2 by Jelmer Vernooij
Run autopep8.
412
                                " 'brz update'\\.", ]
7045.1.13 by Jelmer Vernooij
Fix a few more tests.
413
        self._default_sent_revs = [b'modified-in-local', b'local']
4464.3.11 by Vincent Ladeuil
Add a check for tree/branch sync and tweak help.
414
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
415
    def test_send_default(self):
5147.2.1 by Vincent Ladeuil
Failing tests for bug #519319.
416
        self.assertSendSucceeds([], with_warning=True)
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
417
418
    def test_send_with_revision(self):
7045.1.13 by Jelmer Vernooij
Fix a few more tests.
419
        self.assertSendSucceeds(['-r', 'revid:local'], revs=[b'local'])
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
420
421
    def test_send_no_strict(self):
4464.3.11 by Vincent Ladeuil
Add a check for tree/branch sync and tweak help.
422
        self.assertSendSucceeds(['--no-strict'])
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
423
424
    def test_send_strict_with_changes(self):
425
        self.assertSendFails(['--strict'])
426
427
    def test_send_respect_config_var_strict(self):
428
        self.set_config_send_strict('true')
429
        self.assertSendFails([])
4464.3.11 by Vincent Ladeuil
Add a check for tree/branch sync and tweak help.
430
        self.assertSendSucceeds(['--no-strict'])
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
431
432
    def test_send_bogus_config_var_ignored(self):
433
        self.set_config_send_strict("I'm unsure")
5147.2.1 by Vincent Ladeuil
Failing tests for bug #519319.
434
        self.assertSendSucceeds([], with_warning=True)
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
435
436
    def test_send_no_strict_command_line_override_config(self):
437
        self.set_config_send_strict('true')
438
        self.assertSendFails([])
4464.3.11 by Vincent Ladeuil
Add a check for tree/branch sync and tweak help.
439
        self.assertSendSucceeds(['--no-strict'])
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
440
4721.2.1 by Vincent Ladeuil
Some test cleamup.
441
    def test_send_strict_command_line_override_config(self):
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
442
        self.set_config_send_strict('false')
4464.3.11 by Vincent Ladeuil
Add a check for tree/branch sync and tweak help.
443
        self.assertSendSucceeds([])
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
444
        self.assertSendFails(['--strict'])
4464.3.6 by Vincent Ladeuil
bundle-revisions should support --strict too.
445
446
447
class TestBundleStrictWithoutChanges(TestSendStrictWithoutChanges):
448
449
    _default_command = ['bundle-revisions', '../parent']
6365.1.1 by Jelmer Vernooij
Add blackbox test for hpss use in 'bzr send'.
450
451
452
class TestSmartServerSend(tests.TestCaseWithTransport):
453
454
    def test_send(self):
455
        self.setup_smart_server_with_call_log()
456
        t = self.make_branch_and_tree('branch')
6855.4.1 by Jelmer Vernooij
Yet more bees.
457
        self.build_tree_contents([('branch/foo', b'thecontents')])
6365.1.1 by Jelmer Vernooij
Add blackbox test for hpss use in 'bzr send'.
458
        t.add("foo")
459
        t.commit("message")
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
460
        local = t.controldir.sprout('local-branch').open_workingtree()
6855.4.1 by Jelmer Vernooij
Yet more bees.
461
        self.build_tree_contents([('branch/foo', b'thenewcontents')])
6365.1.1 by Jelmer Vernooij
Add blackbox test for hpss use in 'bzr send'.
462
        local.commit("anothermessage")
463
        self.reset_smart_call_log()
464
        out, err = self.run_bzr(
465
            ['send', '-o', 'x.diff', self.get_url('branch')], working_dir='local-branch')
466
        # This figure represent the amount of work to perform this use case. It
467
        # is entirely ok to reduce this number if a test fails due to rpc_count
468
        # being too low. If rpc_count increases, more network roundtrips have
469
        # become necessary for this use case. Please do not adjust this number
470
        # upwards without agreement from bzr's network support maintainers.
6404.6.2 by Vincent Ladeuil
Merge trunk resolving conflicts and fixing more test failures related to
471
        self.assertLength(7, self.hpss_calls)
6366.1.4 by Jelmer Vernooij
Test connection count calls for most blackbox commands.
472
        self.assertLength(1, self.hpss_connections)
6365.1.1 by Jelmer Vernooij
Add blackbox test for hpss use in 'bzr send'.
473
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)