~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-07-19 16:09:34 UTC
  • mfrom: (2520.4.135 bzr.mpbundle)
  • Revision ID: pqm@pqm.ubuntu.com-20070719160934-d51fyijw69oto88p
Add new bundle and merge-directive formats

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 Canonical Ltd
 
1
# Copyright (C) 2006, 2007 Canonical Ltd
2
2
# Authors: Aaron Bentley
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
19
19
import os
20
20
from StringIO import StringIO
21
21
 
22
 
from bzrlib.bundle.serializer import read_bundle
 
22
from bzrlib import merge_directive
 
23
from bzrlib.bundle import serializer
23
24
from bzrlib.bzrdir import BzrDir
24
25
from bzrlib import tests
25
26
 
26
27
 
27
 
class TestBundle(tests.TestCaseWithTransport):
 
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 TestSubmit(tests.TestCaseWithTransport):
28
34
 
29
35
    def make_trees(self):
30
36
        grandparent_tree = BzrDir.create_standalone_workingtree('grandparent')
39
45
        """Parent location is used as a basis by default"""
40
46
        self.make_trees()
41
47
        os.chdir('grandparent')
42
 
        errmsg = self.run_bzr('bundle', retcode=3)[1]
43
 
        self.assertContainsRe(errmsg, 'No base branch known or specified')
 
48
        errmsg = self.run_bzr('submit', retcode=3)[1]
 
49
        self.assertContainsRe(errmsg, 'No submit branch known or specified')
44
50
        os.chdir('../branch')
45
 
        stdout, stderr = self.run_bzr('bundle')
 
51
        stdout, stderr = self.run_bzr('submit')
46
52
        self.assertEqual(stderr.count('Using saved location'), 1)
47
53
        br = read_bundle(StringIO(stdout))
48
54
        self.assertRevisions(br, ['revision3'])
49
55
 
50
56
    def assertRevisions(self, bi, expected):
51
 
        self.assertEqual([r.revision_id for r in bi.revisions], expected)
 
57
        self.assertEqual(set(r.revision_id for r in bi.revisions),
 
58
            set(expected))
52
59
 
53
60
    def test_uses_submit(self):
54
61
        """Submit location can be used and set"""
55
62
        self.make_trees()
56
63
        os.chdir('branch')
57
 
        br = read_bundle(StringIO(self.run_bzr('bundle')[0]))
 
64
        br = read_bundle(StringIO(self.run_bzr('submit')[0]))
58
65
        self.assertRevisions(br, ['revision3'])
59
 
        br = read_bundle(StringIO(self.run_bzr('bundle ../grandparent')[0]))
 
66
        br = read_bundle(StringIO(self.run_bzr('submit ../grandparent')[0]))
60
67
        self.assertRevisions(br, ['revision3', 'revision2'])
61
68
        # submit location should be auto-remembered
62
 
        br = read_bundle(StringIO(self.run_bzr('bundle')[0]))
63
 
        self.assertRevisions(br, ['revision3', 'revision2'])
64
 
        self.run_bzr('bundle ../parent')
65
 
        br = read_bundle(StringIO(self.run_bzr('bundle')[0]))
66
 
        self.assertRevisions(br, ['revision3', 'revision2'])
67
 
        self.run_bzr('bundle ../parent --remember')
 
69
        br = read_bundle(StringIO(self.run_bzr('submit')[0]))
 
70
        self.assertRevisions(br, ['revision3', 'revision2'])
 
71
        self.run_bzr('submit ../parent')
 
72
        br = read_bundle(StringIO(self.run_bzr('bundle')[0]))
 
73
        self.assertRevisions(br, ['revision3', 'revision2'])
 
74
        self.run_bzr('submit ../parent --remember')
68
75
        br = read_bundle(StringIO(self.run_bzr('bundle')[0]))
69
76
        self.assertRevisions(br, ['revision3'])
70
 
        err = self.run_bzr('bundle --remember', retcode=3)[1]
