@matheusbsbs / matheus-bagliano / commits / 7b802b86a6
Fork 0

update-index: do not die too early in a read-only repository.

This delays the error exit from hold_lock_file_for_update() in update-index, so that "update-index --refresh" in a read-only repository can still report what paths are stat-dirty before exiting. Also it makes -q to squelch the error message. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Feb 22, 2007 at 00:30 UTC 7b802b86a6734a47c964d84922af2a016d836882
1 file changed +10 -1
builtin-update-index.c
+10 -1
@@ -486,6 +486,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
486 int prefix_length = prefix ? strlen(prefix) : 0;
487 char set_executable_bit = 0;
488 unsigned int refresh_flags = 0;
489 + int lock_error = 0;
490 struct lock_file *lock_file;
491
492 git_config(git_default_config);
@@ -493,7 +494,9 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
494 /* We can't free this memory, it becomes part of a linked list parsed atexit() */
495 lock_file = xcalloc(1, sizeof(struct lock_file));
496
496 - newfd = hold_lock_file_for_update(lock_file, get_index_file(), 1);
497 + newfd = hold_lock_file_for_update(lock_file, get_index_file(), 0);
498 + if (newfd < 0)
499 + lock_error = errno;
500
501 entries = read_cache();
502 if (entries < 0)
@@ -650,6 +653,12 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
653
654 finish:
655 if (active_cache_changed) {
656 + if (newfd < 0) {
657 + if (refresh_flags & REFRESH_QUIET)
658 + exit(128);
659 + die("unable to create '%s.lock': %s",
660 + get_index_file(), strerror(lock_error));
661 + }
662 if (write_cache(newfd, active_cache, active_nr) ||
663 close(newfd) || commit_lock_file(lock_file))
664 die("Unable to write new index file");