~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/test_commit.py

- constraints on revprops
- tests for this

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
 
from bzrlib.config import BranchConfig
26
 
from bzrlib.errors import PointlessCommit, BzrError, SigningFailed
 
23
from bzrlib.errors import PointlessCommit, BzrError
27
24
 
28
25
 
29
26
# TODO: Test commit with some added, and added-but-missing files
30
27
 
31
 
class MustSignConfig(BranchConfig):
32
 
 
33
 
    def signature_needed(self):
34
 
        return True
35
 
 
36
 
    def gpg_signing_command(self):
37
 
        return ['cat', '-']
38
 
 
39
 
 
40
 
class BranchWithHooks(BranchConfig):
41
 
 
42
 
    def post_commit(self):
43
 
        return "bzrlib.ahook bzrlib.ahook"
44
 
 
45
 
 
46
28
class TestCommit(TestCaseInTempDir):
47
29
 
48
30
    def test_simple_commit(self):
69
51
        tree2 = b.revision_tree(rh[1])
70
52
        eq(tree2.get_file_text(file_id), 'version 2')
71
53
 
 
54
 
72
55
    def test_delete_commit(self):
73
56
        """Test a commit with a deleted file"""
74
57
        b = Branch.initialize('.')
196
179
        b.move(['hello'], 'a')
197
180
        r2 = 'test@rev-2'
198
181
        b.commit('two', rev_id=r2, allow_pointless=False)
199
 
        self.check_inventory_shape(b.working_tree().read_working_inventory(),
 
182
        self.check_inventory_shape(b.inventory,
200
183
                                   ['a', 'a/hello', 'b'])
201
184
 
202
185
        b.move(['b'], 'a')
203
186
        r3 = 'test@rev-3'
204
187
        b.commit('three', rev_id=r3, allow_pointless=False)
205
 
        self.check_inventory_shape(b.working_tree().read_working_inventory(),
 
188
        self.check_inventory_shape(b.inventory,
206
189
                                   ['a', 'a/hello', 'a/b'])
207
190
        self.check_inventory_shape(b.get_revision_inventory(r3),
208
191
                                   ['a', 'a/hello', 'a/b'])
211
194
               os.sep.join(['a', 'b']))
212
195
        r4 = 'test@rev-4'
213
196
        b.commit('four', rev_id=r4, allow_pointless=False)
214
 
        self.check_inventory_shape(b.working_tree().read_working_inventory(),
 
197
        self.check_inventory_shape(b.inventory,
215
198
                                   ['a', 'a/b/hello', 'a/b'])
216
199
 
217
200
        inv = b.get_revision_inventory(r4)
221
204
 
222
205
        
223
206
    def test_removed_commit(self):
224
 
        """Commit with a removed file"""
 
207
        """Test a commit with a removed file"""
225
208
        b = Branch.initialize('.')
226
 
        wt = b.working_tree()
227
209
        file('hello', 'w').write('hello world')
228
210
        b.add(['hello'], ['hello-id'])
229
211
        b.commit(message='add hello')
230
212
 
231
 
        wt = b.working_tree()  # FIXME: kludge for aliasing of working inventory
232
 
        wt.remove('hello')
 
213
        b.remove('hello')
233
214
        b.commit('removed hello', rev_id='rev2')
234
215
 
235
216
        tree = b.revision_tree('rev2')
265
246
        self.assertEqual('1', inv['file1id'].revision)
266
247
        # FIXME: This should raise a KeyError I think, rbc20051006
267
248
        self.assertRaises(BzrError, inv.__getitem__, 'file2id')
268
 
 
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
 
    def test_signed_commit(self):
305
 
        import bzrlib.gpg
306
 
        import bzrlib.commit as commit
307
 
        oldstrategy = bzrlib.gpg.GPGStrategy
308
 
        branch = Branch.initialize('.')
309
 
        branch.commit("base", allow_pointless=True, rev_id='A')
310
 
        self.failIf(branch.revision_store.has_id('A', 'sig'))
311
 
        try:
312
 
            from bzrlib.testament import Testament
313
 
            # monkey patch gpg signing mechanism
314
 
            bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
315
 
            commit.Commit(config=MustSignConfig(branch)).commit(branch, "base",
316
 
                                                      allow_pointless=True,
317
 
                                                      rev_id='B')
318
 
            self.assertEqual(Testament.from_revision(branch,'B').as_short_text(),
319
 
                             branch.revision_store.get('B', 'sig').read())
320
 
        finally:
321
 
            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