summaryrefslogtreecommitdiff
path: root/tests/refs/transactions.c
diff options
context:
space:
mode:
authorSebastian Henke <s.henke@henke-informatik.de>2019-10-11 12:44:09 +0200
committerSebastian Henke <s.henke@henke-informatik.de>2019-10-17 13:25:36 +0200
commit47531f47334d8b14f6f3ad30a780565c657e4698 (patch)
tree1c3f754e03c9b2f68e01094c7482d74f9289fe1a /tests/refs/transactions.c
parentef5a3851fdece852569ffebf3537883223744a7a (diff)
downloadlibgit2-47531f47334d8b14f6f3ad30a780565c657e4698.tar.gz
refs: unlock unmodified refs on transaction commit
Refs which are locked in a transaction without an altered target, still should to be unlocked on `git_transaction_commit`. `git_transaction_free` also unlocks refs but the moment of calling of `git_transaction_free` cannot be controlled in all situations. Some binding libs call `git_transaction_free` on garbage collection or not at all if the application exits before and don't provide public access to `git_transaction_free`. It is better to release locks as soon as possible.
Diffstat (limited to 'tests/refs/transactions.c')
-rw-r--r--tests/refs/transactions.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/refs/transactions.c b/tests/refs/transactions.c
index d4ddf459f..50c102ad0 100644
--- a/tests/refs/transactions.c
+++ b/tests/refs/transactions.c
@@ -129,3 +129,29 @@ void test_refs_transactions__error_on_locking_locked_ref(void)
git_transaction_free(g_tx_with_lock);
git_repository_free(g_repo_with_locking_tx);
}
+
+void test_refs_transactions__commit_unlocks_unmodified_ref(void)
+{
+ git_transaction *second_tx;
+
+ cl_git_pass(git_transaction_new(&second_tx, g_repo));
+ cl_git_pass(git_transaction_lock_ref(second_tx, "refs/heads/master"));
+ cl_git_pass(git_transaction_commit(second_tx));
+
+ /* a transaction must now be able to get the lock */
+ cl_git_pass(git_transaction_lock_ref(g_tx, "refs/heads/master"));
+
+ git_transaction_free(second_tx);
+}
+
+void test_refs_transactions__free_unlocks_unmodified_ref(void)
+{
+ git_transaction *second_tx;
+
+ cl_git_pass(git_transaction_new(&second_tx, g_repo));
+ cl_git_pass(git_transaction_lock_ref(second_tx, "refs/heads/master"));
+ git_transaction_free(second_tx);
+
+ /* a transaction must now be able to get the lock */
+ cl_git_pass(git_transaction_lock_ref(g_tx, "refs/heads/master"));
+}