git-rm: do not fail on already removed file.
Often the user would do "/bin/rm foo" before telling git, but then want to tell git about it. "git rm foo" however would fail because it cannot unlink(2) foo. Treat ENOENT error return from unlink(2) as if a successful removal happened. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Jan 11, 2007 at 14:58 UTC
646ac22bdf7f7011bb4c77647053416e892ce64d
1 file changed
+5
-1
builtin-rm.c
+5
-1
@@ -32,6 +32,10 @@ static int remove_file(const char *name)
32
char *slash;
33
34
ret = unlink(name);
35
+ if (ret && errno == ENOENT)
36
+ /* The user has removed it from the filesystem by hand */
37
+ ret = errno = 0;
38
+
39
if (!ret && (slash = strrchr(name, '/'))) {
40
char *n = xstrdup(name);
41
do {
@@ -204,7 +208,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
208
return 0;
209
210
/*
207
- * Then, unless we used "--cache", remove the filenames from
211
+ * Then, unless we used "--cached", remove the filenames from
212
* the workspace. If we fail to remove the first one, we
213
* abort the "git rm" (but once we've successfully removed
214
* any file at all, we'll go ahead and commit to it all: