/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2520.5.4 by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command
1
# Copyright (C) 2006, 2007 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
19
import os
3060.2.1 by Lukáš Lalinský
Fix misplaced branch lock in cmd_send.
20
import sys
1185.84.4 by Aaron Bentley
Use parent branch as default base branch
21
from StringIO import StringIO
22
2681.1.13 by Aaron Bentley
Add support for submit_to config option
23
from bzrlib import (
24
    branch as _mod_branch,
25
    merge_directive,
26
    )
2520.5.4 by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command
27
from bzrlib.bundle import serializer
1185.84.4 by Aaron Bentley
Use parent branch as default base branch
28
from bzrlib.bzrdir import BzrDir
2490.2.28 by Aaron Bentley
Fix handling of null revision
29
from bzrlib import tests
30
31
2520.5.4 by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command
32
def read_bundle(fileobj):
33
    md = merge_directive.MergeDirective.from_lines(fileobj.readlines())
34
    return serializer.read_bundle(StringIO(md.get_raw_bundle()))
35
36
2659.1.3 by Aaron Bentley
Fix test_uses_submit testcase
37
class TestSend(tests.TestCaseWithTransport):
1185.84.4 by Aaron Bentley
Use parent branch as default base branch
38
1793.2.13 by Aaron Bentley
Use single make function for tests
39
    def make_trees(self):
40
        grandparent_tree = BzrDir.create_standalone_workingtree('grandparent')
2681.1.2 by Aaron Bentley
Add support for selecting bundle format
41
        self.build_tree_contents([('grandparent/file1', 'grandparent')])
42
        grandparent_tree.add('file1')
1793.2.13 by Aaron Bentley
Use single make function for tests
43
        grandparent_tree.commit('initial commit', rev_id='revision1')
44
        parent_bzrdir = grandparent_tree.bzrdir.sprout('parent')
45
        parent_tree = parent_bzrdir.open_workingtree()
46
        parent_tree.commit('next commit', rev_id='revision2')
47
        branch_tree = parent_tree.bzrdir.sprout('branch').open_workingtree()
2681.1.2 by Aaron Bentley
Add support for selecting bundle format
48
        self.build_tree_contents([('branch/file1', 'branch')])
1793.2.13 by Aaron Bentley
Use single make function for tests
49
        branch_tree.commit('last commit', rev_id='revision3')
50
1185.84.4 by Aaron Bentley
Use parent branch as default base branch
51
    def test_uses_parent(self):
52
        """Parent location is used as a basis by default"""
2387.1.1 by Robert Collins
Remove the --basis parameter to clone etc. (Robert Collins)
53
        self.make_trees()
1793.2.13 by Aaron Bentley
Use single make function for tests
54
        os.chdir('grandparent')
2654.3.1 by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout
55
        errmsg = self.run_bzr('send -o-', retcode=3)[1]
2520.5.4 by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command
56
        self.assertContainsRe(errmsg, 'No submit branch known or specified')
1185.84.4 by Aaron Bentley
Use parent branch as default base branch
57
        os.chdir('../branch')
2654.3.1 by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout
58
        stdout, stderr = self.run_bzr('send -o-')
3596.3.1 by James Westby
Give the user a bit more information about which saved location is being used.
59
        self.assertEqual(stderr.count('Using saved parent location'), 1)
1793.2.12 by Aaron Bentley
Avoid duplicating the 'Using specified base' message
60
        br = read_bundle(StringIO(stdout))
1793.2.14 by Aaron Bentley
Clean up bundle revision specification
61
        self.assertRevisions(br, ['revision3'])
62
2681.1.1 by Aaron Bentley
Split 'send' into 'send' and 'bundle'.
63
    def test_bundle(self):
64
        """Bundle works like send, except -o is not required"""
65
        self.make_trees()
66
        os.chdir('grandparent')
67
        errmsg = self.run_bzr('bundle', retcode=3)[1]
68
        self.assertContainsRe(errmsg, 'No submit branch known or specified')
69
        os.chdir('../branch')
70
        stdout, stderr = self.run_bzr('bundle')
3596.3.1 by James Westby
Give the user a bit more information about which saved location is being used.
71
        self.assertEqual(stderr.count('Using saved parent location'), 1)
2681.1.1 by Aaron Bentley
Split 'send' into 'send' and 'bundle'.
72
        br = read_bundle(StringIO(stdout))
73
        self.assertRevisions(br, ['revision3'])
74
1793.2.14 by Aaron Bentley
Clean up bundle revision specification
75
    def assertRevisions(self, bi, expected):
2520.4.82 by Aaron Bentley
Fix tests to stop expecting bundles to build trees
76
        self.assertEqual(set(r.revision_id for r in bi.revisions),
77
            set(expected))
1804.1.1 by Aaron Bentley
Add support for submit location to bundles
78
79
    def test_uses_submit(self):
80
        """Submit location can be used and set"""
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
81
        self.make_trees()
1804.1.1 by Aaron Bentley
Add support for submit location to bundles
82
        os.chdir('branch')
2654.3.1 by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout
83
        br = read_bundle(StringIO(self.run_bzr('send -o-')[0]))
1793.2.14 by Aaron Bentley
Clean up bundle revision specification
84
        self.assertRevisions(br, ['revision3'])
2654.3.1 by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout
85
        br = read_bundle(StringIO(self.run_bzr('send ../grandparent -o-')[0]))
1793.2.14 by Aaron Bentley
Clean up bundle revision specification
86
        self.assertRevisions(br, ['revision3', 'revision2'])
1804.1.1 by Aaron Bentley
Add support for submit location to bundles
87
        # submit location should be auto-remembered
2654.3.1 by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout
88
        br = read_bundle(StringIO(self.run_bzr('send -o-')[0]))
89
        self.assertRevisions(br, ['revision3', 'revision2'])
90
        self.run_bzr('send ../parent -o-')
91
        br = read_bundle(StringIO(self.run_bzr('send -o-')[0]))
92
        self.assertRevisions(br, ['revision3', 'revision2'])
93
        self.run_bzr('send ../parent --remember -o-')
94
        br = read_bundle(StringIO(self.run_bzr('send -o-')[0]))
1793.2.14 by Aaron Bentley
Clean up bundle revision specification
95
        self.assertRevisions(br, ['revision3'])
2654.3.1 by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout
96
        err = self.run_bzr('send --remember -o-', retcode=3)[1]
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
97
        self.assertContainsRe(err,
1804.1.1 by Aaron Bentley
Add support for submit location to bundles
98
                              '--remember requires a branch to be specified.')
1793.2.14 by Aaron Bentley
Clean up bundle revision specification
99
100
    def test_revision_branch_interaction(self):
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
101
        self.make_trees()
1793.2.14 by Aaron Bentley
Clean up bundle revision specification
102
        os.chdir('branch')
2654.3.1 by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout
103
        bi = read_bundle(StringIO(self.run_bzr('send ../grandparent -o-')[0]))
1793.2.14 by Aaron Bentley
Clean up bundle revision specification
104
        self.assertRevisions(bi, ['revision3', 'revision2'])
2654.3.1 by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout
105
        out = StringIO(self.run_bzr('send ../grandparent -r -2 -o-')[0])
1793.2.14 by Aaron Bentley
Clean up bundle revision specification
106
        bi = read_bundle(out)
107
        self.assertRevisions(bi, ['revision2'])
2654.3.1 by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout
108
        sio = StringIO(self.run_bzr('send -r -2..-1 -o-')[0])
2520.5.4 by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command
109
        md = merge_directive.MergeDirective.from_lines(sio.readlines())
110
        self.assertEqual('revision2', md.base_revision_id)
111
        self.assertEqual('revision3', md.revision_id)
112
        sio.seek(0)
113
        bi = read_bundle(sio)
114
        self.assertRevisions(bi, ['revision2', 'revision3'])
2654.3.1 by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout
115
        self.run_bzr('send ../grandparent -r -2..-1 -o-')
2178.4.1 by Alexander Belchenko
Provide tests to illustrate bug #55276 on win32.
116
117
    def test_output(self):
118
        # check output for consistency
2178.4.5 by Alexander Belchenko
Spell-checking (thanks to Aaron)
119
        # win32 stdout converts LF to CRLF,
2520.5.4 by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command
120
        # which would break patch-based bundles
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
121
        self.make_trees()
2178.4.1 by Alexander Belchenko
Provide tests to illustrate bug #55276 on win32.
122
        os.chdir('branch')
2665.4.1 by Aaron Bentley
teach run_bzr_subprocess to accept either a list of strings or a string
123
        stdout = self.run_bzr_subprocess('send -o-')[0]
2178.4.1 by Alexander Belchenko
Provide tests to illustrate bug #55276 on win32.
124
        br = read_bundle(StringIO(stdout))
125
        self.assertRevisions(br, ['revision3'])
2490.2.28 by Aaron Bentley
Fix handling of null revision
126
127
    def test_no_common_ancestor(self):
128
        foo = self.make_branch_and_tree('foo')
2520.5.4 by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command
129
        foo.commit('rev a')
2490.2.28 by Aaron Bentley
Fix handling of null revision
130
        bar = self.make_branch_and_tree('bar')
2520.5.4 by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command
131
        bar.commit('rev b')
2490.2.28 by Aaron Bentley
Fix handling of null revision
132
        os.chdir('foo')
2654.3.1 by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout
133
        self.run_bzr('send ../bar -o-')
2520.4.121 by Aaron Bentley
Polish up submit command
134
2654.3.1 by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout
135
    def send_directive(self, args):
136
        sio = StringIO(self.run_bzr(['send', '-o-'] + args)[0])
2520.4.121 by Aaron Bentley
Polish up submit command
137
        return merge_directive.MergeDirective.from_lines(sio.readlines())
138
139
    def test_content_options(self):
140
        """--no-patch and --no-bundle should work and be independant"""
141
        self.make_trees()
142
        os.chdir('branch')
2654.3.1 by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout
143
        md = self.send_directive([])
2520.4.121 by Aaron Bentley
Polish up submit command
144
        self.assertIsNot(None, md.bundle)
145
        self.assertIsNot(None, md.patch)
2681.1.2 by Aaron Bentley
Add support for selecting bundle format
146
147
        md = self.send_directive(['--format=0.9'])
148
        self.assertIsNot(None, md.bundle)
149
        self.assertIsNot(None, md.patch)
150
2654.3.1 by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout
151
        md = self.send_directive(['--no-patch'])
2520.4.121 by Aaron Bentley
Polish up submit command
152
        self.assertIsNot(None, md.bundle)
153
        self.assertIs(None, md.patch)
2681.1.2 by Aaron Bentley
Add support for selecting bundle format
154
        self.run_bzr_error(['Format 0.9 does not permit bundle with no patch'],
155
                      'send --no-patch --format=0.9 -o-')
156
2654.3.1 by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout
157
        md = self.send_directive(['--no-bundle', '.', '.'])
2520.4.121 by Aaron Bentley
Polish up submit command
158
        self.assertIs(None, md.bundle)
159
        self.assertIsNot(None, md.patch)
2681.1.2 by Aaron Bentley
Add support for selecting bundle format
160
161
        md = self.send_directive(['--no-bundle', '--format=0.9', '../parent',
162
                                  '.'])
163
        self.assertIs(None, md.bundle)
164
        self.assertIsNot(None, md.patch)
165
2654.3.1 by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout
166
        md = self.send_directive(['--no-bundle', '--no-patch', '.', '.'])
2520.4.121 by Aaron Bentley
Polish up submit command
167
        self.assertIs(None, md.bundle)
168
        self.assertIs(None, md.patch)
169
2681.1.2 by Aaron Bentley
Add support for selecting bundle format
170
        md = self.send_directive(['--no-bundle', '--no-patch', '--format=0.9',
171
                                  '../parent', '.'])
172
        self.assertIs(None, md.bundle)
173
        self.assertIs(None, md.patch)
174
2520.4.121 by Aaron Bentley
Polish up submit command
175
    def test_from_option(self):
176
        self.make_trees()
2654.3.1 by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout
177
        self.run_bzr('send', retcode=3)
178
        md = self.send_directive(['--from', 'branch'])
2520.4.121 by Aaron Bentley
Polish up submit command
179
        self.assertEqual('revision3', md.revision_id)
2654.3.1 by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout
180
        md = self.send_directive(['-f', 'branch'])
2520.4.121 by Aaron Bentley
Polish up submit command
181
        self.assertEqual('revision3', md.revision_id)
182
183
    def test_output_option(self):
184
        self.make_trees()
2654.3.1 by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout
185
        stdout = self.run_bzr('send -f branch --output file1')[0]
2520.4.121 by Aaron Bentley
Polish up submit command
186
        self.assertEqual('', stdout)
187
        md_file = open('file1', 'rb')
188
        self.addCleanup(md_file.close)
189
        self.assertContainsRe(md_file.read(), 'revision3')
2654.3.1 by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout
190
        stdout = self.run_bzr('send -f branch --output -')[0]
191
        self.assertContainsRe(stdout, 'revision3')
2520.4.132 by Aaron Bentley
Merge from bzr.dev
192
3794.4.3 by Aaron Bentley
Switch to blackbox testing.
193
    def test_note_revisions(self):
194
        self.make_trees()
195
        stderr = self.run_bzr('send -f branch --output file1')[1]
196
        self.assertContainsRe(stderr, r'Bundling 1 revision\(s\).\n')
197
2681.1.13 by Aaron Bentley
Add support for submit_to config option
198
    def test_mailto_option(self):
2654.3.1 by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout
199
        self.make_trees()
2681.1.13 by Aaron Bentley
Add support for submit_to config option
200
        branch = _mod_branch.Branch.open('branch')
