[Outreachy PATCH] credential-store: add lockTimeout config option
- From
- Okhuomon Ajayi <okhuomonajayi54@gmail.com>
- Date
- Oct 14, 2026, 23:27 UTC
- Message-ID
- <20261014232739.23021-1-okhuomonajayi54@gmail.com>
- In-Reply-To
- <20261014155529.84134-1-okhuomonajayi54@gmail.com>
Support credentialStore.lockTimeout as the preferred setting for credential lock retries, retaining lockTimeoutMS as a deprecated alias.
Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com> --- Documentation/config/credential.adoc | 5 ++- builtin/credential-store.c | 4 +- t/t0302-credential-store.sh | 56 ++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 2 deletions(-)
diff --git a/Documentation/config/credential.adoc b/Documentation/config/credential.adoc index 80a7c77772..6fa40560be 100644 --- a/Documentation/config/credential.adoc +++ b/Documentation/config/credential.adoc @@ -48,8 +48,11 @@ credential.<url>.*:: credentialCache.ignoreSIGHUP:: Tell git-credential-cache--daemon to ignore SIGHUP, instead of quitting. -credentialStore.lockTimeoutMS:: +credentialStore.lockTimeout:: The length of time, in milliseconds, for git-credential-store to retry when trying to lock the credentials file. A value of 0 means not to retry at all; -1 means to try indefinitely. Default is 1000 (i.e., retry for 1s). + +credentialStore.lockTimeoutMS (deprecated):: + This is a deprecated synonym for `credentialStore.lockTimeout`. diff --git a/builtin/credential-store.c b/builtin/credential-store.c index bc1453c6b2..9fef54d218 100644 --- a/builtin/credential-store.c +++ b/builtin/credential-store.c @@ -67,7 +67,9 @@ static void rewrite_credential_file(const char *fn, struct credential *c, { int timeout_ms = 1000; - repo_config_get_int(the_repository, "credentialstore.locktimeoutms", &timeout_ms); + /* lockTimeoutMS is a deprecated synonym of lockTimeout. */ + if (repo_config_get_int(the_repository, "credentialstore.locktimeout", &timeout_ms)) + repo_config_get_int(the_repository, "credentialstore.locktimeoutms", &timeout_ms); if (hold_lock_file_for_update_timeout(&credential_lock, fn, 0, timeout_ms) < 0) die_errno(_("unable to get credential storage lock in %d ms"), timeout_ms); if (extra) diff --git a/t/t0302-credential-store.sh b/t/t0302-credential-store.sh index c1cd60edd0..408f26bb10 100755 --- a/t/t0302-credential-store.sh +++ b/t/t0302-credential-store.sh @@ -210,4 +210,60 @@ test_expect_success 'get: store file can contain empty/bogus lines' ' EOF ' +# Holding creds.lock makes the next store fail. The error reports the +# timeout that was actually used, so "in 0 ms" means that name won. +test_expect_success 'credentialStore.lockTimeoutMS=0 gives up immediately' ' + test_when_finished "rm -f creds creds.lock" && + >"creds.lock" && + test_must_fail git -c credentialStore.lockTimeoutMS=0 \ + credential-store --file=creds store 2>err <<-\EOF && + protocol=https + host=example.com + username=store-user + password=store-pass + EOF + test_grep "unable to get credential storage lock in 0 ms" err +' + +test_expect_success 'credentialStore.lockTimeout=0 gives up immediately' ' + test_when_finished "rm -f creds creds.lock" && + >"creds.lock" && + test_must_fail git -c credentialStore.lockTimeout=0 \ + credential-store --file=creds store 2>err <<-\EOF && + protocol=https + host=example.com + username=store-user + password=store-pass + EOF + test_grep "unable to get credential storage lock in 0 ms" err +' + +test_expect_success 'credentialStore.lockTimeout wins when both are set' ' + test_when_finished "rm -f creds creds.lock" && + >"creds.lock" && + test_must_fail git \ + -c credentialStore.lockTimeout=0 \ + -c credentialStore.lockTimeoutMS=500 \ + credential-store --file=creds store 2>err <<-\EOF && + protocol=https + host=example.com + username=store-user + password=store-pass + EOF + test_grep "unable to get credential storage lock in 0 ms" err +' + +test_expect_success 'credentialStore.lockTimeout allows a store' ' + test_when_finished "rm -f creds" && + git -c credentialStore.lockTimeout=1000 \ + credential-store --file=creds store <<-\EOF && + protocol=https + host=example.com + username=store-user + password=store-pass + EOF + echo "https://store-user:store-pass@example.com" >expect && + test_cmp expect creds +' + test_done
-- 2.54.0