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):
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')
246
258
self.assertEqual('1', inv['file1id'].revision)
247
259
# FIXME: This should raise a KeyError I think, rbc20051006
248
260
self.assertRaises(BzrError, inv.__getitem__, 'file2id')
262
def test_strict_commit(self):
263
"""Try and commit with unknown files and strict = True, should fail."""
264
from bzrlib.errors import StrictCommitFailed
265
b = Branch.initialize('.')
266
file('hello', 'w').write('hello world')
268
file('goodbye', 'w').write('goodbye cruel world!')
269
self.assertRaises(StrictCommitFailed, b.commit,
270
message='add hello but not goodbye', strict=True)
272
def test_nonstrict_commit(self):
273
"""Try and commit with unknown files and strict = False, should work."""
274
b = Branch.initialize('.')
275
file('hello', 'w').write('hello world')
277
file('goodbye', 'w').write('goodbye cruel world!')
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