Skip to content

Commit 1099c31

Browse files
committed
Merge branch 'ps/gc-stale-lock-warning' into next
Give a bit of advice/hint message when "git gc" stops finding a lock file left by another instance of "git gc" that still is potentially running. * ps/gc-stale-lock-warning: builtin/gc: provide hint when maintenance hits a stale schedule lock
2 parents 2339988 + 656ca92 commit 1099c31

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,4 +1011,12 @@ 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" &&
1016+
git init repo &&
1017+
: >repo/.git/objects/schedule.lock &&
1018+
test_must_fail git -C repo maintenance start 2>err &&
1019+
test_grep "Another scheduled git-maintenance(1) process seems to be running" err
1020+
'
1021+
10141022
test_done

0 commit comments

Comments
 (0)