[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>
Petr Baudis committed
Sep 18, 2005 at 21:09 UTC
34143b2639625f29edf7b1c0c5af58e545845911
1 file changed
+25
-11
update-index.c
+25
-11
@@ -50,11 +50,20 @@ static int add_file_to_cache(char *path)
50
* case just fine without --force-remove.
51
*/
52
if (status == 0 || (errno == ENOENT || errno == ENOTDIR)) {
53
- if (allow_remove)
54
- return remove_file_from_cache(path);
53
+ if (allow_remove) {
54
+ if (remove_file_from_cache(path))
55
+ return error("%s: cannot remove from the index",
56
+ path);
57
+ else
58
+ return 0;
59
+ } else if (status < 0) {
60
+ return error("%s: does not exist and --remove not passed",
61
+ path);
62
+ }
63
}
64
if (0 == status)
57
- return error("%s: is a directory", path);
65
+ return error("%s: is a directory - add files inside instead",
66
+ path);
67
else
68
return error("lstat(\"%s\"): %s", path,
69
strerror(errno));
@@ -71,15 +80,17 @@ static int add_file_to_cache(char *path)
80
case S_IFREG:
81
fd = open(path, O_RDONLY);
82
if (fd < 0)
74
- return -1;
83
+ return error("open(\"%s\"): %s", path, strerror(errno));
84
if (index_fd(ce->sha1, fd, &st, !info_only, NULL) < 0)
76
- return -1;
85
+ return error("%s: failed to insert into database", path);
86
break;
87
case S_IFLNK:
88
target = xmalloc(st.st_size+1);
89
if (readlink(path, target, st.st_size+1) != st.st_size) {
90
+ char *errstr = strerror(errno);
91
free(target);
82
- return -1;
92
+ return error("readlink(\"%s\"): %s", path,
93
+ errstr);
94
}
95
if (info_only) {
96
unsigned char hdr[50];
@@ -87,15 +98,18 @@ static int add_file_to_cache(char *path)
98
write_sha1_file_prepare(target, st.st_size, "blob",
99
ce->sha1, hdr, &hdrlen);
100
} else if (write_sha1_file(target, st.st_size, "blob", ce->sha1))
90
- return -1;
101
+ return error("%s: failed to insert into database", path);
102
free(target);
103
break;
104
default:
94
- return -1;
105
+ return error("%s: unsupported file type", path);
106
}
107
option = allow_add ? ADD_CACHE_OK_TO_ADD : 0;
108
option |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0;
98
- return add_cache_entry(ce, option);
109
+ if (add_cache_entry(ce, option))
110
+ return error("%s: cannot add to the index - missing --add option?",
111
+ path);
112
+ return 0;
113
}
114
115
static int compare_data(struct cache_entry *ce, struct stat *st)
@@ -393,11 +407,11 @@ int main(int argc, char **argv)
407
}
408
if (force_remove) {
409
if (remove_file_from_cache(path))
396
- die("git-update-index: --force-remove cannot remove %s", path);
410
+ die("git-update-index: unable to remove %s", path);
411
continue;
412
}
413
if (add_file_to_cache(path))
400
- die("Unable to add %s to database; maybe you want to use --add option?", path);
414
+ die("Unable to process file %s", path);
415
}
416
if (write_cache(newfd, active_cache, active_nr) ||
417
commit_index_file(&cache_file))