21
20
from bzrlib.selftest import TestCaseInTempDir
22
21
from bzrlib.branch import Branch
23
from bzrlib.workingtree import WorkingTree
24
22
from bzrlib.commit import Commit
25
23
from bzrlib.config import BranchConfig
26
from bzrlib.errors import PointlessCommit, BzrError, SigningFailed
24
from bzrlib.errors import PointlessCommit, BzrError
29
27
# TODO: Test commit with some added, and added-but-missing files
223
215
def test_removed_commit(self):
224
"""Commit with a removed file"""
216
"""Test a commit with a removed file"""
225
217
b = Branch.initialize('.')
226
wt = b.working_tree()
227
218
file('hello', 'w').write('hello world')
228
219
b.add(['hello'], ['hello-id'])
229
220
b.commit(message='add hello')
231
wt = b.working_tree() # FIXME: kludge for aliasing of working inventory
233
223
b.commit('removed hello', rev_id='rev2')
235
225
tree = b.revision_tree('rev2')
266
256
# FIXME: This should raise a KeyError I think, rbc20051006
267
257
self.assertRaises(BzrError, inv.__getitem__, 'file2id')
269
def test_strict_commit(self):
270
"""Try and commit with unknown files and strict = True, should fail."""
271
from bzrlib.errors import StrictCommitFailed
272
b = Branch.initialize('.')
273
file('hello', 'w').write('hello world')
275
file('goodbye', 'w').write('goodbye cruel world!')
276
self.assertRaises(StrictCommitFailed, b.commit,
277
message='add hello but not goodbye', strict=True)
279
def test_strict_commit_without_unknowns(self):
280
"""Try and commit with no unknown files and strict = True,
282
from bzrlib.errors import StrictCommitFailed
283
b = Branch.initialize('.')
284
file('hello', 'w').write('hello world')
286
b.commit(message='add hello', strict=True)
288
def test_nonstrict_commit(self):
289
"""Try and commit with unknown files and strict = False, should work."""
290
b = Branch.initialize('.')
291
file('hello', 'w').write('hello world')
293
file('goodbye', 'w').write('goodbye cruel world!')
294
b.commit(message='add hello but not goodbye', strict=False)
296
def test_nonstrict_commit_without_unknowns(self):
297
"""Try and commit with no unknown files and strict = False,
299
b = Branch.initialize('.')
300
file('hello', 'w').write('hello world')
302
b.commit(message='add hello', strict=False)
304
259
def test_signed_commit(self):
305
260
import bzrlib.gpg
306
261
import bzrlib.commit as commit
319
274
branch.revision_store.get('B', 'sig').read())
321
276
bzrlib.gpg.GPGStrategy = oldstrategy
323
def test_commit_failed_signature(self):
325
import bzrlib.commit as commit
326
oldstrategy = bzrlib.gpg.GPGStrategy
327
branch = Branch.initialize('.')
328
branch.commit("base", allow_pointless=True, rev_id='A')
329
self.failIf(branch.revision_store.has_id('A', 'sig'))
331
from bzrlib.testament import Testament
332
# monkey patch gpg signing mechanism
333
bzrlib.gpg.GPGStrategy = bzrlib.gpg.DisabledGPGStrategy
334
config = MustSignConfig(branch)
335
self.assertRaises(SigningFailed,
336
commit.Commit(config=config).commit,
338
allow_pointless=True,
340
branch = Branch.open('.')
341
self.assertEqual(branch.revision_history(), ['A'])
342
self.failIf(branch.revision_store.has_id('B'))
344
bzrlib.gpg.GPGStrategy = oldstrategy
346
def test_commit_invokes_hooks(self):
347
import bzrlib.commit as commit
348
branch = Branch.initialize('.')
350
def called(branch, rev_id):
351
calls.append('called')
352
bzrlib.ahook = called
354
config = BranchWithHooks(branch)
355
commit.Commit(config=config).commit(
357
allow_pointless=True,
359
self.assertEqual(['called', 'called'], calls)