Merge pull request #5264 from henkesn/refs-unlock-on-commit refs: unlock unmodified refs on transaction commit
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
diff --git a/src/transaction.c b/src/transaction.c
index 5dd7f42..7367d12 100644
--- a/src/transaction.c
+++ b/src/transaction.c
@@ -334,7 +334,13 @@ int git_transaction_commit(git_transaction *tx)
return error;
}
- if (node->ref_type != GIT_REFERENCE_INVALID) {
+ if (node->ref_type == GIT_REFERENCE_INVALID) {
+ /* ref was locked but not modified */
+ if ((error = git_refdb_unlock(tx->db, node->payload, false, false, NULL, NULL, NULL)) < 0) {
+ return error;
+ }
+ node->committed = true;
+ } else {
if ((error = update_target(tx->db, node)) < 0)
return error;
}
diff --git a/tests/refs/transactions.c b/tests/refs/transactions.c
index d4ddf45..50c102a 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"));
+}