/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2052.3.2 by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical
1
# Copyright (C) 2006 Canonical Ltd
1185.84.4 by Aaron Bentley
Use parent branch as default base branch
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
1793.2.2 by Aaron Bentley
Move BundleReader into v07 serializer
22
from bzrlib.bundle.serializer import read_bundle
1185.84.4 by Aaron Bentley
Use parent branch as default base branch
23
from bzrlib.bzrdir import BzrDir
2490.2.28 by Aaron Bentley
Fix handling of null revision
24
from bzrlib import tests
25
26
27
class TestBundle(tests.TestCaseWithTransport):
1185.84.4 by Aaron Bentley
Use parent branch as default base branch
28
1793.2.13 by Aaron Bentley
Use single make function for tests
29
    def make_trees(self):
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')
37
1185.84.4 by Aaron Bentley
Use parent branch as default base branch
38
    def test_uses_parent(self):
39
        """Parent location is used as a basis by default"""
2387.1.1 by Robert Collins
Remove the --basis parameter to clone etc. (Robert Collins)
40
        self.make_trees()
1793.2.13 by Aaron Bentley
Use single make function for tests
41
        os.chdir('grandparent')
1185.84.4 by Aaron Bentley
Use parent branch as default base branch
42
        errmsg = self.run_bzr('bundle', retcode=3)[1]
43
        self.assertContainsRe(errmsg, 'No base branch known or specified')
44
        os.chdir('../branch')
1793.2.12 by Aaron Bentley
Avoid duplicating the 'Using specified base' message
45
        stdout, stderr = self.run_bzr('bundle')
46
        self.assertEqual(stderr.count('Using saved location'), 1)
47
        br = read_bundle(StringIO(stdout))
1793.2.14 by Aaron Bentley
Clean up bundle revision specification
48
        self.assertRevisions(br, ['revision3'])
49
50
    def assertRevisions(self, bi, expected):
51
        self.assertEqual([r.revision_id for r in bi.revisions], expected)
1804.1.1 by Aaron Bentley
Add support for submit location to bundles
52
53
    def test_uses_submit(self):
54
        """Submit location can be used and set"""
1793.2.13 by Aaron Bentley
Use single make function for tests
55
        self.make_trees()        
1804.1.1 by Aaron Bentley
Add support for submit location to bundles
56
        os.chdir('branch')
57
        br = read_bundle(StringIO(self.run_bzr('bundle')[0]))
1793.2.14 by Aaron Bentley
Clean up bundle revision specification
58
        self.assertRevisions(br, ['revision3'])
1793.2.13 by Aaron Bentley
Use single make function for tests
59
        br = read_bundle(StringIO(self.run_bzr('bundle', '../grandparent')[0]))
1793.2.14 by Aaron Bentley
Clean up bundle revision specification
60
        self.assertRevisions(br, ['revision3', 'revision2'])
1804.1.1 by Aaron Bentley
Add support for submit location to bundles
61
        # submit location should be auto-remembered
62
        br = read_bundle(StringIO(self.run_bzr('bundle')[0]))
1793.2.14 by Aaron Bentley
Clean up bundle revision specification
63
        self.assertRevisions(br, ['revision3', 'revision2'])
1804.1.1 by Aaron Bentley
Add support for submit location to bundles
64
        self.run_bzr('bundle', '../parent')
65
        br = read_bundle(StringIO(self.run_bzr('bundle')[0]))
1793.2.14 by Aaron Bentley
Clean up bundle revision specification
66
        self.assertRevisions(br, ['revision3', 'revision2'])
1804.1.1 by Aaron Bentley
Add support for submit location to bundles
67
        self.run_bzr('bundle', '../parent', '--remember')
68
        br = read_bundle(StringIO(self.run_bzr('bundle')[0]))
1793.2.14 by Aaron Bentley
Clean up bundle revision specification
69
        self.assertRevisions(br, ['revision3'])
1804.1.1 by Aaron Bentley
Add support for submit location to bundles
70
        err = self.run_bzr('bundle', '--remember', retcode=3)[1]
71
        self.assertContainsRe(err, 
72
                              '--remember requires a branch to be specified.')
1793.2.14 by Aaron Bentley
Clean up bundle revision specification
73
74
    def test_revision_branch_interaction(self):
75
        self.make_trees()        
76
        os.chdir('branch')
77
        bi = read_bundle(StringIO(self.run_bzr('bundle', '../grandparent')[0]))
78
        self.assertRevisions(bi, ['revision3', 'revision2'])
79
        out = StringIO(self.run_bzr('bundle', '../grandparent', '-r', '-2')[0])
80
        bi = read_bundle(out)
81
        self.assertRevisions(bi, ['revision2'])
82
        bi = read_bundle(StringIO(self.run_bzr('bundle', '-r', '-2..-1')[0]))
83
        self.assertRevisions(bi, ['revision3'])
84
        self.run_bzr('bundle', '../grandparent', '-r', '-2..-1', retcode=3)
2178.4.1 by Alexander Belchenko
Provide tests to illustrate bug #55276 on win32.
85
86
    def test_output(self):
87
        # check output for consistency
2178.4.5 by Alexander Belchenko
Spell-checking (thanks to Aaron)
88
        # win32 stdout converts LF to CRLF,
89
        # and this is breaks the created bundle
2178.4.1 by Alexander Belchenko
Provide tests to illustrate bug #55276 on win32.
90
        self.make_trees()        
91
        os.chdir('branch')
92
        stdout = self.run_bzr_subprocess('bundle')[0]
93
        br = read_bundle(StringIO(stdout))
94
        self.assertRevisions(br, ['revision3'])
2490.2.28 by Aaron Bentley
Fix handling of null revision
95
96
    def test_no_common_ancestor(self):
97
        foo = self.make_branch_and_tree('foo')
98
        bar = self.make_branch_and_tree('bar')
99
        os.chdir('foo')
100
        self.run_bzr('bundle', '../bar')