/brz/remove-bazaar

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