~bzr-pqm/bzr/bzr.dev

6404.6.1 by Vincent Ladeuil
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made.
1
# Copyright (C) 2006-2012 Canonical Ltd
1185.84.4 by Aaron Bentley
Use parent branch as default base branch
2
# Authors: Aaron Bentley
3
#
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1185.84.4 by Aaron Bentley
Use parent branch as default base branch
17
18
4464.3.1 by Vincent Ladeuil
Fix more imports.
19
from cStringIO import StringIO
1185.84.4 by Aaron Bentley
Use parent branch as default base branch
20
2681.1.13 by Aaron Bentley
Add support for submit_to config option
21
from bzrlib import (
4464.3.1 by Vincent Ladeuil
Fix more imports.
22
    branch,
23
    bzrdir,
2681.1.13 by Aaron Bentley
Add support for submit_to config option
24
    merge_directive,
4464.3.1 by Vincent Ladeuil
Fix more imports.
25
    tests,
2681.1.13 by Aaron Bentley
Add support for submit_to config option
26
    )
6437.16.1 by Jelmer Vernooij
Fix 'bzr send' in treeless branches.
27
from bzrlib.controldir import ControlDir
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
5861.1.5 by Vincent Ladeuil
Just use scripts, we don't care about the internal trees.
30
from bzrlib.tests import (
31
    scenarios,
32
    )
6365.1.1 by Jelmer Vernooij
Add blackbox test for hpss use in 'bzr send'.
33
from bzrlib.tests.matchers import ContainsNoVfsCalls
5861.1.5 by Vincent Ladeuil
Just use scripts, we don't care about the internal trees.
34
35
36
load_tests = scenarios.load_tests_apply_scenarios
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
37
38
4464.3.7 by Vincent Ladeuil
Use mixins as suggested by Martin on IRC.
39
class TestSendMixin(object):
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
40
4464.3.6 by Vincent Ladeuil
bundle-revisions should support --strict too.
41
    _default_command = ['send', '-o-']
42
    _default_wd = 'branch'
43
44
    def run_send(self, args, cmd=None, rc=0, wd=None, err_re=None):
45
        if cmd is None: cmd = self._default_command
46
        if wd is None: wd = self._default_wd
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
47
        if err_re is None: err_re = []
48
        return self.run_bzr(cmd + args, retcode=rc,
49
                            working_dir=wd,
50
                            error_regexes=err_re)
51
52
    def get_MD(self, args, cmd=None, wd='branch'):
53
        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
54
        return merge_directive.MergeDirective.from_lines(out)
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
55
56
    def assertBundleContains(self, revs, args, cmd=None, wd='branch'):
57
        md = self.get_MD(args, cmd=cmd, wd=wd)
58
        br = serializer.read_bundle(StringIO(md.get_raw_bundle()))
59
        self.assertEqual(set(revs), set(r.revision_id for r in br.revisions))
60
61
4464.3.7 by Vincent Ladeuil
Use mixins as suggested by Martin on IRC.
62
class TestSend(tests.TestCaseWithTransport, TestSendMixin):
1185.84.4 by Aaron Bentley
Use parent branch as default base branch
63
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
64
    def setUp(self):
65
        super(TestSend, self).setUp()
4464.3.1 by Vincent Ladeuil
Fix more imports.
66
        grandparent_tree = bzrdir.BzrDir.create_standalone_workingtree(
67
            'grandparent')
2681.1.2 by Aaron Bentley
Add support for selecting bundle format
68
        self.build_tree_contents([('grandparent/file1', 'grandparent')])
69
        grandparent_tree.add('file1')
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
70
        grandparent_tree.commit('initial commit', rev_id='rev1')
71
1793.2.13 by Aaron Bentley
Use single make function for tests
72
        parent_bzrdir = grandparent_tree.bzrdir.sprout('parent')
73
        parent_tree = parent_bzrdir.open_workingtree()
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
74
        parent_tree.commit('next commit', rev_id='rev2')
75
1793.2.13 by Aaron Bentley
Use single make function for tests
76
        branch_tree = parent_tree.bzrdir.sprout('branch').open_workingtree()
2681.1.2 by Aaron Bentley
Add support for selecting bundle format
77
        self.build_tree_contents([('branch/file1', 'branch')])
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
78
        branch_tree.commit('last commit', rev_id='rev3')
