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