~bzr-pqm/bzr/bzr.dev

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