~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/test_commit.py

  • Committer: Robert Collins
  • Date: 2005-10-17 11:56:54 UTC
  • mfrom: (1185.16.59)
  • Revision ID: robertc@robertcollins.net-20051017115654-662239e1587524a8
mergeĀ fromĀ martin.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
import os
19
19
 
20
 
import bzrlib
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
27
25
 
28
26
 
29
27
# TODO: Test commit with some added, and added-but-missing files
37
35
        return ['cat', '-']
38
36
 
39
37
 
40
 
class BranchWithHooks(BranchConfig):
41
 
 
42
 
    def post_commit(self):
43
 
        return "bzrlib.ahook bzrlib.ahook"
44
 
 
45
 
 
46
38
class TestCommit(TestCaseInTempDir):
47
39
 
48
40
    def test_simple_commit(self):
221
213
 
222
214
        
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')
230
221
 
231
 
        wt = b.working_tree()  # FIXME: kludge for aliasing of working inventory
232
 
        wt.remove('hello')
 
222
        b.remove('hello')
233
223
        b.commit('removed hello', rev_id='rev2')
234
224
 
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')
268
258
 
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')
274
 
        b.add('hello')
275
 
        file('goodbye', 'w').write('goodbye cruel world!')
276
 
        self.assertRaises(StrictCommitFailed, b.commit,
277
 
            message='add hello but not goodbye', strict=True)
278
 
 
279
 
    def test_strict_commit_without_unknowns(self):
280
 
        """Try and commit with no unknown files and strict = True,
281
 
        should work."""
282
 
        from bzrlib.errors import StrictCommitFailed
283
 
        b = Branch.initialize('.')
284
 
        file('hello', 'w').write('hello world')
285
 
        b.add('hello')
286
 
        b.commit(message='add hello', strict=True)
287
 
 
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')
292
 
        b.add('hello')
293
 
        file('goodbye', 'w').write('goodbye cruel world!')
294
 
        b.commit(message='add hello but not goodbye', strict=False)
295
 
 
296
 
    def test_nonstrict_commit_without_unknowns(self):
297
 
        """Try and commit with no unknown files and strict = False,
298
 
        should work."""
299
 
        b = Branch.initialize('.')
300
 
        file('hello', 'w').write('hello world')
301
 
        b.add('hello')
302
 
        b.commit(message='add hello', strict=False)
303
 
 
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())
320
275
        finally:
321
276
            bzrlib.gpg.GPGStrategy = oldstrategy
322
 
 
323
 
    def test_commit_failed_signature(self):
324
 
        import bzrlib.gpg
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'))
330
 
        try:
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,
337
 
                              branch, "base",
338
 
                              allow_pointless=True,
339
 
                              rev_id='B')
340
 
            branch = Branch.open('.')
341
 
            self.assertEqual(branch.revision_history(), ['A'])
342
 
            self.failIf(branch.revision_store.has_id('B'))
343
 
        finally:
344
 
            bzrlib.gpg.GPGStrategy = oldstrategy
345
 
 
346
 
    def test_commit_invokes_hooks(self):
347
 
        import bzrlib.commit as commit
348
 
        branch = Branch.initialize('.')
349
 
        calls = []
350
 
        def called(branch, rev_id):
351
 
            calls.append('called')
352
 
        bzrlib.ahook = called
353
 
        try:
354
 
            config = BranchWithHooks(branch)
355
 
            commit.Commit(config=config).commit(
356
 
                            branch, "base",
357
 
                            allow_pointless=True,
358
 
                            rev_id='A')
359
 
            self.assertEqual(['called', 'called'], calls)
360
 
        finally:
361
 
            del bzrlib.ahook