1
# Copyright (C) 2006 Canonical Ltd
2
# Authors: Aaron Bentley
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.
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.
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
20
from StringIO import StringIO
22
from bzrlib.bundle.serializer import read_bundle
23
from bzrlib.bzrdir import BzrDir
24
from bzrlib import tests
27
class TestBundle(tests.TestCaseWithTransport):
30
grandparent_tree = BzrDir.create_standalone_workingtree('grandparent')
31
grandparent_tree.commit('initial commit', rev_id='revision1')
32
parent_bzrdir = grandparent_tree.bzrdir.sprout('parent')
33
parent_tree = parent_bzrdir.open_workingtree()
34
parent_tree.commit('next commit', rev_id='revision2')
35
branch_tree = parent_tree.bzrdir.sprout('branch').open_workingtree()
36
branch_tree.commit('last commit', rev_id='revision3')
38
def test_uses_parent(self):
39
"""Parent location is used as a basis by default"""
41
os.chdir('grandparent')
42
errmsg = self.run_bzr('bundle', retcode=3)[1]
43
self.assertContainsRe(errmsg, 'No base branch known or specified')
45
stdout, stderr = self.run_bzr('bundle')
46
self.assertEqual(stderr.count('Using saved location'), 1)
47
br = read_bundle(StringIO(stdout))
48
self.assertRevisions(br, ['revision3'])
50
def assertRevisions(self, bi, expected):
51
self.assertEqual(set(r.revision_id for r in bi.revisions),
54
def test_uses_submit(self):
55
"""Submit location can be used and set"""
58
br = read_bundle(StringIO(self.run_bzr('bundle')[0]))
59
self.assertRevisions(br, ['revision3'])
60
br = read_bundle(StringIO(self.run_bzr('bundle', '../grandparent')[0]))
61
self.assertRevisions(br, ['revision3', 'revision2'])
62
# submit location should be auto-remembered
63
br = read_bundle(StringIO(self.run_bzr('bundle')[0]))
64
self.assertRevisions(br, ['revision3', 'revision2'])
65
self.run_bzr('bundle', '../parent')
66
br = read_bundle(StringIO(self.run_bzr('bundle')[0]))
67
self.assertRevisions(br, ['revision3', 'revision2'])
68
self.run_bzr('bundle', '../parent', '--remember')
69
br = read_bundle(StringIO(self.run_bzr('bundle')[0]))
70
self.assertRevisions(br, ['revision3'])
71
err = self.run_bzr('bundle', '--remember', retcode=3)[1]
72
self.assertContainsRe(err,
73
'--remember requires a branch to be specified.')
75
def test_revision_branch_interaction(self):
78
bi = read_bundle(StringIO(self.run_bzr('bundle', '../grandparent')[0]))
79
self.assertRevisions(bi, ['revision3', 'revision2'])
80
out = StringIO(self.run_bzr('bundle', '../grandparent', '-r', '-2')[0])
82
self.assertRevisions(bi, ['revision2'])
83
bi = read_bundle(StringIO(self.run_bzr('bundle', '-r', '-2..-1')[0]))
84
self.assertRevisions(bi, ['revision3'])
85
self.run_bzr('bundle', '../grandparent', '-r', '-2..-1', retcode=3)
87
def test_output(self):
88
# check output for consistency
89
# win32 stdout converts LF to CRLF,
90
# and this is breaks the created bundle
93
stdout = self.run_bzr_subprocess('bundle')[0]
94
br = read_bundle(StringIO(stdout))
95
self.assertRevisions(br, ['revision3'])
97
def test_no_common_ancestor(self):
98
foo = self.make_branch_and_tree('foo')
99
bar = self.make_branch_and_tree('bar')
101
self.run_bzr('bundle', '../bar')