~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/test_commit.py

[merge] from robert and fix up tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
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
24
26
 
25
27
 
26
28
# TODO: Test commit with some added, and added-but-missing files
27
29
 
 
30
class MustSignConfig(BranchConfig):
 
31
 
 
32
    def signature_needed(self):
 
33
        return True
 
34
 
 
35
    def gpg_signing_command(self):
 
36
        return ['cat', '-']
 
37
 
 
38
 
28
39
class TestCommit(TestCaseInTempDir):
29
40
 
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')
53
64
 
54
 
 
55
65
    def test_delete_commit(self):
56
66
        """Test a commit with a deleted file"""
57
67
        b = Branch.initialize('.')
204
214
 
205
215
        
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')
212
223
 
213
 
        b.remove('hello')
 
224
        wt = b.working_tree()  # FIXME: kludge for aliasing of working inventory
 
225
        wt.remove('hello')
214
226
        b.commit('removed hello', rev_id='rev2')
215
227
 
216
228
        tree = b.revision_tree('rev2')
264
276
        b.add('hello')
265
277
        file('goodbye', 'w').write('goodbye cruel world!')
266
278
        b.commit(message='add hello but not goodbye', strict=False)
 
279
 
 
280
    def test_signed_commit(self):
 
281
        import bzrlib.gpg
 
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'))
 
287
        try:
 
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,
 
293
                                                      rev_id='B')
 
294
            self.assertEqual(Testament.from_revision(branch,'B').as_short_text(),
 
295
                             branch.revision_store.get('B', 'sig').read())
 
296
        finally:
 
297
            bzrlib.gpg.GPGStrategy = oldstrategy
 
298
 
 
299
    def test_commit_failed_signature(self):
 
300
        import bzrlib.gpg
 
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'))
 
306
        try:
 
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,
 
313
                              branch, "base",
 
314
                              allow_pointless=True,
 
315
                              rev_id='B')
 
316
            branch = Branch.open('.')
 
317
            self.assertEqual(branch.revision_history(), ['A'])
 
318
            self.failIf(branch.revision_store.has_id('B'))
 
319
        finally:
 
320
            bzrlib.gpg.GPGStrategy = oldstrategy