/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_send.py

  • Committer: Robert Collins
  • Date: 2007-09-19 05:14:14 UTC
  • mto: (2835.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 2836.
  • Revision ID: robertc@robertcollins.net-20070919051414-2tgjqteg7k3ps4h0
* ``pull``, ``merge`` and ``push`` will no longer silently correct some
  repository index errors that occured as a result of the Weave disk format.
  Instead the ``reconcile`` command needs to be run to correct those
  problems if they exist (and it has been able to fix most such problems
  since bzr 0.8). Some new problems have been identified during this release
  and you should run ``bzr check`` once on every repository to see if you
  need to reconcile. If you cannot ``pull`` or ``merge`` from a remote
  repository due to mismatched parent errors - a symptom of index errors -
  you should simply take a full copy of that remote repository to a clean
  directory outside any local repositories, then run reconcile on it, and
  finally pull from it locally. (And naturally email the repositories owner
  to ask them to upgrade and run reconcile).
  (Robert Collins)

* ``VersionedFile.fix_parents`` has been removed as a harmful API.
  ``VersionedFile.join`` will no longer accept different parents on either
  side of a join - it will either ignore them, or error, depending on the
  implementation. See notes when upgrading for more information.
  (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006, 2007 Canonical Ltd
 
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
 
 
22
from bzrlib import (
 
23
    branch as _mod_branch,
 
24
    merge_directive,
 
25
    )
 
26
from bzrlib.bundle import serializer
 
27
from bzrlib.bzrdir import BzrDir
 
28
from bzrlib import tests
 
29
 
 
30
 
 
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
 
 
36
class TestSend(tests.TestCaseWithTransport):
 
37
 
 
38
    def make_trees(self):
 
39
        grandparent_tree = BzrDir.create_standalone_workingtree('grandparent')
 
40
        self.build_tree_contents([('grandparent/file1', 'grandparent')])
 
41
        grandparent_tree.add('file1')
 
42
        grandparent_tree.commit('initial commit', rev_id='revision1')
 
43
        parent_bzrdir = grandparent_tree.bzrdir.sprout('parent')
 
44
        parent_tree = parent_bzrdir.open_workingtree()
 
45
        parent_tree.commit('next commit', rev_id='revision2')
 
46
        branch_tree = parent_tree.bzrdir.sprout('branch').open_workingtree()
 
47
        self.build_tree_contents([('branch/file1', 'branch')])
 
48
        branch_tree.commit('last commit', rev_id='revision3')
 
49
 
 
50
    def test_uses_parent(self):
 
51
        """Parent location is used as a basis by default"""
 
52
        self.make_trees()
 
53
        os.chdir('grandparent')
 
54
        errmsg = self.run_bzr('send -o-', retcode=3)[1]
 
55
        self.assertContainsRe(errmsg, 'No submit branch known or specified')
 
56
        os.chdir('../branch')
 
57
        stdout, stderr = self.run_bzr('send -o-')
 
58
        self.assertEqual(stderr.count('Using saved location'), 1)
 
59
        br = read_bundle(StringIO(stdout))
 
60
        self.assertRevisions(br, ['revision3'])
 
61
 
 
62
    def test_bundle(self):
 
63
        """Bundle works like send, except -o is not required"""
 
64
        self.make_trees()
 
65
        os.chdir('grandparent')
 
66
        errmsg = self.run_bzr('bundle', retcode=3)[1]
 
67
        self.assertContainsRe(errmsg, 'No submit branch known or specified')
 
68
        os.chdir('../branch')
 
69
        stdout, stderr = self.run_bzr('bundle')
 
70
        self.assertEqual(stderr.count('Using saved location'), 1)
 
71
        br = read_bundle(StringIO(stdout))
 
72
        self.assertRevisions(br, ['revision3'])
 
73
 
 
74
    def assertRevisions(self, bi, expected):
 
75
        self.assertEqual(set(r.revision_id for r in bi.revisions),
 
76
            set(expected))
 
77
 
 
78
    def test_uses_submit(self):
 
79
        """Submit location can be used and set"""
 
80
        self.make_trees()
 
81
        os.chdir('branch')
 
82
        br = read_bundle(StringIO(self.run_bzr('send -o-')[0]))
 
83
        self.assertRevisions(br, ['revision3'])
 
84
        br = read_bundle(StringIO(self.run_bzr('send ../grandparent -o-')[0]))
 
85
        self.assertRevisions(br, ['revision3', 'revision2'])
 
86
        # submit location should be auto-remembered
 
87
        br = read_bundle(StringIO(self.run_bzr('send -o-')[0]))
 
88
        self.assertRevisions(br, ['revision3', 'revision2'])
 
89
        self.run_bzr('send ../parent -o-')
 
90
        br = read_bundle(StringIO(self.run_bzr('send -o-')[0]))
 
91
        self.assertRevisions(br, ['revision3', 'revision2'])
 
92
        self.run_bzr('send ../parent --remember -o-')
 
93
        br = read_bundle(StringIO(self.run_bzr('send -o-')[0]))
 
94
        self.assertRevisions(br, ['revision3'])
 
95
        err = self.run_bzr('send --remember -o-', retcode=3)[1]
 
96
        self.assertContainsRe(err, 
 
97
                              '--remember requires a branch to be specified.')
 
98
 
 
99
    def test_revision_branch_interaction(self):
 
100
        self.make_trees()
 
101
        os.chdir('branch')
 
102
        bi = read_bundle(StringIO(self.run_bzr('send ../grandparent -o-')[0]))
 
103
        self.assertRevisions(bi, ['revision3', 'revision2'])
 
104
        out = StringIO(self.run_bzr('send ../grandparent -r -2 -o-')[0])
 
105
        bi = read_bundle(out)
 
106
        self.assertRevisions(bi, ['revision2'])
 
107
        sio = StringIO(self.run_bzr('send -r -2..-1 -o-')[0])
 
108
        md = merge_directive.MergeDirective.from_lines(sio.readlines())
 
109
        self.assertEqual('revision2', md.base_revision_id)
 
110
        self.assertEqual('revision3', md.revision_id)
 
111
        sio.seek(0)
 
112
        bi = read_bundle(sio)
 
113
        self.assertRevisions(bi, ['revision2', 'revision3'])
 
114
        self.run_bzr('send ../grandparent -r -2..-1 -o-')
 
115
 
 
116
    def test_output(self):
 
117
        # check output for consistency
 
118
        # win32 stdout converts LF to CRLF,
 
119
        # which would break patch-based bundles
 
120
        self.make_trees()        
 
121
        os.chdir('branch')
 
122
        stdout = self.run_bzr_subprocess('send -o-')[0]
 
123
        br = read_bundle(StringIO(stdout))
 
124
        self.assertRevisions(br, ['revision3'])
 
125
 
 
126
    def test_no_common_ancestor(self):
 
127
        foo = self.make_branch_and_tree('foo')
 
128
        foo.commit('rev a')
 
129
        bar = self.make_branch_and_tree('bar')
 
130
        bar.commit('rev b')
 
131
        os.chdir('foo')
 
132
        self.run_bzr('send ../bar -o-')
 
133
 
 
134
    def send_directive(self, args):
 
135
        sio = StringIO(self.run_bzr(['send', '-o-'] + args)[0])
 
136
        return merge_directive.MergeDirective.from_lines(sio.readlines())
 
137
 
 
138
    def test_content_options(self):
 
139
        """--no-patch and --no-bundle should work and be independant"""
 
140
        self.make_trees()
 
141
        os.chdir('branch')
 
142
        md = self.send_directive([])
 
143
        self.assertIsNot(None, md.bundle)
 
144
        self.assertIsNot(None, md.patch)
 
145
 
 
146
        md = self.send_directive(['--format=0.9'])
 
147
        self.assertIsNot(None, md.bundle)
 
148
        self.assertIsNot(None, md.patch)
 
149
 
 
150
        md = self.send_directive(['--no-patch'])
 
151
        self.assertIsNot(None, md.bundle)
 
152
        self.assertIs(None, md.patch)
 
153
        self.run_bzr_error(['Format 0.9 does not permit bundle with no patch'],
 
154
                      'send --no-patch --format=0.9 -o-')
 
155
 
 
156
        md = self.send_directive(['--no-bundle', '.', '.'])
 
157
        self.assertIs(None, md.bundle)
 
158
        self.assertIsNot(None, md.patch)
 
159
 
 
160
        md = self.send_directive(['--no-bundle', '--format=0.9', '../parent',
 
161
                                  '.'])
 
162
        self.assertIs(None, md.bundle)
 
163
        self.assertIsNot(None, md.patch)
 
164
 
 
165
        md = self.send_directive(['--no-bundle', '--no-patch', '.', '.'])
 
166
        self.assertIs(None, md.bundle)
 
167
        self.assertIs(None, md.patch)
 
168
 
 
169
        md = self.send_directive(['--no-bundle', '--no-patch', '--format=0.9',
 
170
                                  '../parent', '.'])
 
171
        self.assertIs(None, md.bundle)
 
172
        self.assertIs(None, md.patch)
 
173
 
 
174
    def test_from_option(self):
 
175
        self.make_trees()
 
176
        self.run_bzr('send', retcode=3)
 
177
        md = self.send_directive(['--from', 'branch'])
 
178
        self.assertEqual('revision3', md.revision_id)
 
179
        md = self.send_directive(['-f', 'branch'])
 
180
        self.assertEqual('revision3', md.revision_id)
 
181
 
 
182
    def test_output_option(self):
 
183
        self.make_trees()
 
184
        stdout = self.run_bzr('send -f branch --output file1')[0]
 
185
        self.assertEqual('', stdout)
 
186
        md_file = open('file1', 'rb')
 
187
        self.addCleanup(md_file.close)
 
188
        self.assertContainsRe(md_file.read(), 'revision3')
 
189
        stdout = self.run_bzr('send -f branch --output -')[0]
 
190
        self.assertContainsRe(stdout, 'revision3')
 
191
 
 
192
    def test_mailto_option(self):
 
193
        self.make_trees()
 
194
        branch = _mod_branch.Branch.open('branch')
 
195
        branch.get_config().set_user_option('mail_client', 'bogus')
 
196
        self.run_bzr_error(('No mail-to address specified',), 'send -f branch')
 
197
        self.run_bzr('send -f branch -o-')
 
198
        self.run_bzr_error(('Unknown mail client: bogus',),
 
199
                           'send -f branch --mail-to jrandom@example.org')
 
200
        branch.get_config().set_user_option('submit_to', 'jrandom@example.org')
 
201
        self.run_bzr_error(('Unknown mail client: bogus',),
 
202
                           'send -f branch')
 
203
 
 
204
    def test_format(self):
 
205
        self.make_trees()
 
206
        s = StringIO(self.run_bzr('send -f branch -o- --format=4')[0])
 
207
        md = merge_directive.MergeDirective.from_lines(s.readlines())
 
208
        self.assertIs(merge_directive.MergeDirective2, md.__class__)
 
209
        s = StringIO(self.run_bzr('send -f branch -o- --format=0.9')[0])
 
210
        md = merge_directive.MergeDirective.from_lines(s.readlines())
 
211
        self.assertContainsRe(md.get_raw_bundle().splitlines()[0],
 
212
            '# Bazaar revision bundle v0.9')
 
213
        s = StringIO(self.run_bzr('bundle -f branch -o- --format=0.9')[0])
 
214
        md = merge_directive.MergeDirective.from_lines(s.readlines())
 
215
        self.assertContainsRe(md.get_raw_bundle().splitlines()[0],
 
216
            '# Bazaar revision bundle v0.9')
 
217
        self.assertIs(merge_directive.MergeDirective, md.__class__)
 
218
        self.run_bzr_error(['Bad value .* for option .format.'],
 
219
                            'send -f branch -o- --format=0.999')[0]
 
220
 
 
221
    def test_message_option(self):
 
222
        self.make_trees()
 
223
        self.run_bzr('send', retcode=3)
 
224
        md = self.send_directive(['--from', 'branch'])
 
225
        self.assertIs(None, md.message)
 
226
        md = self.send_directive(['--from', 'branch', '-m', 'my message'])
 
227
        self.assertEqual('my message', md.message)
 
228
 
 
229
    def test_omitted_revision(self):
 
230
        self.make_trees()
 
231
        md = self.send_directive(['-r-2..', '--from', 'branch'])
 
232
        self.assertEqual('revision2', md.base_revision_id)
 
233
        self.assertEqual('revision3', md.revision_id)
 
234
        md = self.send_directive(['-r..3', '--from', 'branch',
 
235
                                 'grandparent'])
 
236
        self.assertEqual('revision1', md.base_revision_id)
 
237
        self.assertEqual('revision3', md.revision_id)