MCPcopy Create free account
hub / github.com/libgit2/pygit2 / test_transaction_rollback_on_exception

Function test_transaction_rollback_on_exception

test/test_transaction.py:51–67  ·  view source on GitHub ↗

Test that transaction rolls back when exception is raised.

(testrepo: Repository)

Source from the content-addressed store, hash-verified

49
50
51def test_transaction_rollback_on_exception(testrepo: Repository) -> None:
52 """Test that transaction rolls back when exception is raised."""
53 master_ref = testrepo.lookup_reference('refs/heads/master')
54 original_target = master_ref.target
55
56 new_target = Oid(hex='5ebeeebb320790caf276b9fc8b24546d63316533')
57
58 # Transaction should not commit if exception is raised
59 with pytest.raises(RuntimeError):
60 with testrepo.transaction() as txn:
61 txn.lock_ref('refs/heads/master')
62 txn.set_target('refs/heads/master', new_target, message='Test update')
63 raise RuntimeError('Abort transaction')
64
65 # Verify the update was NOT applied
66 master_ref = testrepo.lookup_reference('refs/heads/master')
67 assert master_ref.target == original_target
68
69
70def test_transaction_multiple_refs(testrepo: Repository) -> None:

Callers

nothing calls this directly

Calls 3

transactionMethod · 0.80
lock_refMethod · 0.80
set_targetMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…