79
80
    def assertFormatIs(self, fmt_string, md):
81
        self.assertEqual(fmt_string, md.get_raw_bundle().splitlines()[0])
1793.2.13 by Aaron Bentley
Use single make function for tests
82
1185.84.4 by Aaron Bentley
Use parent branch as default base branch
83
    def test_uses_parent(self):
84
        """Parent location is used as a basis by default"""
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
85
        errmsg = self.run_send([], rc=3, wd='grandparent')[1]
2520.5.4 by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command
86
        self.assertContainsRe(errmsg, 'No submit branch known or specified')
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
87
        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.
88
        self.assertEqual(stderr.count('Using saved parent location'), 1)
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
89
        self.assertBundleContains(['rev3'], [])
1793.2.14 by Aaron Bentley
Clean up bundle revision specification
90
2681.1.1 by Aaron Bentley
Split 'send' into 'send' and 'bundle'.
91
    def test_bundle(self):
92
        """Bundle works like send, except -o is not required"""
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
93
        errmsg = self.run_send([], cmd=['bundle'], rc=3, wd='grandparent')[1]
2681.1.1 by Aaron Bentley
Split 'send' into 'send' and 'bundle'.
94
        self.assertContainsRe(errmsg, 'No submit branch known or specified')
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
95
        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.
96
        self.assertEqual(stderr.count('Using saved parent location'), 1)
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
97
        self.assertBundleContains(['rev3'], [], cmd=['bundle'])
1804.1.1 by Aaron Bentley
Add support for submit location to bundles
98
99
    def test_uses_submit(self):
100
        """Submit location can be used and set"""
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
101
        self.assertBundleContains(['rev3'], [])
102
        self.assertBundleContains(['rev3', 'rev2'], ['../grandparent'])
1804.1.1 by Aaron Bentley
Add support for submit location to bundles
103
        # submit location should be auto-remembered
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
104
        self.assertBundleContains(['rev3', 'rev2'], [])
105
106
        self.run_send(['../parent'])
107
        # We still point to ../grandparent
108
        self.assertBundleContains(['rev3', 'rev2'], [])
109
        # Remember parent now
110
        self.run_send(['../parent', '--remember'])
111
        # Now we point to parent
112
        self.assertBundleContains(['rev3'], [])
113
114
        err = self.run_send(['--remember'], rc=3)[1]
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
115
        self.assertContainsRe(err,
1804.1.1 by Aaron Bentley
Add support for submit location to bundles
116
                              '--remember requires a branch to be specified.')
1793.2.14 by Aaron Bentley
Clean up bundle revision specification
117
118
    def test_revision_branch_interaction(self):
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
119
        self.assertBundleContains(['rev3', 'rev2'], ['../grandparent'])
120
        self.assertBundleContains(['rev2'], ['../grandparent', '-r-2'])
121
        self.assertBundleContains(['rev3', 'rev2'],
122
                                  ['../grandparent', '-r-2..-1'])
123
        md = self.get_MD(['-r-2..-1'])
124
        self.assertEqual('rev2', md.base_revision_id)
125
        self.assertEqual('rev3', md.revision_id)
2178.4.1 by Alexander Belchenko
Provide tests to illustrate bug #55276 on win32.
126
127
    def test_output(self):
128
        # check output for consistency
2178.4.5 by Alexander Belchenko
Spell-checking (thanks to Aaron)
129
        # win32 stdout converts LF to CRLF,
2520.5.4 by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command
130
        # which would break patch-based bundles
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
131
        self.assertBundleContains(['rev3'], [])
2490.2.28 by Aaron Bentley
Fix handling of null revision
132
133
    def test_no_common_ancestor(self):
134
        foo = self.make_branch_and_tree('foo')
2520.5.4 by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command
135
        foo.commit('rev a')
2490.2.28 by Aaron Bentley
Fix handling of null revision
136
        bar = self.make_branch_and_tree('bar')
2520.5.4 by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command
137
        bar.commit('rev b')
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
138
        self.run_send(['--from', 'foo', '../bar'], wd='foo')
2520.4.121 by Aaron Bentley
Polish up submit command
139
140
    def test_content_options(self):
