20
20
from bzrlib.selftest import TestCaseInTempDir
21
21
from bzrlib.branch import Branch
22
from bzrlib.workingtree import WorkingTree
22
23
from bzrlib.commit import Commit
23
from bzrlib.errors import PointlessCommit, BzrError
24
from bzrlib.config import BranchConfig
25
from bzrlib.errors import PointlessCommit, BzrError, SigningFailed
26
28
# TODO: Test commit with some added, and added-but-missing files
30
class MustSignConfig(BranchConfig):
32
def signature_needed(self):
35
def gpg_signing_command(self):
28
39
class TestCommit(TestCaseInTempDir):
30
41
def test_simple_commit(self):
51
62
tree2 = b.revision_tree(rh[1])
52
63
eq(tree2.get_file_text(file_id), 'version 2')
55
65
def test_delete_commit(self):
56
66
"""Test a commit with a deleted file"""
57
67
b = Branch.initialize('.')
206
216
def test_removed_commit(self):
207
"""Test a commit with a removed file"""
217
"""Commit with a removed file"""
208
218
b = Branch.initialize('.')
219
wt = b.working_tree()
209
220
file('hello', 'w').write('hello world')
210
221
b.add(['hello'], ['hello-id'])
211
222
b.commit(message='add hello')
224
wt = b.working_tree() # FIXME: kludge for aliasing of working inventory
214
226
b.commit('removed hello', rev_id='rev2')
216
228
tree = b.revision_tree('rev2')
265
277
file('goodbye', 'w').write('goodbye cruel world!')
266
278
b.commit(message='add hello but not goodbye', strict=False)
280
def test_signed_commit(self):
282
import bzrlib.commit as commit
283
oldstrategy = bzrlib.gpg.GPGStrategy
284
branch = Branch.initialize('.')
285
branch.commit("base", allow_pointless=True, rev_id='A')
286
self.failIf(branch.revision_store.has_id('A', 'sig'))
288
from bzrlib.testament import Testament
289
# monkey patch gpg signing mechanism
290
bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
291
commit.Commit(config=MustSignConfig(branch)).commit(branch, "base",
292
allow_pointless=True,
294
self.assertEqual(Testament.from_revision(branch,'B').as_short_text(),
295
branch.revision_store.get('B', 'sig').read())
297
bzrlib.gpg.GPGStrategy = oldstrategy
299
def test_commit_failed_signature(self):
301
import bzrlib.commit as commit
302
oldstrategy = bzrlib.gpg.GPGStrategy
303
branch = Branch.initialize('.')
304
branch.commit("base", allow_pointless=True, rev_id='A')
305
self.failIf(branch.revision_store.has_id('A', 'sig'))
307
from bzrlib.testament import Testament
308
# monkey patch gpg signing mechanism
309
bzrlib.gpg.GPGStrategy = bzrlib.gpg.DisabledGPGStrategy
310
config = MustSignConfig(branch)
311
self.assertRaises(SigningFailed,
312
commit.Commit(config=config).commit,
314
allow_pointless=True,
316
branch = Branch.open('.')
317
self.assertEqual(branch.revision_history(), ['A'])
318
self.failIf(branch.revision_store.has_id('B'))
320
bzrlib.gpg.GPGStrategy = oldstrategy