Skip to content

Commit e43a6fd

Browse files
moygitster
authored andcommitted
More friendly message when locking the index fails.
Just saying that index.lock exists doesn't tell the user _what_ to do to fix the problem. We should give an indication that it's normally safe to delete index.lock after making sure git isn't running here. Signed-off-by: Matthieu Moy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b452cc1 commit e43a6fd

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

builtin-update-index.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -742,8 +742,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
742742
if (newfd < 0) {
743743
if (refresh_flags & REFRESH_QUIET)
744744
exit(128);
745-
die("unable to create '%s.lock': %s",
746-
get_index_file(), strerror(lock_error));
745+
unable_to_lock_index_die(get_index_file(), lock_error);
747746
}
748747
if (write_cache(newfd, active_cache, active_nr) ||
749748
commit_locked_index(lock_file))

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ struct lock_file {
484484
};
485485
#define LOCK_DIE_ON_ERROR 1
486486
#define LOCK_NODEREF 2
487+
extern NORETURN void unable_to_lock_index_die(const char *path, int err);
487488
extern int hold_lock_file_for_update(struct lock_file *, const char *path, int);
488489
extern int hold_lock_file_for_append(struct lock_file *, const char *path, int);
489490
extern int commit_lock_file(struct lock_file *);

lockfile.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,25 @@ static int lock_file(struct lock_file *lk, const char *path, int flags)
158158
return lk->fd;
159159
}
160160

161+
162+
NORETURN void unable_to_lock_index_die(const char *path, int err)
163+
{
164+
if (errno == EEXIST) {
165+
die("Unable to create '%s.lock': %s.\n\n"
166+
"If no other git process is currently running, this probably means a\n"
167+
"git process crashed in this repository earlier. Make sure no other git\n"
168+
"process is running and remove the file manually to continue.",
169+
path, strerror(err));
170+
} else {
171+
die("Unable to create '%s.lock': %s", path, strerror(err));
172+
}
173+
}
174+
161175
int hold_lock_file_for_update(struct lock_file *lk, const char *path, int flags)
162176
{
163177
int fd = lock_file(lk, path, flags);
164178
if (fd < 0 && (flags & LOCK_DIE_ON_ERROR))
165-
die("unable to create '%s.lock': %s", path, strerror(errno));
179+
unable_to_lock_index_die(path, errno);
166180
return fd;
167181
}
168182

0 commit comments

Comments
 (0)