git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Removing files

From
Junio C Hamano <junkio@cox.net>
Date
Jan 11, 2007, 23:36 UTC
Message-ID
<7vzm8p16h9.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<7vejq12nlu.fsf@assigned-by-dhcp.cox.net>
Junio C Hamano <junkio@cox.net> 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 <junkio@cox.net>
---
 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
Previous: Eric WongNext: Junio C Hamano
Message 6 of 15 in “Removing files”
  1. David KågedalJan 11, 2007
  2. Alex RiesenJan 11, 2007
  3. Seth FalconJan 11, 2007
  4. Junio C HamanoJan 11, 2007
  5. Eric WongJan 11, 2007
  6. Junio C HamanoJan 11, 2007
  7. git-status: wording update to deal with deleted files.Junio C Hamano, Jan 11, 2007
  8. Carl WorthJan 11, 2007
  9. Junio C HamanoJan 12, 2007
  10. Carl WorthJan 12, 2007
  11. Jakub NarebskiJan 12, 2007
  12. Jeff KingJan 12, 2007
  13. Juergen RuehleJan 12, 2007
  14. Carl WorthJan 11, 2007
  15. Jeff KingJan 12, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.