~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: mbp at sourcefrog
  • Date: 2005-03-24 00:44:18 UTC
  • Revision ID: mbp@sourcefrog.net-20050324004418-b4a050f656c07f5f
show space usage for various stores in the info command

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 merge_directive
23
 
from bzrlib.bundle import serializer
24
 
from bzrlib.bzrdir import BzrDir
25
 
from bzrlib import tests
26
 
 
27
 
 
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 TestSend(tests.TestCaseWithTransport):
34
 
 
35
 
    def make_trees(self):
36
 
        grandparent_tree = BzrDir.create_standalone_workingtree('grandparent')
37
 
        self.build_tree_contents([('grandparent/file1', 'grandparent')])
38
 
        grandparent_tree.add('file1')
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()
44
 
        self.build_tree_contents([('branch/file1', 'branch')])
45
 
        branch_tree.commit('last commit', rev_id='revision3')
46
 
 
47
 
    def test_uses_parent(self):
48
 
        """Parent location is used as a basis by default"""
49
 
        self.make_trees()
50
 
        os.chdir('grandparent')
51
 
        errmsg = self.run_bzr('send -o-', retcode=3)[1]
52
 
        self.assertContainsRe(errmsg, 'No submit branch known or specified')
53
 
        os.chdir('../branch')
54
 
        stdout, stderr = self.run_bzr('send -o-')
55
 
        self.assertEqual(stderr.count('Using saved location'), 1)
56
 
        br = read_bundle(StringIO(stdout))
57
 
        self.assertRevisions(br, ['revision3'])
58
 
 
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
 
 
71
 
    def assertRevisions(self, bi, expected):
72
 
        self.assertEqual(set(r.revision_id for r in bi.revisions),
73
 
            set(expected))
74
 
 
75
 
    def test_uses_submit(self):
76
 
        """Submit location can be used and set"""
77
 
        self.make_trees()
78
 
        os.chdir('branch')
79
 
        br = read_bundle(StringIO(self.run_bzr('send -o-')[0]))
80
 
        self.assertRevisions(br, ['revision3'])
81
 
        br = read_bundle(StringIO(self.run_bzr('send ../grandparent -o-')[0]))
82
 
        self.assertRevisions(br, ['revision3', 'revision2'])
83
 
        # submit location should be auto-remembered
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]))
91
 
        self.assertRevisions(br, ['revision3'])
92
 
        err = self.run_bzr('send --remember -o-', retcode=3)[1]
93
 
        self.assertContainsRe(err, 
94
 
                              '--remember requires a branch to be specified.')
95
 
 
96
 
    def test_revision_branch_interaction(self):
97
 
        self.make_trees()
98
 
        os.chdir('branch')
99
 
        bi = read_bundle(StringIO(self.run_bzr('send ../grandparent -o-')[0]))
100
 
        self.assertRevisions(bi, ['revision3', 'revision2'])
101
 
        out = StringIO(self.run_bzr('send ../grandparent -r -2 -o-')[0])
102
 
        bi = read_bundle(out)
103
 
        self.assertRevisions(bi, ['revision2'])
104
 
        sio = StringIO(self.run_bzr('send -r -2..-1 -o-')[0])
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'])
111
 
        self.run_bzr('send ../grandparent -r -2..-1 -o-')
112
 
 
113
 
    def test_output(self):
114
 
        # check output for consistency
115
 
        # win32 stdout converts LF to CRLF,
116
 
        # which would break patch-based bundles
117
 
        self.make_trees()        
118
 
        os.chdir('branch')
119
 
        stdout = self.run_bzr_subprocess('send -o-')[0]
120
 
        br = read_bundle(StringIO(stdout))
121
 
        self.assertRevisions(br, ['revision3'])
122
 
 
123
 
    def test_no_common_ancestor(self):
124
 
        foo = self.make_branch_and_tree('foo')
125
 
        foo.commit('rev a')
126
 
        bar = self.make_branch_and_tree('bar')
127
 
        bar.commit('rev b')
128
 
        os.chdir('foo')
129
 
        self.run_bzr('send ../bar -o-')
130
 
 
131
 
    def send_directive(self, args):
132
 
        sio = StringIO(self.run_bzr(['send', '-o-'] + args)[0])
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')
139
 
        md = self.send_directive([])
140
 
        self.assertIsNot(None, md.bundle)
141
 
        self.assertIsNot(None, md.patch)
142
 
 
143
 
        md = self.send_directive(['--format=0.9'])
144
 
        self.assertIsNot(None, md.bundle)
145
 
        self.assertIsNot(None, md.patch)
146
 
 
147
 
        md = self.send_directive(['--no-patch'])
148
 
        self.assertIsNot(None, md.bundle)
149
 
        self.assertIs(None, md.patch)
150
 
        self.run_bzr_error(['Format 0.9 does not permit bundle with no patch'],
151
 
                      'send --no-patch --format=0.9 -o-')
152
 
 
153
 
        md = self.send_directive(['--no-bundle', '.', '.'])
154
 
        self.assertIs(None, md.bundle)
155
 
        self.assertIsNot(None, md.patch)
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
 
 
162
 
        md = self.send_directive(['--no-bundle', '--no-patch', '.', '.'])
163
 
        self.assertIs(None, md.bundle)
164
 
        self.assertIs(None, md.patch)
165
 
 
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
 
 
171
 
    def test_from_option(self):
172
 
        self.make_trees()
173
 
        self.run_bzr('send', retcode=3)
174
 
        md = self.send_directive(['--from', 'branch'])
175
 
        self.assertEqual('revision3', md.revision_id)
176
 
        md = self.send_directive(['-f', 'branch'])
177
 
        self.assertEqual('revision3', md.revision_id)
178
 
 
179
 
    def test_output_option(self):
180
 
        self.make_trees()
181
 
        stdout = self.run_bzr('send -f branch --output file1')[0]
182
 
        self.assertEqual('', stdout)
183
 
        md_file = open('file1', 'rb')
184
 
        self.addCleanup(md_file.close)
185
 
        self.assertContainsRe(md_file.read(), 'revision3')
186
 
        stdout = self.run_bzr('send -f branch --output -')[0]
187
 
        self.assertContainsRe(stdout, 'revision3')
188
 
 
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')
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())
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')
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]