~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-08-17 18:13:57 UTC
  • mfrom: (5268.7.29 transport-segments)
  • Revision ID: pqm@pqm.ubuntu.com-20110817181357-y5q5eth1hk8bl3om
(jelmer) Allow specifying the colocated branch to use in the branch URL,
 and retrieving the branch name using ControlDir._get_selected_branch.
 (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2006-2011 Canonical Ltd
2
2
# Authors: Aaron Bentley
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
13
13
#
14
14
# You should have received a copy of the GNU General Public License
15
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
 
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
17
 
 
18
 
20
19
import sys
21
 
from StringIO import StringIO
 
20
from cStringIO import StringIO
22
21
 
23
22
from bzrlib import (
24
 
    branch as _mod_branch,
 
23
    branch,
 
24
    bzrdir,
25
25
    merge_directive,
 
26
    tests,
26
27
    )
27
28
from bzrlib.bundle import serializer
28
 
from bzrlib.bzrdir import BzrDir
29
 
from bzrlib import tests
30
 
 
31
 
 
32
 
def read_bundle(fileobj):
33
 
    md = merge_directive.MergeDirective.from_lines(fileobj.readlines())
34
 
    return serializer.read_bundle(StringIO(md.get_raw_bundle()))
35
 
 
36
 
 
37
 
class TestSend(tests.TestCaseWithTransport):
38
 
 
39
 
    def make_trees(self):
40
 
        grandparent_tree = BzrDir.create_standalone_workingtree('grandparent')
 
29
from bzrlib.transport import memory
 
30
from bzrlib.tests import (
 
31
    scenarios,
 
32
    script,
 
33
    )
 
34
 
 
35
 
 
36
load_tests = scenarios.load_tests_apply_scenarios
 
37
 
 
38
 
 
39
class TestSendMixin(object):
 
40
 
 
41
    _default_command = ['send', '-o-']
 
42
    _default_wd = 'branch'
 
43
 
 
44
    def run_send(self, args, cmd=None, rc=0, wd=None, err_re=None):
 
45
        if cmd is None: cmd = self._default_command
 
46
        if wd is None: wd = self._default_wd
 
47
        if err_re is None: err_re = []
 
48
        return self.run_bzr(cmd + args, retcode=rc,
 
49
                            working_dir=wd,
 
50
                            error_regexes=err_re)
 
51
 
 
52
    def get_MD(self, args, cmd=None, wd='branch'):
 
53
        out = StringIO(self.run_send(args, cmd=cmd, wd=wd)[0])
 
54
        return merge_directive.MergeDirective.from_lines(out)
 
55
 
 
56
    def assertBundleContains(self, revs, args, cmd=None, wd='branch'):
 
57
        md = self.get_MD(args, cmd=cmd, wd=wd)
 
58
        br = serializer.read_bundle(StringIO(md.get_raw_bundle()))
 
59
        self.assertEqual(set(revs), set(r.revision_id for r in br.revisions))
 
60
 
 
61
 
 
62
class TestSend(tests.TestCaseWithTransport, TestSendMixin):
 
63
 
 
64
    def setUp(self):
 
65
        super(TestSend, self).setUp()
 
66
        grandparent_tree = bzrdir.BzrDir.create_standalone_workingtree(
 
67
            'grandparent')
41
68
        self.build_tree_contents([('grandparent/file1', 'grandparent')])
42
69
        grandparent_tree.add('file1')
43
 
        grandparent_tree.commit('initial commit', rev_id='revision1')
 
70
        grandparent_tree.commit('initial commit', rev_id='rev1')
 
71
 
44
72
        parent_bzrdir = grandparent_tree.bzrdir.sprout('parent')
45
73
        parent_tree = parent_bzrdir.open_workingtree()
46
 
        parent_tree.commit('next commit', rev_id='revision2')
 
74
        parent_tree.commit('next commit', rev_id='rev2')
 
75
 
47
76
        branch_tree = parent_tree.bzrdir.sprout('branch').open_workingtree()
48
77
        self.build_tree_contents([('branch/file1', 'branch')])
49
 
        branch_tree.commit('last commit', rev_id='revision3')
 
78
        branch_tree.commit('last commit', rev_id='rev3')
 
79
 
 
80
    def assertFormatIs(self, fmt_string, md):
 
81
        self.assertEqual(fmt_string, md.get_raw_bundle().splitlines()[0])
50
82
 
51
83
    def test_uses_parent(self):
52
84
        """Parent location is used as a basis by default"""
53
 
        self.make_trees()
54
 
        os.chdir('grandparent')
55
 
        errmsg = self.run_bzr('send -o-', retcode=3)[1]
 
85
        errmsg = self.run_send([], rc=3, wd='grandparent')[1]
56
86
        self.assertContainsRe(errmsg, 'No submit branch known or specified')
57
 
        os.chdir('../branch')
58
 
        stdout, stderr = self.run_bzr('send -o-')
 
87
        stdout, stderr = self.run_send([])
59
88
        self.assertEqual(stderr.count('Using saved parent location'), 1)
60
 
        br = read_bundle(StringIO(stdout))
61
 
        self.assertRevisions(br, ['revision3'])
 
89
        self.assertBundleContains(['rev3'], [])
62
90
 
63
91
    def test_bundle(self):
64
92
        """Bundle works like send, except -o is not required"""
65
 
        self.make_trees()
66
 
        os.chdir('grandparent')
67
 
        errmsg = self.run_bzr('bundle', retcode=3)[1]
 
93
        errmsg = self.run_send([], cmd=['bundle'], rc=3, wd='grandparent')[1]
68
94
        self.assertContainsRe(errmsg, 'No submit branch known or specified')
69
 
        os.chdir('../branch')
70
 
        stdout, stderr = self.run_bzr('bundle')
 
95
        stdout, stderr = self.run_send([], cmd=['bundle'])
71
96
        self.assertEqual(stderr.count('Using saved parent location'), 1)
72
 
        br = read_bundle(StringIO(stdout))
73
 
        self.assertRevisions(br, ['revision3'])
74
 
 
75
 
    def assertRevisions(self, bi, expected):
76
 
        self.assertEqual(set(r.revision_id for r in bi.revisions),
77
 
            set(expected))
 
97
        self.assertBundleContains(['rev3'], [], cmd=['bundle'])
78
98
 
79
99
    def test_uses_submit(self):
80
100
        """Submit location can be used and set"""
81
 
        self.make_trees()
82
 
        os.chdir('branch')
83
 
        br = read_bundle(StringIO(self.run_bzr('send -o-')[0]))
84
 
        self.assertRevisions(br, ['revision3'])
85
 
        br = read_bundle(StringIO(self.run_bzr('send ../grandparent -o-')[0]))
86
 
        self.assertRevisions(br, ['revision3', 'revision2'])
 
101
        self.assertBundleContains(['rev3'], [])
 
102
        self.assertBundleContains(['rev3', 'rev2'], ['../grandparent'])
87
103
        # submit location should be auto-remembered
88
 
        br = read_bundle(StringIO(self.run_bzr('send -o-')[0]))
89
 
        self.assertRevisions(br, ['revision3', 'revision2'])
90
 
        self.run_bzr('send ../parent -o-')
91
 
        br = read_bundle(StringIO(self.run_bzr('send -o-')[0]))
92
 
        self.assertRevisions(br, ['revision3', 'revision2'])
93
 
        self.run_bzr('send ../parent --remember -o-')
94
 
        br = read_bundle(StringIO(self.run_bzr('send -o-')[0]))
95
 
        self.assertRevisions(br, ['revision3'])
96
 
        err = self.run_bzr('send --remember -o-', retcode=3)[1]
97
 
        self.assertContainsRe(err, 
 
104
        self.assertBundleContains(['rev3', 'rev2'], [])
 
105
 
 
106
        self.run_send(['../parent'])
 
107
        # We still point to ../grandparent
 
108
        self.assertBundleContains(['rev3', 'rev2'], [])
 
109
        # Remember parent now
 
110
        self.run_send(['../parent', '--remember'])
 
111
        # Now we point to parent
 
112
        self.assertBundleContains(['rev3'], [])
 
113
 
 
114
        err = self.run_send(['--remember'], rc=3)[1]
 
115
        self.assertContainsRe(err,
98
116
                              '--remember requires a branch to be specified.')
99
117
 
100
118
    def test_revision_branch_interaction(self):
101
 
        self.make_trees()
102
 
        os.chdir('branch')
103
 
        bi = read_bundle(StringIO(self.run_bzr('send ../grandparent -o-')[0]))
104
 
        self.assertRevisions(bi, ['revision3', 'revision2'])
105
 
        out = StringIO(self.run_bzr('send ../grandparent -r -2 -o-')[0])
106
 
        bi = read_bundle(out)
107
 
        self.assertRevisions(bi, ['revision2'])
108
 
        sio = StringIO(self.run_bzr('send -r -2..-1 -o-')[0])
109
 
        md = merge_directive.MergeDirective.from_lines(sio.readlines())
110
 
        self.assertEqual('revision2', md.base_revision_id)
111
 
        self.assertEqual('revision3', md.revision_id)
112
 
        sio.seek(0)
113
 
        bi = read_bundle(sio)
114
 
        self.assertRevisions(bi, ['revision2', 'revision3'])
115
 
        self.run_bzr('send ../grandparent -r -2..-1 -o-')
 
119
        self.assertBundleContains(['rev3', 'rev2'], ['../grandparent'])
 
120
        self.assertBundleContains(['rev2'], ['../grandparent', '-r-2'])
 
121
        self.assertBundleContains(['rev3', 'rev2'],
 
122
                                  ['../grandparent', '-r-2..-1'])
 
123
        md = self.get_MD(['-r-2..-1'])
 
124
        self.assertEqual('rev2', md.base_revision_id)
 
125
        self.assertEqual('rev3', md.revision_id)
116
126
 
117
127
    def test_output(self):
118
128
        # check output for consistency
119
129
        # win32 stdout converts LF to CRLF,
120
130
        # which would break patch-based bundles
121
 
        self.make_trees()        
122
 
        os.chdir('branch')
123
 
        stdout = self.run_bzr_subprocess('send -o-')[0]
124
 
        br = read_bundle(StringIO(stdout))
125
 
        self.assertRevisions(br, ['revision3'])
 
131
        self.assertBundleContains(['rev3'], [])
126
132
 
127
133
    def test_no_common_ancestor(self):
128
134
        foo = self.make_branch_and_tree('foo')
129
135
        foo.commit('rev a')
130
136
        bar = self.make_branch_and_tree('bar')
131
137
        bar.commit('rev b')
132
 
        os.chdir('foo')
133
 
        self.run_bzr('send ../bar -o-')
134
 
 
135
 
    def send_directive(self, args):
136
 
        sio = StringIO(self.run_bzr(['send', '-o-'] + args)[0])
137
 
        return merge_directive.MergeDirective.from_lines(sio.readlines())
 
138
        self.run_send(['--from', 'foo', '../bar'], wd='foo')
138
139
 
139
140
    def test_content_options(self):
140
141
        """--no-patch and --no-bundle should work and be independant"""
141
 
        self.make_trees()
142
 
        os.chdir('branch')
143
 
        md = self.send_directive([])
144
 
        self.assertIsNot(None, md.bundle)
145
 
        self.assertIsNot(None, md.patch)
146
 
 
147
 
        md = self.send_directive(['--format=0.9'])
148
 
        self.assertIsNot(None, md.bundle)
149
 
        self.assertIsNot(None, md.patch)
150
 
 
151
 
        md = self.send_directive(['--no-patch'])
 
142
        md = self.get_MD([])
 
143
        self.assertIsNot(None, md.bundle)
 
144
        self.assertIsNot(None, md.patch)
 
145
 
 
146
        md = self.get_MD(['--format=0.9'])
 
147
        self.assertIsNot(None, md.bundle)
 
148
        self.assertIsNot(None, md.patch)
 
149
 
 
150
        md = self.get_MD(['--no-patch'])
152
151
        self.assertIsNot(None, md.bundle)
153
152
        self.assertIs(None, md.patch)
154
153
        self.run_bzr_error(['Format 0.9 does not permit bundle with no patch'],
155
 
                      'send --no-patch --format=0.9 -o-')
156
 
 
157
 
        md = self.send_directive(['--no-bundle', '.', '.'])
 
154
                           ['send', '--no-patch', '--format=0.9', '-o-'],
 
155
                           working_dir='branch')
 
156
        md = self.get_MD(['--no-bundle', '.', '.'])
158
157
        self.assertIs(None, md.bundle)
159
158
        self.assertIsNot(None, md.patch)
160
159
 
161
 
        md = self.send_directive(['--no-bundle', '--format=0.9', '../parent',
 
160
        md = self.get_MD(['--no-bundle', '--format=0.9', '../parent',
162
161
                                  '.'])
163
162
        self.assertIs(None, md.bundle)
164
163
        self.assertIsNot(None, md.patch)
165
164
 
166
 
        md = self.send_directive(['--no-bundle', '--no-patch', '.', '.'])
 
165
        md = self.get_MD(['--no-bundle', '--no-patch', '.', '.'])
167
166
        self.assertIs(None, md.bundle)
168
167
        self.assertIs(None, md.patch)
169
168
 
170
 
        md = self.send_directive(['--no-bundle', '--no-patch', '--format=0.9',
171
 
                                  '../parent', '.'])
 
169
        md = self.get_MD(['--no-bundle', '--no-patch', '--format=0.9',
 
170
                          '../parent', '.'])
172
171
        self.assertIs(None, md.bundle)
173
172
        self.assertIs(None, md.patch)
174
173
 
175
174
    def test_from_option(self):
176
 
        self.make_trees()
177
175
        self.run_bzr('send', retcode=3)
178
 
        md = self.send_directive(['--from', 'branch'])
179
 
        self.assertEqual('revision3', md.revision_id)
180
 
        md = self.send_directive(['-f', 'branch'])
181
 
        self.assertEqual('revision3', md.revision_id)
 
176
        md = self.get_MD(['--from', 'branch'])
 
177
        self.assertEqual('rev3', md.revision_id)
 
178
        md = self.get_MD(['-f', 'branch'])
 
179
        self.assertEqual('rev3', md.revision_id)
182
180
 
183
181
    def test_output_option(self):
184
 
        self.make_trees()
185
182
        stdout = self.run_bzr('send -f branch --output file1')[0]
186
183
        self.assertEqual('', stdout)
187
184
        md_file = open('file1', 'rb')
188
185
        self.addCleanup(md_file.close)
189
 
        self.assertContainsRe(md_file.read(), 'revision3')
 
186
        self.assertContainsRe(md_file.read(), 'rev3')
190
187
        stdout = self.run_bzr('send -f branch --output -')[0]
191
 
        self.assertContainsRe(stdout, 'revision3')
 
188
        self.assertContainsRe(stdout, 'rev3')
 
189
 
 
190
    def test_note_revisions(self):
 
191
        stderr = self.run_send([])[1]
 
192
        self.assertEndsWith(stderr, '\nBundling 1 revision(s).\n')
192
193
 
193
194
    def test_mailto_option(self):
194
 
        self.make_trees()
195
 
        branch = _mod_branch.Branch.open('branch')
196
 
        branch.get_config().set_user_option('mail_client', 'editor')
197
 
        self.run_bzr_error(('No mail-to address specified',), 'send -f branch')
198
 
        branch.get_config().set_user_option('mail_client', 'bogus')
199
 
        self.run_bzr('send -f branch -o-')
 
195
        b = branch.Branch.open('branch')
 
196
        b.get_config().set_user_option('mail_client', 'editor')
 
197
        self.run_bzr_error(
 
198
            ('No mail-to address \\(--mail-to\\) or output \\(-o\\) specified',
 
199
            ), 'send -f branch')
 
200
        b.get_config().set_user_option('mail_client', 'bogus')
 
201
        self.run_send([])
200
202
        self.run_bzr_error(('Unknown mail client: bogus',),
201
203
                           'send -f branch --mail-to jrandom@example.org')
202
 
        branch.get_config().set_user_option('submit_to', 'jrandom@example.org')
 
204
        b.get_config().set_user_option('submit_to', 'jrandom@example.org')
203
205
        self.run_bzr_error(('Unknown mail client: bogus',),
204
206
                           'send -f branch')
205
207
 
206
208
    def test_mailto_child_option(self):
207
209
        """Make sure that child_submit_to is used."""
208
 
        self.make_trees()
209
 
        branch = _mod_branch.Branch.open('branch')
210
 
        branch.get_config().set_user_option('mail_client', 'bogus')
211
 
        parent = _mod_branch.Branch.open('parent')
212
 
        parent.get_config().set_user_option('child_submit_to', 
 
210
        b = branch.Branch.open('branch')
 
211
        b.get_config().set_user_option('mail_client', 'bogus')
 
212
        parent = branch.Branch.open('parent')
 
213
        parent.get_config().set_user_option('child_submit_to',
213
214
                           'somebody@example.org')
214
215
        self.run_bzr_error(('Unknown mail client: bogus',),
215
216
                           'send -f branch')
216
217
 
217
218
    def test_format(self):
218
 
        self.make_trees()
219
 
        s = StringIO(self.run_bzr('send -f branch -o- --format=4')[0])
220
 
        md = merge_directive.MergeDirective.from_lines(s.readlines())
 
219
        md = self.get_MD(['--format=4'])
221
220
        self.assertIs(merge_directive.MergeDirective2, md.__class__)
222
 
        s = StringIO(self.run_bzr('send -f branch -o- --format=0.9')[0])
223
 
        md = merge_directive.MergeDirective.from_lines(s.readlines())
224
 
        self.assertContainsRe(md.get_raw_bundle().splitlines()[0],
225
 
            '# Bazaar revision bundle v0.9')
226
 
        s = StringIO(self.run_bzr('bundle -f branch -o- --format=0.9')[0])
227
 
        md = merge_directive.MergeDirective.from_lines(s.readlines())
228
 
        self.assertContainsRe(md.get_raw_bundle().splitlines()[0],
229
 
            '# Bazaar revision bundle v0.9')
 
221
        self.assertFormatIs('# Bazaar revision bundle v4', md)
 
222
 
 
223
        md = self.get_MD(['--format=0.9'])
 
224
        self.assertFormatIs('# Bazaar revision bundle v0.9', md)
 
225
 
 
226
        md = self.get_MD(['--format=0.9'], cmd=['bundle'])
 
227
        self.assertFormatIs('# Bazaar revision bundle v0.9', md)
230
228
        self.assertIs(merge_directive.MergeDirective, md.__class__)
 
229
 
231
230
        self.run_bzr_error(['Bad value .* for option .format.'],
232
231
                            'send -f branch -o- --format=0.999')[0]
233
232
 
 
233
    def test_format_child_option(self):
 
234
        parent_config = branch.Branch.open('parent').get_config()
 
235
        parent_config.set_user_option('child_submit_format', '4')
 
236
        md = self.get_MD([])
 
237
        self.assertIs(merge_directive.MergeDirective2, md.__class__)
 
238
 
 
239
        parent_config.set_user_option('child_submit_format', '0.9')
 
240
        md = self.get_MD([])
 
241
        self.assertFormatIs('# Bazaar revision bundle v0.9', md)
 
242
 
 
243
        md = self.get_MD([], cmd=['bundle'])
 
244
        self.assertFormatIs('# Bazaar revision bundle v0.9', md)
 
245
        self.assertIs(merge_directive.MergeDirective, md.__class__)
 
246
 
 
247
        parent_config.set_user_option('child_submit_format', '0.999')
 
248
        self.run_bzr_error(["No such send format '0.999'"],
 
249
                            'send -f branch -o-')[0]
 
250
 
234
251
    def test_message_option(self):
235
 
        self.make_trees()
236
252
        self.run_bzr('send', retcode=3)
237
 
        md = self.send_directive(['--from', 'branch'])
 
253
        md = self.get_MD([])
238
254
        self.assertIs(None, md.message)
239
 
        md = self.send_directive(['--from', 'branch', '-m', 'my message'])
 
255
        md = self.get_MD(['-m', 'my message'])
240
256
        self.assertEqual('my message', md.message)
241
257
 
242
258
    def test_omitted_revision(self):
243
 
        self.make_trees()
244
 
        md = self.send_directive(['-r-2..', '--from', 'branch'])
245
 
        self.assertEqual('revision2', md.base_revision_id)
246
 
        self.assertEqual('revision3', md.revision_id)
247
 
        md = self.send_directive(['-r..3', '--from', 'branch',
248
 
                                 'grandparent'])
249
 
        self.assertEqual('revision1', md.base_revision_id)
250
 
        self.assertEqual('revision3', md.revision_id)
 
259
        md = self.get_MD(['-r-2..'])
 
260
        self.assertEqual('rev2', md.base_revision_id)
 
261
        self.assertEqual('rev3', md.revision_id)
 
262
        md = self.get_MD(['-r..3', '--from', 'branch', 'grandparent'], wd='.')
 
263
        self.assertEqual('rev1', md.base_revision_id)
 
264
        self.assertEqual('rev3', md.revision_id)
251
265
 
252
266
    def test_nonexistant_branch(self):
253
 
        if sys.platform == "win32":
254
 
            location = "C:/i/do/not/exist/"
255
 
        else:
256
 
            location = "/i/do/not/exist/"
 
267
        self.vfs_transport_factory = memory.MemoryServer
 
268
        location = self.get_url('absentdir/')
257
269
        out, err = self.run_bzr(["send", "--from", location], retcode=3)
258
270
        self.assertEqual(out, '')
259
271
        self.assertEqual(err, 'bzr: ERROR: Not a branch: "%s".\n' % location)
 
272
 
 
273
 
 
274
class TestSendStrictMixin(TestSendMixin):
 
275
 
 
276
    def make_parent_and_local_branches(self):
 
277
        # Create a 'parent' branch as the base
 
278
        self.parent_tree = bzrdir.BzrDir.create_standalone_workingtree('parent')
 
279
        self.build_tree_contents([('parent/file', 'parent')])
 
280
        self.parent_tree.add('file')
 
281
        self.parent_tree.commit('first commit', rev_id='parent')
 
282
        # Branch 'local' from parent and do a change
 
283
        local_bzrdir = self.parent_tree.bzrdir.sprout('local')
 
284
        self.local_tree = local_bzrdir.open_workingtree()
 
285
        self.build_tree_contents([('local/file', 'local')])
 
286
        self.local_tree.commit('second commit', rev_id='local')
 
287
 
 
288
    _default_command = ['send', '-o-', '../parent']
 
289
    _default_wd = 'local'
 
290
    _default_sent_revs = ['local']
 
291
    _default_errors = ['Working tree ".*/local/" has uncommitted '
 
292
                       'changes \(See bzr status\)\.',]
 
293
    _default_additional_error = 'Use --no-strict to force the send.\n'
 
294
    _default_additional_warning = 'Uncommitted changes will not be sent.'
 
295
 
 
296
    def set_config_send_strict(self, value):
 
297
        # set config var (any of bazaar.conf, locations.conf, branch.conf
 
298
        # should do)
 
299
        conf = self.local_tree.branch.get_config()
 
300
        conf.set_user_option('send_strict', value)
 
301
 
 
302
    def assertSendFails(self, args):
 
303
        out, err = self.run_send(args, rc=3, err_re=self._default_errors)
 
304
        self.assertContainsRe(err, self._default_additional_error)
 
305
 
 
306
    def assertSendSucceeds(self, args, revs=None, with_warning=False):
 
307
        if with_warning:
 
308
            err_re = self._default_errors
 
309
        else:
 
310
            err_re = []
 
311
        if revs is None:
 
312
            revs = self._default_sent_revs
 
313
        out, err = self.run_send(args, err_re=err_re)
 
314
        bundling_revs = 'Bundling %d revision(s).\n' % len(revs)
 
315
        if with_warning:
 
316
            self.assertContainsRe(err, self._default_additional_warning)
 
317
            self.assertEndsWith(err, bundling_revs)
 
318
        else:
 
319
            self.assertEquals(bundling_revs, err)
 
320
        md = merge_directive.MergeDirective.from_lines(StringIO(out))
 
321
        self.assertEqual('parent', md.base_revision_id)
 
322
        br = serializer.read_bundle(StringIO(md.get_raw_bundle()))
 
323
        self.assertEqual(set(revs), set(r.revision_id for r in br.revisions))
 
324
 
 
325
 
 
326
class TestSendStrictWithoutChanges(tests.TestCaseWithTransport,
 
327
                                   TestSendStrictMixin):
 
328
 
 
329
    def setUp(self):
 
330
        super(TestSendStrictWithoutChanges, self).setUp()
 
331
        self.make_parent_and_local_branches()
 
332
 
 
333
    def test_send_default(self):
 
334
        self.assertSendSucceeds([])
 
335
 
 
336
    def test_send_strict(self):
 
337
        self.assertSendSucceeds(['--strict'])
 
338
 
 
339
    def test_send_no_strict(self):
 
340
        self.assertSendSucceeds(['--no-strict'])
 
341
 
 
342
    def test_send_config_var_strict(self):
 
343
        self.set_config_send_strict('true')
 
344
        self.assertSendSucceeds([])
 
345
 
 
346
    def test_send_config_var_no_strict(self):
 
347
        self.set_config_send_strict('false')
 
348
        self.assertSendSucceeds([])
 
349
 
 
350
 
 
351
class TestSendStrictWithChanges(tests.TestCaseWithTransport,
 
352
                                TestSendStrictMixin):
 
353
 
 
354
    # These are textually the same as test_push.strict_push_change_scenarios,
 
355
    # but since the functions are reimplemented here, the definitions are left
 
356
    # here too.
 
357
    scenarios = [
 
358
        ('uncommitted',
 
359
         dict(_changes_type='_uncommitted_changes')),
 
360
        ('pending_merges',
 
361
         dict(_changes_type='_pending_merges')),
 
362
        ('out-of-sync-trees',
 
363
         dict(_changes_type='_out_of_sync_trees')),
 
364
        ]
 
365
 
 
366
    _changes_type = None # Set by load_tests
 
367
 
 
368
    def setUp(self):
 
369
        super(TestSendStrictWithChanges, self).setUp()
 
370
        # load tests set _changes_types to the name of the method we want to
 
371
        # call now
 
372
        do_changes_func = getattr(self, self._changes_type)
 
373
        do_changes_func()
 
374
 
 
375
    def _uncommitted_changes(self):
 
376
        self.make_parent_and_local_branches()
 
377
        # Make a change without committing it
 
378
        self.build_tree_contents([('local/file', 'modified')])
 
379
 
 
380
    def _pending_merges(self):
 
381
        self.make_parent_and_local_branches()
 
382
        # Create 'other' branch containing a new file
 
383
        other_bzrdir = self.parent_tree.bzrdir.sprout('other')
 
384
        other_tree = other_bzrdir.open_workingtree()
 
385
        self.build_tree_contents([('other/other-file', 'other')])
 
386
        other_tree.add('other-file')
 
387
        other_tree.commit('other commit', rev_id='other')
 
388
        # Merge and revert, leaving a pending merge
 
389
        self.local_tree.merge_from_branch(other_tree.branch)
 
390
        self.local_tree.revert(filenames=['other-file'], backups=False)
 
391
 
 
392
    def _out_of_sync_trees(self):
 
393
        self.make_parent_and_local_branches()
 
394
        self.run_bzr(['checkout', '--lightweight', 'local', 'checkout'])
 
395
        # Make a change and commit it
 
396
        self.build_tree_contents([('local/file', 'modified in local')])
 
397
        self.local_tree.commit('modify file', rev_id='modified-in-local')
 
398
        # Exercise commands from the checkout directory
 
399
        self._default_wd = 'checkout'
 
400
        self._default_errors = ["Working tree is out of date, please run"
 
401
                                " 'bzr update'\.",]
 
402
        self._default_sent_revs = ['modified-in-local', 'local']
 
403
 
 
404
    def test_send_default(self):
 
405
        self.assertSendSucceeds([], with_warning=True)
 
406
 
 
407
    def test_send_with_revision(self):
 
408
        self.assertSendSucceeds(['-r', 'revid:local'], revs=['local'])
 
409
 
 
410
    def test_send_no_strict(self):
 
411
        self.assertSendSucceeds(['--no-strict'])
 
412
 
 
413
    def test_send_strict_with_changes(self):
 
414
        self.assertSendFails(['--strict'])
 
415
 
 
416
    def test_send_respect_config_var_strict(self):
 
417
        self.set_config_send_strict('true')
 
418
        self.assertSendFails([])
 
419
        self.assertSendSucceeds(['--no-strict'])
 
420
 
 
421
    def test_send_bogus_config_var_ignored(self):
 
422
        self.set_config_send_strict("I'm unsure")
 
423
        self.assertSendSucceeds([], with_warning=True)
 
424
 
 
425
    def test_send_no_strict_command_line_override_config(self):
 
426
        self.set_config_send_strict('true')
 
427
        self.assertSendFails([])
 
428
        self.assertSendSucceeds(['--no-strict'])
 
429
 
 
430
    def test_send_strict_command_line_override_config(self):
 
431
        self.set_config_send_strict('false')
 
432
        self.assertSendSucceeds([])
 
433
        self.assertSendFails(['--strict'])
 
434
 
 
435
 
 
436
class TestBundleStrictWithoutChanges(TestSendStrictWithoutChanges):
 
437
 
 
438
    _default_command = ['bundle-revisions', '../parent']