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 |
||
33 |
class TestSubmit(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') |
|
37 |
grandparent_tree.commit('initial commit', rev_id='revision1') |
|
38 |
parent_bzrdir = grandparent_tree.bzrdir.sprout('parent') |
|
39 |
parent_tree = parent_bzrdir.open_workingtree() |
|
40 |
parent_tree.commit('next commit', rev_id='revision2') |
|
41 |
branch_tree = parent_tree.bzrdir.sprout('branch').open_workingtree() |
|
42 |
branch_tree.commit('last commit', rev_id='revision3') |
|
43 |
||
1185.84.4
by Aaron Bentley
Use parent branch as default base branch |
44 |
def test_uses_parent(self): |
45 |
"""Parent location is used as a basis by default"""
|
|
2387.1.1
by Robert Collins
Remove the --basis parameter to clone etc. (Robert Collins) |
46 |
self.make_trees() |
1793.2.13
by Aaron Bentley
Use single make function for tests |
47 |
os.chdir('grandparent') |
2520.5.4
by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command |
48 |
errmsg = self.run_bzr('submit', retcode=3)[1] |
49 |
self.assertContainsRe(errmsg, 'No submit branch known or specified') |
|
1185.84.4
by Aaron Bentley
Use parent branch as default base branch |
50 |
os.chdir('../branch') |
2520.5.4
by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command |
51 |
stdout, stderr = self.run_bzr('submit') |
1793.2.12
by Aaron Bentley
Avoid duplicating the 'Using specified base' message |
52 |
self.assertEqual(stderr.count('Using saved location'), 1) |
53 |
br = read_bundle(StringIO(stdout)) |
|
1793.2.14
by Aaron Bentley
Clean up bundle revision specification |
54 |
self.assertRevisions(br, ['revision3']) |
55 |
||
56 |
def assertRevisions(self, bi, expected): |
|
2520.4.82
by Aaron Bentley
Fix tests to stop expecting bundles to build trees |
57 |
self.assertEqual(set(r.revision_id for r in bi.revisions), |
58 |
set(expected)) |
|
1804.1.1
by Aaron Bentley
Add support for submit location to bundles |
59 |
|
60 |
def test_uses_submit(self): |
|
61 |
"""Submit location can be used and set"""
|
|
2552.2.3
by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests. |
62 |
self.make_trees() |
1804.1.1
by Aaron Bentley
Add support for submit location to bundles |
63 |
os.chdir('branch') |
2520.5.4
by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command |
64 |
br = read_bundle(StringIO(self.run_bzr('submit')[0])) |
1793.2.14
by Aaron Bentley
Clean up bundle revision specification |
65 |
self.assertRevisions(br, ['revision3']) |
2520.5.4
by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command |
66 |
br = read_bundle(StringIO(self.run_bzr('submit ../grandparent')[0])) |
1793.2.14
by Aaron Bentley
Clean up bundle revision specification |
67 |
self.assertRevisions(br, ['revision3', 'revision2']) |
1804.1.1
by Aaron Bentley
Add support for submit location to bundles |
68 |
# submit location should be auto-remembered
|
2520.5.4
by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command |
69 |
br = read_bundle(StringIO(self.run_bzr('submit')[0])) |
70 |
self.assertRevisions(br, ['revision3', 'revision2']) |
|
71 |
self.run_bzr('submit ../parent') |
|
72 |
br = read_bundle(StringIO(self.run_bzr('bundle')[0])) |
|
73 |
self.assertRevisions(br, ['revision3', 'revision2']) |
|
74 |
self.run_bzr('submit ../parent --remember') |
|
1804.1.1
by Aaron Bentley
Add support for submit location to bundles |
75 |
br = read_bundle(StringIO(self.run_bzr('bundle')[0])) |
1793.2.14
by Aaron Bentley
Clean up bundle revision specification |
76 |
self.assertRevisions(br, ['revision3']) |
2520.5.4
by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command |
77 |
err = self.run_bzr('submit --remember', retcode=3)[1] |
1804.1.1
by Aaron Bentley
Add support for submit location to bundles |
78 |
self.assertContainsRe(err, |
79 |
'--remember requires a branch to be specified.') |
|
1793.2.14
by Aaron Bentley
Clean up bundle revision specification |
80 |
|
81 |
def test_revision_branch_interaction(self): |
|
2552.2.3
by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests. |
82 |
self.make_trees() |
1793.2.14
by Aaron Bentley
Clean up bundle revision specification |
83 |
os.chdir('branch') |
2552.2.3
by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests. |
84 |
bi = read_bundle(StringIO(self.run_bzr('bundle ../grandparent')[0])) |
1793.2.14
by Aaron Bentley
Clean up bundle revision specification |
85 |
self.assertRevisions(bi, ['revision3', 'revision2']) |
2520.5.4
by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command |
86 |
out = StringIO(self.run_bzr('submit ../grandparent -r -2')[0]) |
1793.2.14
by Aaron Bentley
Clean up bundle revision specification |
87 |
bi = read_bundle(out) |
88 |
self.assertRevisions(bi, ['revision2']) |
|
2520.5.4
by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command |
89 |
sio = StringIO(self.run_bzr('submit -r -2..-1')[0]) |
90 |
md = merge_directive.MergeDirective.from_lines(sio.readlines()) |
|
91 |
self.assertEqual('revision2', md.base_revision_id) |
|
92 |
self.assertEqual('revision3', md.revision_id) |
|
93 |
sio.seek(0) |
|
94 |
bi = read_bundle(sio) |
|
95 |
self.assertRevisions(bi, ['revision2', 'revision3']) |
|
96 |
self.run_bzr('submit ../grandparent -r -2..-1') |
|
2178.4.1
by Alexander Belchenko
Provide tests to illustrate bug #55276 on win32. |
97 |
|
98 |
def test_output(self): |
|
99 |
# check output for consistency
|
|
2178.4.5
by Alexander Belchenko
Spell-checking (thanks to Aaron) |
100 |
# win32 stdout converts LF to CRLF,
|
2520.5.4
by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command |
101 |
# which would break patch-based bundles
|
2178.4.1
by Alexander Belchenko
Provide tests to illustrate bug #55276 on win32. |
102 |
self.make_trees() |
103 |
os.chdir('branch') |
|
2520.5.4
by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command |
104 |
stdout = self.run_bzr_subprocess('submit')[0] |
2178.4.1
by Alexander Belchenko
Provide tests to illustrate bug #55276 on win32. |
105 |
br = read_bundle(StringIO(stdout)) |
106 |
self.assertRevisions(br, ['revision3']) |
|
2490.2.28
by Aaron Bentley
Fix handling of null revision |
107 |
|
108 |
def test_no_common_ancestor(self): |
|
109 |
foo = self.make_branch_and_tree('foo') |
|
2520.5.4
by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command |
110 |
foo.commit('rev a') |
2490.2.28
by Aaron Bentley
Fix handling of null revision |
111 |
bar = self.make_branch_and_tree('bar') |
2520.5.4
by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command |
112 |
bar.commit('rev b') |
2490.2.28
by Aaron Bentley
Fix handling of null revision |
113 |
os.chdir('foo') |
2520.5.4
by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command |
114 |
self.run_bzr('submit ../bar') |
2520.4.121
by Aaron Bentley
Polish up submit command |
115 |
|
116 |
def submit_directive(self, args): |
|
117 |
sio = StringIO(self.run_bzr(['submit'] + args)[0]) |
|
118 |
return merge_directive.MergeDirective.from_lines(sio.readlines()) |
|
119 |
||
120 |
def test_content_options(self): |
|
121 |
"""--no-patch and --no-bundle should work and be independant"""
|
|
122 |
self.make_trees() |
|
123 |
os.chdir('branch') |
|
124 |
md = self.submit_directive([]) |
|
125 |
self.assertIsNot(None, md.bundle) |
|
126 |
self.assertIsNot(None, md.patch) |
|
127 |
md = self.submit_directive(['--no-patch']) |
|
128 |
self.assertIsNot(None, md.bundle) |
|
129 |
self.assertIs(None, md.patch) |
|
130 |
md = self.submit_directive(['--no-bundle', '.', '.']) |
|
131 |
self.assertIs(None, md.bundle) |
|
132 |
self.assertIsNot(None, md.patch) |
|
133 |
md = self.submit_directive(['--no-bundle', '--no-patch', '.', '.']) |
|
134 |
self.assertIs(None, md.bundle) |
|
135 |
self.assertIs(None, md.patch) |
|
136 |
||
137 |
def test_from_option(self): |
|
138 |
self.make_trees() |
|
139 |
self.run_bzr('submit', retcode=3) |
|
140 |
md = self.submit_directive(['--from', 'branch']) |
|
141 |
self.assertEqual('revision3', md.revision_id) |
|
142 |
md = self.submit_directive(['-f', 'branch']) |
|
143 |
self.assertEqual('revision3', md.revision_id) |
|
144 |
||
145 |
def test_output_option(self): |
|
146 |
self.make_trees() |
|
147 |
stdout = self.run_bzr('submit -f branch --output file1')[0] |
|
148 |
self.assertEqual('', stdout) |
|
149 |
md_file = open('file1', 'rb') |
|
150 |
self.addCleanup(md_file.close) |
|
151 |
self.assertContainsRe(md_file.read(), 'revision3') |
|
2520.4.132
by Aaron Bentley
Merge from bzr.dev |
152 |