@matheusbsbs / matheus-bagliano / commits / e43a6fd3e9
Fork 0

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 <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Matthieu Moy committed Feb 19, 2009 at 13:54 UTC e43a6fd3e94888d76779ad79fb568ed180e5fcdf
3 files changed +17 -3
builtin-update-index.c
+1 -2
@@ -742,8 +742,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
742 if (newfd < 0) {
743 if (refresh_flags & REFRESH_QUIET)
744 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);
746 }
747 if (write_cache(newfd, active_cache, active_nr) ||
748 commit_locked_index(lock_file))
cache.h
+1
@@ -484,6 +484,7 @@ struct lock_file {
484 };
485 #define LOCK_DIE_ON_ERROR 1
486 #define LOCK_NODEREF 2
487 +extern NORETURN void unable_to_lock_index_die(const char *path, int err);
488 extern int hold_lock_file_for_update(struct lock_file *, const char *path, int);
489 extern int hold_lock_file_for_append(struct lock_file *, const char *path, int);
490 extern int commit_lock_file(struct lock_file *);
lockfile.c
+15 -1
@@ -158,11 +158,25 @@ static int lock_file(struct lock_file *lk, const char *path, int flags)
158 return lk->fd;
159 }
160
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 +
175 int hold_lock_file_for_update(struct lock_file *lk, const char *path, int flags)
176 {
177 int fd = lock_file(lk, path, flags);
178 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);
180 return fd;
181 }
182