3042.1.1 by Lukáš Lalinský
Make mail-to address in ``bzr send`` optional for interactive mail clients.
201
        branch.get_config().set_user_option('mail_client', 'editor')
3984.2.1 by Daniel Watkins
Fixed #198418
202
        self.run_bzr_error(
3986.1.2 by Ian Clatworthy
tweak regex pattern in send test
203
            ('No mail-to address \\(--mail-to\\) or output \\(-o\\) specified',
204
            ), 'send -f branch')
2681.1.13 by Aaron Bentley
Add support for submit_to config option
205
        branch.get_config().set_user_option('mail_client', 'bogus')
2681.1.12 by Aaron Bentley
Fix bundle command
206
        self.run_bzr('send -f branch -o-')
2681.1.13 by Aaron Bentley
Add support for submit_to config option
207
        self.run_bzr_error(('Unknown mail client: bogus',),
208
                           'send -f branch --mail-to jrandom@example.org')
209
        branch.get_config().set_user_option('submit_to', 'jrandom@example.org')
210
        self.run_bzr_error(('Unknown mail client: bogus',),
211
                           'send -f branch')
2681.1.2 by Aaron Bentley
Add support for selecting bundle format
212
3251.1.2 by Jelmer Vernooij
``bzr send`` now supports new ``child_submit_to`` option in the submit branch
213
    def test_mailto_child_option(self):
214
        """Make sure that child_submit_to is used."""
215
        self.make_trees()
216
        branch = _mod_branch.Branch.open('branch')
217
        branch.get_config().set_user_option('mail_client', 'bogus')
218
        parent = _mod_branch.Branch.open('parent')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
219
        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
220
                           'somebody@example.org')
221
        self.run_bzr_error(('Unknown mail client: bogus',),
222
                           'send -f branch')
223
2681.1.2 by Aaron Bentley
Add support for selecting bundle format
224
    def test_format(self):
225
        self.make_trees()
226
        s = StringIO(self.run_bzr('send -f branch -o- --format=4')[0])
227
        md = merge_directive.MergeDirective.from_lines(s.readlines())
228
        self.assertIs(merge_directive.MergeDirective2, md.__class__)
229
        s = StringIO(self.run_bzr('send -f branch -o- --format=0.9')[0])
230
        md = merge_directive.MergeDirective.from_lines(s.readlines())
2681.1.3 by Aaron Bentley
Ensure that a format 0.9 bundle is generated
231
        self.assertContainsRe(md.get_raw_bundle().splitlines()[0],
232
            '# Bazaar revision bundle v0.9')
233
        s = StringIO(self.run_bzr('bundle -f branch -o- --format=0.9')[0])
234
        md = merge_directive.MergeDirective.from_lines(s.readlines())
235
        self.assertContainsRe(md.get_raw_bundle().splitlines()[0],
236
            '# Bazaar revision bundle v0.9')
2681.1.2 by Aaron Bentley
Add support for selecting bundle format
237
        self.assertIs(merge_directive.MergeDirective, md.__class__)
238
        self.run_bzr_error(['Bad value .* for option .format.'],
239
                            'send -f branch -o- --format=0.999')[0]
2681.1.9 by Aaron Bentley
Add support for mail-from-editor
240
241
    def test_message_option(self):
242
        self.make_trees()
243
        self.run_bzr('send', retcode=3)
244
        md = self.send_directive(['--from', 'branch'])
245
        self.assertIs(None, md.message)
246
        md = self.send_directive(['--from', 'branch', '-m', 'my message'])
247
        self.assertEqual('my message', md.message)
2747.3.1 by Aaron Bentley
'send' and 'bundle' now handle partial ranges correctly (#61685)
248
249
    def test_omitted_revision(self):
250
        self.make_trees()
251
        md = self.send_directive(['-r-2..', '--from', 'branch'])
252
        self.assertEqual('revision2', md.base_revision_id)
253
        self.assertEqual('revision3', md.revision_id)
254
        md = self.send_directive(['-r..3', '--from', 'branch',
255
                                 'grandparent'])
256
        self.assertEqual('revision1', md.base_revision_id)
257
        self.assertEqual('revision3', md.revision_id)
3060.2.1 by Lukáš Lalinský
Fix misplaced branch lock in cmd_send.
258
259
    def test_nonexistant_branch(self):
260
        if sys.platform == "win32":
261
            location = "C:/i/do/not/exist/"
262
        else:
263
            location = "/i/do/not/exist/"
264
        out, err = self.run_bzr(["send", "--from", location], retcode=3)
265
        self.assertEqual(out, '')
266
        self.assertEqual(err, 'bzr: ERROR: Not a branch: "%s".\n' % location)