Skip to content

Commit 2f60534

Browse files
committed
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
2 parents cc01bad + ba874d1 commit 2f60534

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

builtin/gc.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2890,8 +2890,17 @@ static int update_background_schedule(const struct maintenance_start_opts *opts,
28902890
char *lock_path = xstrfmt("%s/schedule", the_repository->objects->odb->path);
28912891

28922892
if (hold_lock_file_for_update(&lk, lock_path, LOCK_NO_DEREF) < 0) {
2893+
if (errno == EEXIST)
2894+
error(_("unable to create '%s.lock': %s.\n\n"
2895+
"Another scheduled git-maintenance(1) process seems to be running in this\n"
2896+
"repository. Please make sure no other maintenance processes are running and\n"
2897+
"then try again. If it still fails, a git-maintenance(1) process may have\n"
2898+
"crashed in this repository earlier: remove the file manually to continue."),
2899+
absolute_path(lock_path), strerror(errno));
2900+
else
2901+
error_errno(_("cannot acquire lock for scheduled background maintenance"));
28932902
free(lock_path);
2894-
return error(_("another process is scheduling background maintenance"));
2903+
return -1;
28952904
}
28962905

28972906
for (i = 1; i < ARRAY_SIZE(scheduler_fn); i++) {

t/t7900-maintenance.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,4 +1011,17 @@ test_expect_success 'repacking loose objects is quiet' '
10111011
)
10121012
'
10131013

1014+
test_expect_success 'maintenance aborts with existing lock file' '
1015+
test_when_finished "rm -rf repo script" &&
1016+
mkdir script &&
1017+
write_script script/systemctl <<-\EOF &&
1018+
true
1019+
EOF
1020+
1021+
git init repo &&
1022+
: >repo/.git/objects/schedule.lock &&
1023+
test_must_fail env PATH="$PWD/script:$PATH" git -C repo maintenance start --scheduler=systemd 2>err &&
1024+
test_grep "Another scheduled git-maintenance(1) process seems to be running" err
1025+
'
1026+
10141027
test_done

0 commit comments

Comments
 (0)