diff options
| author | Junio C Hamano <gitster@pobox.com> | 2024-12-04 10:14:37 +0900 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2024-12-04 10:14:37 +0900 |
| commit | 2f605347da0f6859175d6110cfd49b2d8937dea4 (patch) | |
| tree | 8c691ef0b9be969be1677fed60f2be507e73c308 | |
| parent | cc01bad4a9f566cf4453c7edd6b433851b0835e2 (diff) | |
| parent | ba874d1dac4b4284b98132ce727b29325202c798 (diff) | |
| download | git-2f605347da0f6859175d6110cfd49b2d8937dea4.tar.gz | |
Merge branch 'ps/gc-stale-lock-warning'
Give a bit of advice/hint message when "git maintenance" stops finding a
lock file left by another instance that still is potentially running.
* ps/gc-stale-lock-warning:
t7900: fix host-dependent behaviour when testing git-maintenance(1)
builtin/gc: provide hint when maintenance hits a stale schedule lock
| -rw-r--r-- | builtin/gc.c | 11 | ||||
| -rwxr-xr-x | t/t7900-maintenance.sh | 13 |
2 files changed, 23 insertions, 1 deletions
diff --git a/builtin/gc.c b/builtin/gc.c index d52735354c..34848626e4 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -2890,8 +2890,17 @@ static int update_background_schedule(const struct maintenance_start_opts *opts, char *lock_path = xstrfmt("%s/schedule", the_repository->objects->odb->path); if (hold_lock_file_for_update(&lk, lock_path, LOCK_NO_DEREF) < 0) { + if (errno == EEXIST) + error(_("unable to create '%s.lock': %s.\n\n" + "Another scheduled git-maintenance(1) process seems to be running in this\n" + "repository. Please make sure no other maintenance processes are running and\n" + "then try again. If it still fails, a git-maintenance(1) process may have\n" + "crashed in this repository earlier: remove the file manually to continue."), + absolute_path(lock_path), strerror(errno)); + else + error_errno(_("cannot acquire lock for scheduled background maintenance")); free(lock_path); - return error(_("another process is scheduling background maintenance")); + return -1; } for (i = 1; i < ARRAY_SIZE(scheduler_fn); i++) { diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh index c224c8450c..4bbc171958 100755 --- a/t/t7900-maintenance.sh +++ b/t/t7900-maintenance.sh @@ -1011,4 +1011,17 @@ test_expect_success 'repacking loose objects is quiet' ' ) ' +test_expect_success 'maintenance aborts with existing lock file' ' + test_when_finished "rm -rf repo script" && + mkdir script && + write_script script/systemctl <<-\EOF && + true + EOF + + git init repo && + : >repo/.git/objects/schedule.lock && + test_must_fail env PATH="$PWD/script:$PATH" git -C repo maintenance start --scheduler=systemd 2>err && + test_grep "Another scheduled git-maintenance(1) process seems to be running" err +' + test_done |
