1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
# Copyright (C) 2006, 2007 Canonical Ltd
# Authors: Aaron Bentley
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import os
from StringIO import StringIO
from bzrlib import merge_directive
from bzrlib.bundle import serializer
from bzrlib.bzrdir import BzrDir
from bzrlib import tests
def read_bundle(fileobj):
md = merge_directive.MergeDirective.from_lines(fileobj.readlines())
return serializer.read_bundle(StringIO(md.get_raw_bundle()))
class TestSubmit(tests.TestCaseWithTransport):
def make_trees(self):
grandparent_tree = BzrDir.create_standalone_workingtree('grandparent')
grandparent_tree.commit('initial commit', rev_id='revision1')
parent_bzrdir = grandparent_tree.bzrdir.sprout('parent')
parent_tree = parent_bzrdir.open_workingtree()
parent_tree.commit('next commit', rev_id='revision2')
branch_tree = parent_tree.bzrdir.sprout('branch').open_workingtree()
branch_tree.commit('last commit', rev_id='revision3')
def test_uses_parent(self):
"""Parent location is used as a basis by default"""
self.make_trees()
os.chdir('grandparent')
errmsg = self.run_bzr('submit', retcode=3)[1]
self.assertContainsRe(errmsg, 'No submit branch known or specified')
os.chdir('../branch')
stdout, stderr = self.run_bzr('submit')
self.assertEqual(stderr.count('Using saved location'), 1)
br = read_bundle(StringIO(stdout))
self.assertRevisions(br, ['revision3'])
def assertRevisions(self, bi, expected):
self.assertEqual(set(r.revision_id for r in bi.revisions),
set(expected))
def test_uses_submit(self):
"""Submit location can be used and set"""
self.make_trees()
os.chdir('branch')
br = read_bundle(StringIO(self.run_bzr('submit')[0]))
self.assertRevisions(br, ['revision3'])
br = read_bundle(StringIO(self.run_bzr('submit ../grandparent')[0]))
self.assertRevisions(br, ['revision3', 'revision2'])
# submit location should be auto-remembered
br = read_bundle(StringIO(self.run_bzr('submit')[0]))
self.assertRevisions(br, ['revision3', 'revision2'])
self.run_bzr('submit ../parent')
br = read_bundle(StringIO(self.run_bzr('bundle')[0]))
self.assertRevisions(br, ['revision3', 'revision2'])
self.run_bzr('submit ../parent --remember')
br = read_bundle(StringIO(self.run_bzr('bundle')[0]))
self.assertRevisions(br, ['revision3'])
err = self.run_bzr('submit --remember', retcode=3)[1]
self.assertContainsRe(err,
'--remember requires a branch to be specified.')
def test_revision_branch_interaction(self):
self.make_trees()
os.chdir('branch')
bi = read_bundle(StringIO(self.run_bzr('bundle ../grandparent')[0]))
self.assertRevisions(bi, ['revision3', 'revision2'])
out = StringIO(self.run_bzr('submit ../grandparent -r -2')[0])
bi = read_bundle(out)
self.assertRevisions(bi, ['revision2'])
sio = StringIO(self.run_bzr('submit -r -2..-1')[0])
md = merge_directive.MergeDirective.from_lines(sio.readlines())
self.assertEqual('revision2', md.base_revision_id)
self.assertEqual('revision3', md.revision_id)
sio.seek(0)
bi = read_bundle(sio)
self.assertRevisions(bi, ['revision2', 'revision3'])
self.run_bzr('submit ../grandparent -r -2..-1')
def test_output(self):
# check output for consistency
# win32 stdout converts LF to CRLF,
# which would break patch-based bundles
self.make_trees()
os.chdir('branch')
stdout = self.run_bzr_subprocess('submit')[0]
br = read_bundle(StringIO(stdout))
self.assertRevisions(br, ['revision3'])
def test_no_common_ancestor(self):
foo = self.make_branch_and_tree('foo')
foo.commit('rev a')
bar = self.make_branch_and_tree('bar')
bar.commit('rev b')
os.chdir('foo')
self.run_bzr('submit ../bar')
def submit_directive(self, args):
sio = StringIO(self.run_bzr(['submit'] + args)[0])
return merge_directive.MergeDirective.from_lines(sio.readlines())
def test_content_options(self):
"""--no-patch and --no-bundle should work and be independant"""
self.make_trees()
os.chdir('branch')
md = self.submit_directive([])
self.assertIsNot(None, md.bundle)
self.assertIsNot(None, md.patch)
md = self.submit_directive(['--no-patch'])
self.assertIsNot(None, md.bundle)
self.assertIs(None, md.patch)
md = self.submit_directive(['--no-bundle', '.', '.'])
self.assertIs(None, md.bundle)
self.assertIsNot(None, md.patch)
md = self.submit_directive(['--no-bundle', '--no-patch', '.', '.'])
self.assertIs(None, md.bundle)
self.assertIs(None, md.patch)
def test_from_option(self):
self.make_trees()
self.run_bzr('submit', retcode=3)
md = self.submit_directive(['--from', 'branch'])
self.assertEqual('revision3', md.revision_id)
md = self.submit_directive(['-f', 'branch'])
self.assertEqual('revision3', md.revision_id)
def test_output_option(self):
self.make_trees()
stdout = self.run_bzr('submit -f branch --output file1')[0]
self.assertEqual('', stdout)
md_file = open('file1', 'rb')
self.addCleanup(md_file.close)
self.assertContainsRe(md_file.read(), 'revision3')
|