Anonymous avatar Anonymous committed 34143b2

[PATCH] Improve git-update-index error reporting

This makes git-update-index error reporting much less confusing. The
user will know what went wrong with better precision, and will be given
a hopefully less confusing advice.

Signed-off-by: Petr Baudis <pasky@suse.cz>;
Signed-off-by: Junio C Hamano <junkio@cox.net>;

Comments (0)

Files changed (1)

 		 * case just fine without --force-remove.
 		 */
 		if (status == 0 || (errno == ENOENT || errno == ENOTDIR)) {
-			if (allow_remove)
-				return remove_file_from_cache(path);
+			if (allow_remove) {
+				if (remove_file_from_cache(path))
+					return error("%s: cannot remove from the index",
+					             path);
+				else
+					return 0;
+			} else if (status < 0) {
+				return error("%s: does not exist and --remove not passed",
+				             path);
+			}
 		}
 		if (0 == status)
-			return error("%s: is a directory", path);
+			return error("%s: is a directory - add files inside instead",
+			             path);
 		else
 			return error("lstat(\"%s\"): %s", path,
 				     strerror(errno));
 	case S_IFREG:
 		fd = open(path, O_RDONLY);
 		if (fd < 0)
-			return -1;
+			return error("open(\"%s\"): %s", path, strerror(errno));
 		if (index_fd(ce->sha1, fd, &st, !info_only, NULL) < 0)
-			return -1;
+			return error("%s: failed to insert into database", path);
 		break;
 	case S_IFLNK:
 		target = xmalloc(st.st_size+1);
 		if (readlink(path, target, st.st_size+1) != st.st_size) {
+			char *errstr = strerror(errno);
 			free(target);
-			return -1;
+			return error("readlink(\"%s\"): %s", path,
+			             errstr);
 		}
 		if (info_only) {
 			unsigned char hdr[50];
 			write_sha1_file_prepare(target, st.st_size, "blob",
 						ce->sha1, hdr, &hdrlen);
 		} else if (write_sha1_file(target, st.st_size, "blob", ce->sha1))
-			return -1;
+			return error("%s: failed to insert into database", path);
 		free(target);
 		break;
 	default:
-		return -1;
+		return error("%s: unsupported file type", path);
 	}
 	option = allow_add ? ADD_CACHE_OK_TO_ADD : 0;
 	option |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0;
-	return add_cache_entry(ce, option);
+	if (add_cache_entry(ce, option))
+		return error("%s: cannot add to the index - missing --add option?",
+			     path);
+	return 0;
 }
 
 static int compare_data(struct cache_entry *ce, struct stat *st)
 		}
 		if (force_remove) {
 			if (remove_file_from_cache(path))
-				die("git-update-index: --force-remove cannot remove %s", path);
+				die("git-update-index: unable to remove %s", path);
 			continue;
 		}
 		if (add_file_to_cache(path))
-			die("Unable to add %s to database; maybe you want to use --add option?", path);
+			die("Unable to process file %s", path);
 	}
 	if (write_cache(newfd, active_cache, active_nr) ||
 	    commit_index_file(&cache_file))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.