Thread (1 message) 1 message, 1 author, 2016-06-15
  • (off-list ancestor, not in this archive)
  • Re: Removing files · Junio C Hamano <hidden> · 2016-06-15

Re: Removing files

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:42:49
Subsystem: the rest · Maintainer: Linus Torvalds

Possibly related (same subject, not in this thread)

Junio C Hamano [off-list ref] writes:
I think the right fix is to suggest "git add/rm" in status
output and make "git rm" not barf if the user has already
removed the file from the working tree.
This does the latter.  A separate patch will do the former.

-- >8 --

[PATCH] 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 <redacted>
---
 builtin-rm.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/builtin-rm.c b/builtin-rm.c
index 5b078c4..d81f289 100644
--- a/builtin-rm.c
+++ b/builtin-rm.c
@@ -32,6 +32,10 @@ static int remove_file(const char *name)
 	char *slash;
 
 	ret = unlink(name);
+	if (ret && errno == ENOENT)
+		/* The user has removed it from the filesystem by hand */
+		ret = errno = 0;
+
 	if (!ret && (slash = strrchr(name, '/'))) {
 		char *n = xstrdup(name);
 		do {
@@ -204,7 +208,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
 		return 0;
 
 	/*
-	 * Then, unless we used "--cache", remove the filenames from
+	 * Then, unless we used "--cached", remove the filenames from
 	 * the workspace. If we fail to remove the first one, we
 	 * abort the "git rm" (but once we've successfully removed
 	 * any file at all, we'll go ahead and commit to it all:
-- 
1.4.4.4.gb8a1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help