141
        """--no-patch and --no-bundle should work and be independant"""
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
142
        md = self.get_MD([])
143
        self.assertIsNot(None, md.bundle)
144
        self.assertIsNot(None, md.patch)
145
146
        md = self.get_MD(['--format=0.9'])
147
        self.assertIsNot(None, md.bundle)
148
        self.assertIsNot(None, md.patch)
149
150
        md = self.get_MD(['--no-patch'])
2520.4.121 by Aaron Bentley
Polish up submit command
151
        self.assertIsNot(None, md.bundle)
152
        self.assertIs(None, md.patch)
2681.1.2 by Aaron Bentley
Add support for selecting bundle format
153
        self.run_bzr_error(['Format 0.9 does not permit bundle with no patch'],
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
154
                           ['send', '--no-patch', '--format=0.9', '-o-'],
155
                           working_dir='branch')
156
        md = self.get_MD(['--no-bundle', '.', '.'])
2520.4.121 by Aaron Bentley
Polish up submit command
157
        self.assertIs(None, md.bundle)
158
        self.assertIsNot(None, md.patch)
2681.1.2 by Aaron Bentley
Add support for selecting bundle format
159
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
160
        md = self.get_MD(['--no-bundle', '--format=0.9', '../parent',
2681.1.2 by Aaron Bentley
Add support for selecting bundle format
161
                                  '.'])
162
        self.assertIs(None, md.bundle)
163
        self.assertIsNot(None, md.patch)
164
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
165
        md = self.get_MD(['--no-bundle', '--no-patch', '.', '.'])
2520.4.121 by Aaron Bentley
Polish up submit command
166
        self.assertIs(None, md.bundle)
167
        self.assertIs(None, md.patch)
168
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
169
        md = self.get_MD(['--no-bundle', '--no-patch', '--format=0.9',
170
                          '../parent', '.'])
2681.1.2 by Aaron Bentley
Add support for selecting bundle format
171
        self.assertIs(None, md.bundle)
172
        self.assertIs(None, md.patch)
173
2520.4.121 by Aaron Bentley
Polish up submit command
174
    def test_from_option(self):
2654.3.1 by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout
175
        self.run_bzr('send', retcode=3)
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
176
        md = self.get_MD(['--from', 'branch'])
177
        self.assertEqual('rev3', md.revision_id)
178
        md = self.get_MD(['-f', 'branch'])
179
        self.assertEqual('rev3', md.revision_id)
2520.4.121 by Aaron Bentley
Polish up submit command
180
181
    def test_output_option(self):
2654.3.1 by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout
182
        stdout = self.run_bzr('send -f branch --output file1')[0]
2520.4.121 by Aaron Bentley
Polish up submit command
183
        self.assertEqual('', stdout)
184
        md_file = open('file1', 'rb')
185
        self.addCleanup(md_file.close)
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
186
        self.assertContainsRe(md_file.read(), 'rev3')
2654.3.1 by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout
187
        stdout = self.run_bzr('send -f branch --output -')[0]
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
188
        self.assertContainsRe(stdout, 'rev3')
2520.4.132 by Aaron Bentley
Merge from bzr.dev
189
3794.4.3 by Aaron Bentley
Switch to blackbox testing.
190
    def test_note_revisions(self):
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
191
        stderr = self.run_send([])[1]
6143.1.4 by Jonathan Riddell
update tests
192
        self.assertEndsWith(stderr, '\nBundling 1 revision.\n')
3794.4.3 by Aaron Bentley
Switch to blackbox testing.
193
2681.1.13 by Aaron Bentley
Add support for submit_to config option
194
    def test_mailto_option(self):
4464.3.1 by Vincent Ladeuil
Fix more imports.
195
        b = branch.Branch.open('branch')
6449.5.2 by Jelmer Vernooij
Use config stacks in tests, too.
196
        b.get_config_stack().set('mail_client', 'editor')
3984.2.1 by Daniel Watkins
Fixed #198418
197
        self.run_bzr_error(
3986.1.2 by Ian Clatworthy
tweak regex pattern in send test
198
            ('No mail-to address \\(--mail-to\\) or output \\(-o\\) specified',
199
            ), 'send -f branch')
6449.5.2 by Jelmer Vernooij
Use config stacks in tests, too.
200
        b.get_config_stack().set('mail_client', 'bogus')
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
201
        self.run_send([])
