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
|
|
16 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
17 |
||
18 |
||
19 |
import os |
|
20 |
from StringIO import StringIO |
|
21 |
||
|
2520.5.4
by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command |
22 |
from bzrlib import merge_directive |
23 |
from bzrlib.bundle import serializer |
|
|
1185.84.4
by Aaron Bentley
Use parent branch as default base branch |
24 |
from bzrlib.bzrdir import BzrDir |
|
2490.2.28
by Aaron Bentley
Fix handling of null revision |
25 |
from bzrlib import tests |
26 |
||
27 |
||
|
2520.5.4
by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command |
28 |
def read_bundle(fileobj): |
29 |
md = merge_directive.MergeDirective.from_lines(fileobj.readlines()) |
|
30 |
return serializer.read_bundle(StringIO(md.get_raw_bundle())) |
|
31 |
||
32 |
||
|
2659.1.3
by Aaron Bentley
Fix test_uses_submit testcase |
33 |
class TestSend(tests.TestCaseWithTransport): |
|
1185.84.4
by Aaron Bentley
Use parent branch as default base branch |
34 |
|
|
1793.2.13
by Aaron Bentley
Use single make function for tests |
35 |
def make_trees(self): |
36 |
grandparent_tree = BzrDir.create_standalone_workingtree('grandparent') |
|
|
2681.1.2
by Aaron Bentley
Add support for selecting bundle format |
37 |
self.build_tree_contents([('grandparent/file1', 'grandparent')]) |
38 |
grandparent_tree.add('file1') |
|
|
1793.2.13
by Aaron Bentley
Use single make function for tests |
39 |
grandparent_tree.commit('initial commit', rev_id='revision1') |
40 |
parent_bzrdir = grandparent_tree.bzrdir.sprout('parent') |
|
41 |
parent_tree = parent_bzrdir.open_workingtree() |
|
42 |
parent_tree.commit('next commit', rev_id='revision2') |
|
43 |
branch_tree = parent_tree.bzrdir.sprout('branch').open_workingtree() |
|
|
2681.1.2
by Aaron Bentley
Add support for selecting bundle format |
44 |
self.build_tree_contents([('branch/file1', 'branch')]) |
|
1793.2.13
by Aaron Bentley
Use single make function for tests |
45 |
branch_tree.commit('last commit', rev_id='revision3') |
46 |
||
|
1185.84.4
by Aaron Bentley
Use parent branch as default base branch |
47 |
def test_uses_parent(self): |
48 |
"""Parent location is used as a basis by default""" |
|
|
2387.1.1
by Robert Collins
Remove the --basis parameter to clone etc. (Robert Collins) |
49 |
self.make_trees() |
|
1793.2.13
by Aaron Bentley
Use single make function for tests |
50 |
os.chdir('grandparent') |
|
2654.3.1
by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout |
51 |
errmsg = self.run_bzr('send -o-', retcode=3)[1] |
|
2520.5.4
by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command |
52 |
self.assertContainsRe(errmsg, 'No submit branch known or specified') |
|
1185.84.4
by Aaron Bentley
Use parent branch as default base branch |
53 |
os.chdir('../branch') |
|
2654.3.1
by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout |
54 |
stdout, stderr = self.run_bzr('send -o-') |
|
1793.2.12
by Aaron Bentley
Avoid duplicating the 'Using specified base' message |
55 |
self.assertEqual(stderr.count('Using saved location'), 1) |
56 |
br = read_bundle(StringIO(stdout)) |
|
|
1793.2.14
by Aaron Bentley
Clean up bundle revision specification |
57 |
self.assertRevisions(br, ['revision3']) |
58 |
||
|
2681.1.1
by Aaron Bentley
Split 'send' into 'send' and 'bundle'. |
59 |
def test_bundle(self): |
60 |
"""Bundle works like send, except -o is not required""" |
|
61 |
self.make_trees() |
|
62 |
os.chdir('grandparent') |
|
63 |
errmsg = self.run_bzr('bundle', retcode=3)[1] |
|
64 |
self.assertContainsRe(errmsg, 'No submit branch known or specified') |
|
65 |
os.chdir('../branch') |
|
66 |
stdout, stderr = self.run_bzr('bundle') |
|
67 |
self.assertEqual(stderr.count('Using saved location'), 1) |
|
68 |
br = read_bundle(StringIO(stdout)) |
|
69 |
self.assertRevisions(br, ['revision3']) |
|
70 |
||
|
1793.2.14
by Aaron Bentley
Clean up bundle revision specification |
71 |
def assertRevisions(self, bi, expected): |
|
2520.4.82
by Aaron Bentley
Fix tests to stop expecting bundles to build trees |
72 |
self.assertEqual(set(r.revision_id for r in bi.revisions), |
73 |
set(expected)) |
|
|
1804.1.1
by Aaron Bentley
Add support for submit location to bundles |
74 |
|
75 |
def test_uses_submit(self): |
|
76 |
"""Submit location can be used and set""" |
|
|
2552.2.3
by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests. |
77 |
self.make_trees() |
|
1804.1.1
by Aaron Bentley
Add support for submit location to bundles |
78 |
os.chdir('branch') |
|
2654.3.1
by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout |
79 |
br = read_bundle(StringIO(self.run_bzr('send -o-')[0])) |
|
1793.2.14
by Aaron Bentley
Clean up bundle revision specification |
80 |
self.assertRevisions(br, ['revision3']) |
|
2654.3.1
by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout |
81 |
br = read_bundle(StringIO(self.run_bzr('send ../grandparent -o-')[0])) |
|
1793.2.14
by Aaron Bentley
Clean up bundle revision specification |
82 |
self.assertRevisions(br, ['revision3', 'revision2']) |
|
1804.1.1
by Aaron Bentley
Add support for submit location to bundles |
83 |
# submit location should be auto-remembered
|
|
2654.3.1
by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout |
84 |
br = read_bundle(StringIO(self.run_bzr('send -o-')[0])) |
85 |
self.assertRevisions(br, ['revision3', 'revision2']) |
|
86 |
self.run_bzr('send ../parent -o-') |
|
87 |
br = read_bundle(StringIO(self.run_bzr('send -o-')[0])) |
|
88 |
self.assertRevisions(br, ['revision3', 'revision2']) |
|
89 |
self.run_bzr('send ../parent --remember -o-') |
|
90 |
br = read_bundle(StringIO(self.run_bzr('send -o-')[0])) |
|
|
1793.2.14
by Aaron Bentley
Clean up bundle revision specification |
91 |
self.assertRevisions(br, ['revision3']) |
|
2654.3.1
by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout |
92 |
err = self.run_bzr('send --remember -o-', retcode=3)[1] |
|
1804.1.1
by Aaron Bentley
Add support for submit location to bundles |
93 |
self.assertContainsRe(err, |
94 |
'--remember requires a branch to be specified.') |
|
|
1793.2.14
by Aaron Bentley
Clean up bundle revision specification |
95 |
|
96 |
def test_revision_branch_interaction(self): |
|
|
2552.2.3
by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests. |
97 |
self.make_trees() |
|
1793.2.14
by Aaron Bentley
Clean up bundle revision specification |
98 |
os.chdir('branch') |
|
2654.3.1
by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout |
99 |
bi = read_bundle(StringIO(self.run_bzr('send ../grandparent -o-')[0])) |
|
1793.2.14
by Aaron Bentley
Clean up bundle revision specification |
100 |
self.assertRevisions(bi, ['revision3', 'revision2']) |
|
2654.3.1
by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout |
101 |
out = StringIO(self.run_bzr('send ../grandparent -r -2 -o-')[0]) |
|
1793.2.14
by Aaron Bentley
Clean up bundle revision specification |
102 |
bi = read_bundle(out) |
103 |
self.assertRevisions(bi, ['revision2']) |
|
|
2654.3.1
by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout |
104 |
sio = StringIO(self.run_bzr('send -r -2..-1 -o-')[0]) |
|
2520.5.4
by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command |
105 |
md = merge_directive.MergeDirective.from_lines(sio.readlines()) |
106 |
self.assertEqual('revision2', md.base_revision_id) |
|
107 |
self.assertEqual('revision3', md.revision_id) |
|
108 |
sio.seek(0) |
|
109 |
bi = read_bundle(sio) |
|
110 |
self.assertRevisions(bi, ['revision2', 'revision3']) |
|
|
2654.3.1
by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout |
111 |
self.run_bzr('send ../grandparent -r -2..-1 -o-') |
|
2178.4.1
by Alexander Belchenko
Provide tests to illustrate bug #55276 on win32. |
112 |
|
113 |
def test_output(self): |
|
114 |
# check output for consistency
|
|
|
2178.4.5
by Alexander Belchenko
Spell-checking (thanks to Aaron) |
115 |
# win32 stdout converts LF to CRLF,
|
|
2520.5.4
by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command |
116 |
# which would break patch-based bundles
|
|
2178.4.1
by Alexander Belchenko
Provide tests to illustrate bug #55276 on win32. |
117 |
self.make_trees() |
118 |
os.chdir('branch') |
|
|
2665.4.1
by Aaron Bentley
teach run_bzr_subprocess to accept either a list of strings or a string |
119 |
stdout = self.run_bzr_subprocess('send -o-')[0] |
|
2178.4.1
by Alexander Belchenko
Provide tests to illustrate bug #55276 on win32. |
120 |
br = read_bundle(StringIO(stdout)) |
121 |
self.assertRevisions(br, ['revision3']) |
|
|
2490.2.28
by Aaron Bentley
Fix handling of null revision |
122 |
|
123 |
def test_no_common_ancestor(self): |
|
124 |
foo = self.make_branch_and_tree('foo') |
|
|
2520.5.4
by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command |
125 |
foo.commit('rev a') |
|
2490.2.28
by Aaron Bentley
Fix handling of null revision |
126 |
bar = self.make_branch_and_tree('bar') |
|
2520.5.4
by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command |
127 |
bar.commit('rev b') |
|
2490.2.28
by Aaron Bentley
Fix handling of null revision |
128 |
os.chdir('foo') |
|
2654.3.1
by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout |
129 |
self.run_bzr('send ../bar -o-') |
|
2520.4.121
by Aaron Bentley
Polish up submit command |
130 |
|
|
2654.3.1
by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout |
131 |
def send_directive(self, args): |
132 |
sio = StringIO(self.run_bzr(['send', '-o-'] + args)[0]) |
|
|
2520.4.121
by Aaron Bentley
Polish up submit command |
133 |
return merge_directive.MergeDirective.from_lines(sio.readlines()) |
134 |
||
135 |
def test_content_options(self): |
|
136 |
"""--no-patch and --no-bundle should work and be independant""" |
|
137 |
self.make_trees() |
|
138 |
os.chdir('branch') |
|
|
2654.3.1
by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout |
139 |
md = self.send_directive([]) |
|
2520.4.121
by Aaron Bentley
Polish up submit command |
140 |
self.assertIsNot(None, md.bundle) |
141 |
self.assertIsNot(None, md.patch) |
|
|
2681.1.2
by Aaron Bentley
Add support for selecting bundle format |
142 |
|
143 |
md = self.send_directive(['--format=0.9']) |
|
144 |
self.assertIsNot(None, md.bundle) |
|
145 |
self.assertIsNot(None, md.patch) |
|
146 |
||
|
2654.3.1
by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout |
147 |
md = self.send_directive(['--no-patch']) |
|
2520.4.121
by Aaron Bentley
Polish up submit command |
148 |
self.assertIsNot(None, md.bundle) |
149 |
self.assertIs(None, md.patch) |
|
|
2681.1.2
by Aaron Bentley
Add support for selecting bundle format |
150 |
self.run_bzr_error(['Format 0.9 does not permit bundle with no patch'], |
151 |
'send --no-patch --format=0.9 -o-') |
|
152 |
||
|
2654.3.1
by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout |
153 |
md = self.send_directive(['--no-bundle', '.', '.']) |
|
2520.4.121
by Aaron Bentley
Polish up submit command |
154 |
self.assertIs(None, md.bundle) |
155 |
self.assertIsNot(None, md.patch) |
|
|
2681.1.2
by Aaron Bentley
Add support for selecting bundle format |
156 |
|
157 |
md = self.send_directive(['--no-bundle', '--format=0.9', '../parent', |
|
158 |
'.']) |
|
159 |
self.assertIs(None, md.bundle) |
|
160 |
self.assertIsNot(None, md.patch) |
|
161 |
||
|
2654.3.1
by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout |
162 |
md = self.send_directive(['--no-bundle', '--no-patch', '.', '.']) |
|
2520.4.121
by Aaron Bentley
Polish up submit command |
163 |
self.assertIs(None, md.bundle) |
164 |
self.assertIs(None, md.patch) |
|
165 |
||
|
2681.1.2
by Aaron Bentley
Add support for selecting bundle format |
166 |
md = self.send_directive(['--no-bundle', '--no-patch', '--format=0.9', |
167 |
'../parent', '.']) |
|
168 |
self.assertIs(None, md.bundle) |
|
169 |
self.assertIs(None, md.patch) |
|
170 |
||
|
2520.4.121
by Aaron Bentley
Polish up submit command |
171 |
def test_from_option(self): |
172 |
self.make_trees() |
|
|
2654.3.1
by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout |
173 |
self.run_bzr('send', retcode=3) |
174 |
md = self.send_directive(['--from', 'branch']) |
|
|
2520.4.121
by Aaron Bentley
Polish up submit command |
175 |
self.assertEqual('revision3', md.revision_id) |
|
2654.3.1
by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout |
176 |
md = self.send_directive(['-f', 'branch']) |
|
2520.4.121
by Aaron Bentley
Polish up submit command |
177 |
self.assertEqual('revision3', md.revision_id) |
178 |
||
179 |
def test_output_option(self): |
|
180 |
self.make_trees() |
|
|
2654.3.1
by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout |
181 |
stdout = self.run_bzr('send -f branch --output file1')[0] |
|
2520.4.121
by Aaron Bentley
Polish up submit command |
182 |
self.assertEqual('', stdout) |
183 |
md_file = open('file1', 'rb') |
|
184 |
self.addCleanup(md_file.close) |
|
185 |
self.assertContainsRe(md_file.read(), 'revision3') |
|
|
2654.3.1
by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout |
186 |
stdout = self.run_bzr('send -f branch --output -')[0] |
187 |
self.assertContainsRe(stdout, 'revision3') |
|
|
2520.4.132
by Aaron Bentley
Merge from bzr.dev |
188 |
|
|
2654.3.1
by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout |
189 |
def test_output_option_required(self): |
190 |
self.make_trees() |
|
191 |
self.run_bzr_error(('File must be specified with --output',), |
|
192 |
'send -f branch') |
|
|
2681.1.2
by Aaron Bentley
Add support for selecting bundle format |
193 |
|
194 |
def test_format(self): |
|
195 |
self.make_trees() |
|
196 |
s = StringIO(self.run_bzr('send -f branch -o- --format=4')[0]) |
|
197 |
md = merge_directive.MergeDirective.from_lines(s.readlines()) |
|
198 |
self.assertIs(merge_directive.MergeDirective2, md.__class__) |
|
199 |
s = StringIO(self.run_bzr('send -f branch -o- --format=0.9')[0]) |
|
200 |
md = merge_directive.MergeDirective.from_lines(s.readlines()) |
|
|
2681.1.3
by Aaron Bentley
Ensure that a format 0.9 bundle is generated |
201 |
self.assertContainsRe(md.get_raw_bundle().splitlines()[0], |
202 |
'# Bazaar revision bundle v0.9') |
|
203 |
s = StringIO(self.run_bzr('bundle -f branch -o- --format=0.9')[0]) |
|
204 |
md = merge_directive.MergeDirective.from_lines(s.readlines()) |
|
205 |
self.assertContainsRe(md.get_raw_bundle().splitlines()[0], |
|
206 |
'# Bazaar revision bundle v0.9') |
|
|
2681.1.2
by Aaron Bentley
Add support for selecting bundle format |
207 |
self.assertIs(merge_directive.MergeDirective, md.__class__) |
208 |
self.run_bzr_error(['Bad value .* for option .format.'], |
|
209 |
'send -f branch -o- --format=0.999')[0] |