Skip to content

Commit

Permalink
Merge branch 'ps/gc-stale-lock-warning' into next
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gitster committed Nov 20, 2024
2 parents 2339988 + 656ca92 commit 1099c31
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
11 changes: 10 additions & 1 deletion builtin/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
8 changes: 8 additions & 0 deletions t/t7900-maintenance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1011,4 +1011,12 @@ test_expect_success 'repacking loose objects is quiet' '
)
'

test_expect_success 'maintenance aborts with existing lock file' '
test_when_finished "rm -rf repo" &&
git init repo &&
: >repo/.git/objects/schedule.lock &&
test_must_fail git -C repo maintenance start 2>err &&
test_grep "Another scheduled git-maintenance(1) process seems to be running" err
'

test_done

0 comments on commit 1099c31

Please sign in to comment.