6449.5.5 by Jelmer Vernooij
Consider invalid mail clients an error rather than just a warning.
202
        self.run_bzr_error(('Bad value "bogus" for option "mail_client"',),
2681.1.13 by Aaron Bentley
Add support for submit_to config option
203
                           'send -f branch --mail-to jrandom@example.org')
6421.3.1 by Vincent Ladeuil
Migrate more branch options to config stacks.
204
        b.get_config_stack().set('submit_to', 'jrandom@example.org')
6449.5.5 by Jelmer Vernooij
Consider invalid mail clients an error rather than just a warning.
205
        self.run_bzr_error(('Bad value "bogus" for option "mail_client"',),
2681.1.13 by Aaron Bentley
Add support for submit_to config option
206
                           'send -f branch')
2681.1.2 by Aaron Bentley
Add support for selecting bundle format
207
3251.1.2 by Jelmer Vernooij
``bzr send`` now supports new ``child_submit_to`` option in the submit branch
208
    def test_mailto_child_option(self):
209
        """Make sure that child_submit_to is used."""
4464.3.1 by Vincent Ladeuil
Fix more imports.
210
        b = branch.Branch.open('branch')
6449.5.2 by Jelmer Vernooij
Use config stacks in tests, too.
211
        b.get_config_stack().set('mail_client', 'bogus')
4464.3.1 by Vincent Ladeuil
Fix more imports.
212
        parent = branch.Branch.open('parent')
6421.3.1 by Vincent Ladeuil
Migrate more branch options to config stacks.
213
        parent.get_config_stack().set('child_submit_to', 'somebody@example.org')
6449.5.5 by Jelmer Vernooij
Consider invalid mail clients an error rather than just a warning.
214
        self.run_bzr_error(('Bad value "bogus" for option "mail_client"',),
215
                'send -f branch')
3251.1.2 by Jelmer Vernooij
``bzr send`` now supports new ``child_submit_to`` option in the submit branch
216
2681.1.2 by Aaron Bentley
Add support for selecting bundle format
217
    def test_format(self):
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
218
        md = self.get_MD(['--format=4'])
2681.1.2 by Aaron Bentley
Add support for selecting bundle format
219
        self.assertIs(merge_directive.MergeDirective2, md.__class__)
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
220
        self.assertFormatIs('# Bazaar revision bundle v4', md)
221
222
        md = self.get_MD(['--format=0.9'])
223
        self.assertFormatIs('# Bazaar revision bundle v0.9', md)
224
225
        md = self.get_MD(['--format=0.9'], cmd=['bundle'])
226
        self.assertFormatIs('# Bazaar revision bundle v0.9', md)
2681.1.2 by Aaron Bentley
Add support for selecting bundle format
227
        self.assertIs(merge_directive.MergeDirective, md.__class__)
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
228
2681.1.2 by Aaron Bentley
Add support for selecting bundle format
229
        self.run_bzr_error(['Bad value .* for option .format.'],
230
                            'send -f branch -o- --format=0.999')[0]
2681.1.9 by Aaron Bentley
Add support for mail-from-editor
231
4370.2.1 by Jelmer Vernooij
Support ``child_submit_format`` option set in the submit branch in "bzr send".
232
    def test_format_child_option(self):
6404.6.2 by Vincent Ladeuil
Merge trunk resolving conflicts and fixing more test failures related to
233
        br = branch.Branch.open('parent')
234
        conf = br.get_config_stack()
6404.6.7 by Vincent Ladeuil
Change set/remove to require a lock for the branch config files.
235
        conf.set('child_submit_format', '4')
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
236
        md = self.get_MD([])
4370.2.1 by Jelmer Vernooij
Support ``child_submit_format`` option set in the submit branch in "bzr send".
237
        self.assertIs(merge_directive.MergeDirective2, md.__class__)
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
238
6404.6.7 by Vincent Ladeuil
Change set/remove to require a lock for the branch config files.
239
        conf.set('child_submit_format', '0.9')
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
240
        md = self.get_MD([])
241
        self.assertFormatIs('# Bazaar revision bundle v0.9', md)
242
243
        md = self.get_MD([], cmd=['bundle'])
244
        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".
