~bzr-pqm/bzr/bzr.dev

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