~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

Merge from bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
import os
18
18
import smtplib
19
19
 
20
 
from bzrlib import gpg, tests
 
20
from bzrlib import (
 
21
    gpg,
 
22
    tests,
 
23
    workingtree,
 
24
    )
21
25
 
22
26
 
23
27
EMAIL1 = """To: pqm@example.com
25
29
Subject: bar
26
30
 
27
31
# Bazaar merge directive format 1
28
 
# revision_id: jrandom@example.com-.*
 
32
# revision_id: bar-id
29
33
# target_branch: ../tree2
30
34
# testament_sha1: .*
31
35
# timestamp: .*
36
40
class TestMergeDirective(tests.TestCaseWithTransport):
37
41
 
38
42
    def prepare_merge_directive(self):
39
 
        tree1 = self.make_branch_and_tree('tree1')
 
43
        self.tree1 = self.make_branch_and_tree('tree1')
40
44
        self.build_tree_contents([('tree1/file', 'a\nb\nc\nd\n')])
41
 
        tree1.branch.get_config().set_user_option('email',
 
45
        self.tree1.branch.get_config().set_user_option('email',
42
46
            'J. Random Hacker <jrandom@example.com>')
43
 
        tree1.add('file')
44
 
        tree1.commit('foo')
45
 
        tree2=tree1.bzrdir.sprout('tree2').open_workingtree()
 
47
        self.tree1.add('file')
 
48
        self.tree1.commit('foo')
 
49
        self.tree2 = self.tree1.bzrdir.sprout('tree2').open_workingtree()
46
50
        self.build_tree_contents([('tree1/file', 'a\nb\nc\nd\ne\n')])
47
 
        tree1.commit('bar')
 
51
        self.tree1.commit('bar', rev_id='bar-id')
48
52
        os.chdir('tree1')
49
 
        return tree1, tree2
 
53
        return self.tree1, self.tree2
50
54
 
51
55
    def test_merge_directive(self):
52
56
        self.prepare_merge_directive()
132
136
                          'pqm@example.com'), call[1:3])
133
137
        self.assertContainsRe(call[3], EMAIL1)
134
138
 
 
139
    def test_pull_raw(self):
 
140
        self.prepare_merge_directive()
 
141
        self.tree1.commit('baz', rev_id='baz-id')
 
142
        md_text = self.run_bzr('merge-directive', self.tree2.basedir,
 
143
                               '-r', '2', self.tree1.basedir, '--plain')[0]
 
144
        self.build_tree_contents([('../directive', md_text)])
 
145
        os.chdir('../tree2')
 
146
        self.run_bzr('pull', '../directive')
 
147
        wt = workingtree.WorkingTree.open('.')
 
148
        self.assertEqual('bar-id', wt.last_revision())
 
149
 
 
150
    def test_pull_user_r(self):
 
151
        """If the user supplies -r, an error is emitted"""
 
152
        self.prepare_merge_directive()
 
153
        self.tree1.commit('baz', rev_id='baz-id')
 
154
        md_text = self.run_bzr('merge-directive', self.tree2.basedir,
 
155
                               self.tree1.basedir, '--plain')[0]
 
156
        self.build_tree_contents([('../directive', md_text)])
 
157
        os.chdir('../tree2')
 
158
        self.run_bzr_error(
 
159
            ('Cannot use -r with merge directives or bundles',),
 
160
            'pull', '-r', '2', '../directive')
 
161
 
 
162
    def test_pull_bundle(self):
 
163
        self.prepare_merge_directive()
 
164
        self.tree1.commit('baz', rev_id='baz-id')
 
165
        md_text = self.run_bzr('merge-directive', self.tree2.basedir,
 
166
                               '-r', '2', '/dev/null', '--bundle')[0]
 
167
        self.build_tree_contents([('../directive', md_text)])
 
168
        os.chdir('../tree2')
 
169
        self.run_bzr('pull', '../directive')
 
170
        wt = workingtree.WorkingTree.open('.')
 
171
        self.assertEqual('bar-id', wt.last_revision())
 
172
 
 
173
    def test_merge_raw(self):
 
174
        self.prepare_merge_directive()
 
175
        self.tree1.commit('baz', rev_id='baz-id')
 
176
        md_text = self.run_bzr('merge-directive', self.tree2.basedir,
 
177
                               '-r', '2', self.tree1.basedir, '--plain')[0]
 
178
        self.build_tree_contents([('../directive', md_text)])
 
179
        os.chdir('../tree2')
 
180
        self.run_bzr('merge', '../directive')
 
181
        wt = workingtree.WorkingTree.open('.')
 
182
        self.assertEqual('bar-id', wt.get_parent_ids()[1])
 
183
 
 
184
    def test_merge_user_r(self):
 
185
        """If the user supplies -r, an error is emitted"""
 
186
        self.prepare_merge_directive()
 
187
        self.tree1.commit('baz', rev_id='baz-id')
 
188
        md_text = self.run_bzr('merge-directive', self.tree2.basedir,
 
189
                               self.tree1.basedir, '--plain')[0]
 
190
        self.build_tree_contents([('../directive', md_text)])
 
191
        os.chdir('../tree2')
 
192
        self.run_bzr_error(
 
193
            ('Cannot use -r with merge directives or bundles',),
 
194
            'merge', '-r', '2', '../directive')
 
195
 
 
196
    def test_merge_bundle(self):
 
197
        self.prepare_merge_directive()
 
198
        self.tree1.commit('baz', rev_id='baz-id')
 
199
        md_text = self.run_bzr('merge-directive', self.tree2.basedir,
 
200
                               '-r', '2', '/dev/null', '--bundle')[0]
 
201
        self.build_tree_contents([('../directive', md_text)])
 
202
        os.chdir('../tree2')
 
203
        self.run_bzr('merge', '../directive')
 
204
        wt = workingtree.WorkingTree.open('.')
 
205
        self.assertEqual('bar-id', wt.get_parent_ids()[1])
 
206
 
135
207
    def test_mail_uses_config(self):
136
208
        tree1, tree2 = self.prepare_merge_directive()
137
209
        tree1.branch.get_config().set_user_option('smtp_server', 'bogushost')