245
        self.assertIs(merge_directive.MergeDirective, md.__class__)
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
246
6404.6.7 by Vincent Ladeuil
Change set/remove to require a lock for the branch config files.
247
        conf.set('child_submit_format', '0.999')
4370.2.1 by Jelmer Vernooij
Support ``child_submit_format`` option set in the submit branch in "bzr send".
248
        self.run_bzr_error(["No such send format '0.999'"],
249
                            'send -f branch -o-')[0]
250
2681.1.9 by Aaron Bentley
Add support for mail-from-editor
251
    def test_message_option(self):
252
        self.run_bzr('send', retcode=3)
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
253
        md = self.get_MD([])
2681.1.9 by Aaron Bentley
Add support for mail-from-editor
254
        self.assertIs(None, md.message)
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
255
        md = self.get_MD(['-m', 'my message'])
2681.1.9 by Aaron Bentley
Add support for mail-from-editor
256
        self.assertEqual('my message', md.message)
2747.3.1 by Aaron Bentley
'send' and 'bundle' now handle partial ranges correctly (#61685)
257
258
    def test_omitted_revision(self):
4464.3.2 by Vincent Ladeuil
Cleanup send tests.
259
        md = self.get_MD(['-r-2..'])
260
        self.assertEqual('rev2', md.base_revision_id)
261
        self.assertEqual('rev3', md.revision_id)
262
        md = self.get_MD(['-r..3', '--from', 'branch', 'grandparent'], wd='.')
263
        self.assertEqual('rev1', md.base_revision_id)
264
        self.assertEqual('rev3', md.revision_id)
3060.2.1 by Lukáš Lalinský
Fix misplaced branch lock in cmd_send.
265
266
    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.
267
        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.
268
        location = self.get_url('absentdir/')
3060.2.1 by Lukáš Lalinský
Fix misplaced branch lock in cmd_send.
269
        out, err = self.run_bzr(["send", "--from", location], retcode=3)
270
        self.assertEqual(out, '')
271
        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.
272
273
4464.3.7 by Vincent Ladeuil
Use mixins as suggested by Martin on IRC.
274
class TestSendStrictMixin(TestSendMixin):
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
275
276
    def make_parent_and_local_branches(self):
277
        # Create a 'parent' branch as the base
278
        self.parent_tree = bzrdir.BzrDir.create_standalone_workingtree('parent')
279
        self.build_tree_contents([('parent/file', 'parent')])
280
        self.parent_tree.add('file')
281
        self.parent_tree.commit('first commit', rev_id='parent')
282
        # Branch 'local' from parent and do a change
283
        local_bzrdir = self.parent_tree.bzrdir.sprout('local')
284
        self.local_tree = local_bzrdir.open_workingtree()
285
        self.build_tree_contents([('local/file', 'local')])
286
        self.local_tree.commit('second commit', rev_id='local')
287
4464.3.11 by Vincent Ladeuil
Add a check for tree/branch sync and tweak help.
288
    _default_command = ['send', '-o-', '../parent']
289
    _default_wd = 'local'
290
    _default_sent_revs = ['local']
291
    _default_errors = ['Working tree ".*/local/" has uncommitted '
292
                       'changes \(See bzr status\)\.',]
5171.2.3 by Vincent Ladeuil
Fixed as per Andrew's review.
293
    _default_additional_error = 'Use --no-strict to force the send.\n'
294
    _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.
295
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
296
    def set_config_send_strict(self, value):
6404.6.1 by Vincent Ladeuil
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made.
297
        br = branch.Branch.open('local')
6404.6.7 by Vincent Ladeuil
Change set/remove to require a lock for the branch config files.
298
        br.get_config_stack().set('send_strict', value)
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
299
300
    def assertSendFails(self, args):
5171.2.3 by Vincent Ladeuil
Fixed as per Andrew's review.
301
        out, err = self.run_send(args, rc=3, err_re=self._default_errors)
302
        self.assertContainsRe(err, self._default_additional_error)
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
303
5147.2.1 by Vincent Ladeuil
Failing tests for bug #519319.
304
    def assertSendSucceeds(self, args, revs=None, with_warning=False):
305
        if with_warning:
306
            err_re = self._default_errors
307
        else:
308
            err_re = []
4464.3.11 by Vincent Ladeuil
Add a check for tree/branch sync and tweak help.
309
        if revs is None:
310
            revs = self._default_sent_revs
5147.2.1 by Vincent Ladeuil
Failing tests for bug #519319.
311
        out, err = self.run_send(args, err_re=err_re)
6143.1.4 by Jonathan Riddell
update tests
312
        if len(revs) == 1:
313
            bundling_revs = 'Bundling %d revision.\n'% len(revs)
314
        else:
315
            bundling_revs = 'Bundling %d revisions.\n' % len(revs)
5147.2.1 by Vincent Ladeuil
Failing tests for bug #519319.
316
        if with_warning:
5171.2.3 by Vincent Ladeuil
Fixed as per Andrew's review.
317
            self.assertContainsRe(err, self._default_additional_warning)
5147.2.1 by Vincent Ladeuil
Failing tests for bug #519319.
318
            self.assertEndsWith(err, bundling_revs)
319
        else:
320
            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
321
        md = merge_directive.MergeDirective.from_lines(StringIO(out))
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
322
        self.assertEqual('parent', md.base_revision_id)
323
        br = serializer.read_bundle(StringIO(md.get_raw_bundle()))
324
        self.assertEqual(set(revs), set(r.revision_id for r in br.revisions))
325
326
4464.3.7 by Vincent Ladeuil
Use mixins as suggested by Martin on IRC.
327
class TestSendStrictWithoutChanges(tests.TestCaseWithTransport,
328
                                   TestSendStrictMixin):
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
329
330
    def setUp(self):
331
        super(TestSendStrictWithoutChanges, self).setUp()
332
        self.make_parent_and_local_branches()
333
6437.16.1 by Jelmer Vernooij
Fix 'bzr send' in treeless branches.
334
    def test_send_without_workingtree(self):
335
        ControlDir.open("local").destroy_workingtree()
336
        self.assertSendSucceeds([])
337
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
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,
5861.1.4 by Vincent Ladeuil
Fix send --no-remember when no location is set.
357
                                TestSendStrictMixin):
