1
# Copyright (C) 2007 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
from bzrlib import gpg, tests
23
EMAIL1 = """To: pqm@example.com
24
From: J. Random Hacker <jrandom@example.com>
27
# Bazaar merge directive format 1
28
# revision_id: jrandom@example.com-.*
29
# target_branch: ../tree2
36
class TestMergeDirective(tests.TestCaseWithTransport):
38
def prepare_merge_directive(self):
39
tree1 = self.make_branch_and_tree('tree1')
40
self.build_tree_contents([('tree1/file', 'a\nb\nc\nd\n')])
41
tree1.branch.get_config().set_user_option('email',
42
'J. Random Hacker <jrandom@example.com>')
45
tree2=tree1.bzrdir.sprout('tree2').open_workingtree()
46
self.build_tree_contents([('tree1/file', 'a\nb\nc\nd\ne\n')])
50
def test_merge_directive(self):
51
self.prepare_merge_directive()
52
md_text = self.run_bzr('merge-directive', '../tree2')[0]
53
self.assertContainsRe(md_text, "\\+e")
54
md_text = self.run_bzr('merge-directive', '-r', '-2', '../tree2')[0]
55
self.assertNotContainsRe(md_text, "\\+e")
57
def test_submit_branch(self):
58
self.prepare_merge_directive()
59
self.run_bzr_error(('No submit branch',), 'merge-directive', retcode=3)
60
self.run_bzr('merge-directive', '../tree2')
62
def test_public_branch(self):
63
self.prepare_merge_directive()
64
self.run_bzr_error(('No public branch',), 'merge-directive', '--diff',
65
'../tree2', retcode=3)
66
md_text = self.run_bzr('merge-directive', '../tree2')[0]
67
self.assertNotContainsRe(md_text, 'source_branch:')
68
self.run_bzr('merge-directive', '--diff', '../tree2', '.')
69
self.run_bzr('merge-directive', '--diff')[0]
70
self.assertNotContainsRe(md_text, 'source_branch:')
72
def test_patch_types(self):
73
self.prepare_merge_directive()
74
md_text = self.run_bzr('merge-directive', '../tree2')[0]
75
self.assertContainsRe(md_text, "Bazaar revision bundle")
76
self.assertContainsRe(md_text, "\\+e")
77
md_text = self.run_bzr('merge-directive', '../tree2', '--diff', '.')[0]
78
self.assertNotContainsRe(md_text, "Bazaar revision bundle")
79
self.assertContainsRe(md_text, "\\+e")
80
md_text = self.run_bzr('merge-directive', '--plain')[0]
81
self.assertNotContainsRe(md_text, "\\+e")
83
def test_message(self):
84
self.prepare_merge_directive()
85
md_text = self.run_bzr('merge-directive', '../tree2')[0]
86
self.assertNotContainsRe(md_text, 'message: Message for merge')
87
md_text = self.run_bzr('merge-directive', '-m', 'Message for merge')[0]
88
self.assertContainsRe(md_text, 'message: Message for merge')
90
def test_signing(self):
91
self.prepare_merge_directive()
92
old_strategy = gpg.GPGStrategy
93
gpg.GPGStrategy = gpg.LoopbackGPGStrategy
95
md_text = self.run_bzr('merge-directive', '--sign', '../tree2')[0]
97
gpg.GPGStrategy = old_strategy
98
self.assertContainsRe(md_text, '^-----BEGIN PSEUDO-SIGNED CONTENT')
101
self.prepare_merge_directive()
103
def sendmail(self, from_, to, message):
104
sendmail_calls.append((self, from_, to, message))
105
old_sendmail = smtplib.SMTP.sendmail
106
smtplib.SMTP.sendmail = sendmail
108
md_text = self.run_bzr('merge-directive', '--mail-to',
109
'pqm@example.com', '--plain', '../tree2',
112
smtplib.SMTP.sendmail = old_sendmail
113
self.assertEqual('', md_text)
114
self.assertEqual(1, len(sendmail_calls))
115
call = sendmail_calls[0]
116
self.assertEqual(('J. Random Hacker <jrandom@example.com>',
117
'pqm@example.com'), call[1:3])
118
self.assertContainsRe(call[3], EMAIL1)