~bzr-pqm/bzr/bzr.dev

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