4464.3.4 by Vincent Ladeuil
Fix bug #206577 by adding a --strict option to send.
358
5559.2.2 by Martin Pool
Change to using standard load_tests_apply_scenarios.
359
    # These are textually the same as test_push.strict_push_change_scenarios,
360
    # but since the functions are reimplemented here, the definitions are left
361
    # here too.
362
    scenarios = [
363
        ('uncommitted',
364
         dict(_changes_type='_uncommitted_changes')),
365
        ('pending_merges',
366
         dict(_changes_type='_pending_merges')),
367
        ('out-of-sync-trees',
368
         dict(_changes_type='_out_of_sync_trees')),
369
        ]
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']
6365.1.1 by Jelmer Vernooij
Add blackbox test for hpss use in 'bzr send'.
444
445
446
class TestSmartServerSend(tests.TestCaseWithTransport):
447
448
    def test_send(self):
449
        self.setup_smart_server_with_call_log()
450
        t = self.make_branch_and_tree('branch')
451
        self.build_tree_contents([('branch/foo', 'thecontents')])
452
        t.add("foo")
453
        t.commit("message")
454
        local = t.bzrdir.sprout('local-branch').open_workingtree()
455
        self.build_tree_contents([('branch/foo', 'thenewcontents')])
456
        local.commit("anothermessage")
457
        self.reset_smart_call_log()
458
        out, err = self.run_bzr(
459
            ['send', '-o', 'x.diff', self.get_url('branch')], working_dir='local-branch')
460
        # This figure represent the amount of work to perform this use case. It
461
        # is entirely ok to reduce this number if a test fails due to rpc_count
462
        # being too low. If rpc_count increases, more network roundtrips have
463
        # become necessary for this use case. Please do not adjust this number
464
        # upwards without agreement from bzr's network support maintainers.
6404.6.2 by Vincent Ladeuil
Merge trunk resolving conflicts and fixing more test failures related to
465
        self.assertLength(7, self.hpss_calls)
6366.1.4 by Jelmer Vernooij
Test connection count calls for most blackbox commands.
466
        self.assertLength(1, self.hpss_connections)
6365.1.1 by Jelmer Vernooij
Add blackbox test for hpss use in 'bzr send'.
467
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)