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

[PATCH] git rm: refresh index before up-to-date check

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Oct 7, 2008, 16:08 UTC
Message-ID
<alpine.DEB.1.00.0810071807500.22125@pacific.mpi-cbg.de.mpi-cbg.de>

Since "git rm" is supposed to be porcelain, we should convince it to be user friendly by refreshing the index itself.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 builtin-rm.c  |    1 +
 t/t3600-rm.sh |   25 +++++++++++++++++--------
 2 files changed, 18 insertions(+), 8 deletions(-)
diff --git a/builtin-rm.c b/builtin-rm.c
index 50ae6d5..e06640c 100644
--- a/builtin-rm.c
+++ b/builtin-rm.c
@@ -137,6 +137,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
 
 	if (read_cache() < 0)
 		die("index file corrupt");
+	refresh_cache(REFRESH_QUIET);
 
 	pathspec = get_pathspec(prefix, argv);
 	seen = NULL;
diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh
index 558c80e..66aca99 100755
--- a/t/t3600-rm.sh
+++ b/t/t3600-rm.sh
@@ -219,14 +219,23 @@ test_expect_success 'Remove nonexistent file returns nonzero exit status' '
 
 test_expect_success 'Call "rm" from outside the work tree' '
 	mkdir repo &&
-	cd repo &&
-	git init &&
-	echo something > somefile &&
-	git add somefile &&
-	git commit -m "add a file" &&
-	(cd .. &&
-	 git --git-dir=repo/.git --work-tree=repo rm somefile) &&
-	test_must_fail git ls-files --error-unmatch somefile
+	(cd repo &&
+	 git init &&
+	 echo something > somefile &&
+	 git add somefile &&
+	 git commit -m "add a file" &&
+	 (cd .. &&
+	  git --git-dir=repo/.git --work-tree=repo rm somefile) &&
+	test_must_fail git ls-files --error-unmatch somefile)
+'
+
+test_expect_success 'refresh index before checking if it is up-to-date' '
+
+	git reset --hard &&
+	test-chmtime -86400 frotz/nitfol &&
+	git rm frotz/nitfol &&
+	test ! -f frotz/nitfol
+
 '
 
 test_done
-- 
1.6.0.2.713.g3dcb0
Message 1 of 1 in “git rm: refresh index before up-to-date check”
  1. git rm: refresh index before up-to-date checkJohannes Schindelin, Oct 7, 2008

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.