aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--builtin/gc.c11
-rwxr-xr-xt/t7900-maintenance.sh8
2 files changed, 18 insertions, 1 deletions
diff --git a/builtin/gc.c b/builtin/gc.c
index 6a7a2da006..f78817a2fb 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -2887,8 +2887,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 a66d0e089d..ee803b35b4 100755
--- a/t/t7900-maintenance.sh
+++ b/t/t7900-maintenance.sh
@@ -995,4 +995,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