71
 
        self.assertContainsRe(err,
 
77
        err = self.run_bzr('submit --remember', retcode=3)[1]
 
78
        self.assertContainsRe(err, 
72
79
                              '--remember requires a branch to be specified.')
73
80
 
74
81
    def test_revision_branch_interaction(self):
76
83
        os.chdir('branch')
77
84
        bi = read_bundle(StringIO(self.run_bzr('bundle ../grandparent')[0]))
78
85
        self.assertRevisions(bi, ['revision3', 'revision2'])
79
 
        out = StringIO(self.run_bzr('bundle ../grandparent -r -2')[0])
 
86
        out = StringIO(self.run_bzr('submit ../grandparent -r -2')[0])
80
87
        bi = read_bundle(out)
81
88
        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)
 
89
        sio = StringIO(self.run_bzr('submit -r -2..-1')[0])
 
90
        md = merge_directive.MergeDirective.from_lines(sio.readlines())
 
91
        self.assertEqual('revision2', md.base_revision_id)
 
92
        self.assertEqual('revision3', md.revision_id)
 
93
        sio.seek(0)
 
94
        bi = read_bundle(sio)
 
95
        self.assertRevisions(bi, ['revision2', 'revision3'])
 
96
        self.run_bzr('submit ../grandparent -r -2..-1')
85
97
 
86
98
    def test_output(self):
87
99
        # check output for consistency
88
100
        # win32 stdout converts LF to CRLF,
89
 
        # and this is breaks the created bundle
90
 
        self.make_trees()
 
101
        # which would break patch-based bundles
 
102
        self.make_trees()        
91
103
        os.chdir('branch')
92
 
        stdout = self.run_bzr_subprocess('bundle')[0]
 
104
        stdout = self.run_bzr_subprocess('submit')[0]
93
105
        br = read_bundle(StringIO(stdout))
94
106
        self.assertRevisions(br, ['revision3'])
95
107
 
96
108
    def test_no_common_ancestor(self):
97
109
        foo = self.make_branch_and_tree('foo')
 
110
        foo.commit('rev a')
98
111
        bar = self.make_branch_and_tree('bar')
 
112
        bar.commit('rev b')
99
113
        os.chdir('foo')
100
 
        self.run_bzr('bundle ../bar')
 
114
        self.run_bzr('submit ../bar')
 
115
 
 
116
    def submit_directive(self, args):
 
117
        sio = StringIO(self.run_bzr(['submit'] + args)[0])
 
118
        return merge_directive.MergeDirective.from_lines(sio.readlines())
 
119
 
 
120
    def test_content_options(self):
 
121
        """--no-patch and --no-bundle should work and be independant"""
 
122
        self.make_trees()
 
123
        os.chdir('branch')
 
124
        md = self.submit_directive([])
 
125
        self.assertIsNot(None, md.bundle)
 
126
        self.assertIsNot(None, md.patch)
 
127
        md = self.submit_directive(['--no-patch'])
 
128
        self.assertIsNot(None, md.bundle)
 
129
        self.assertIs(None, md.patch)
 
130
        md = self.submit_directive(['--no-bundle', '.', '.'])
 
131
        self.assertIs(None, md.bundle)
 
132
        self.assertIsNot(None, md.patch)
 
133
        md = self.submit_directive(['--no-bundle', '--no-patch', '.', '.'])
 
134
        self.assertIs(None, md.bundle)
 
135
        self.assertIs(None, md.patch)
 
136
 
 
137
    def test_from_option(self):
 
138
        self.make_trees()
 
139
        self.run_bzr('submit', retcode=3)
 
140
        md = self.submit_directive(['--from', 'branch'])
 
141
        self.assertEqual('revision3', md.revision_id)
 
142
        md = self.submit_directive(['-f', 'branch'])
 
143
        self.assertEqual('revision3', md.revision_id)
 
144
 
 
145
    def test_output_option(self):
 
146
        self.make_trees()
 
147
        stdout = self.run_bzr('submit -f branch --output file1')[0]
 
148
        self.assertEqual('', stdout)
 
149
        md_file = open('file1', 'rb')
 
150
        self.addCleanup(md_file.close)
 
151
        self.assertContainsRe(md_file.read(), 'revision3')
 
152