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

[PATCH v2 4/9] git rm: display a warning for every unremovable file

From
Peter Collingbourne <peter@pcc.me.uk>
Date
Apr 10, 2010, 18:23 UTC
Message-ID
<1270923830-11830-5-git-send-email-peter@pcc.me.uk>
In-Reply-To
<1270923830-11830-1-git-send-email-peter@pcc.me.uk>

When ‘git rm’ was built in (d9b814cc, 2006-05-19), its semantics changed: before, it just removed files until it encountered an error and then would error out, whereas since then, it makes an attempt to either remove all files or remove none at all. In particular, if ‘git rm’ fails to remove a file after other files have already been removed, it does not abort but instead silently accepts the error.

Better to warn the user in this case!

This problem is particularly noticeable when dealing with submodules because the rmdir operation will fail for every initialised submodule. The removal of the contents of an initialised submodule directory should always be user controlled, due to the possibility of unpropagated changes to the submodule. Therefore, the user should always be informed of any such removal failures.

Based-on-work-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Peter Collingbourne <peter@pcc.me.uk>
---
 builtin/rm.c  |    2 ++
 t/t3600-rm.sh |   15 +++++++++++++++
 2 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/builtin/rm.c b/builtin/rm.c
index f3772c8..05a5158 100644
--- a/builtin/rm.c
+++ b/builtin/rm.c
@@ -259,6 +259,8 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
 			}
 			if (!removed)
 				die_errno("git rm: '%s'", path);
+			else
+				warning("git rm: '%s': %s", path, strerror(errno));
 		}
 	}
 
diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh
index 5186844..ecddd67 100755
--- a/t/t3600-rm.sh
+++ b/t/t3600-rm.sh
@@ -180,6 +180,21 @@ test_expect_success 'Message when first removal fails' '
 ! test -e plugh || chmod 775 plugh
 rm -fr msg plugh xyzzy
 
+test_expect_success 'Message when second removal fails' '
+	touch plugh &&
+	mkdir -p xyzzy &&
+	touch xyzzy/plugh &&
+	git add plugh xyzzy/plugh &&
+	git commit --allow-empty -a -m "two files to remove" &&
+	chmod a-w xyzzy &&
+
+	git rm plugh xyzzy/plugh 2>msg &&
+
+	grep "git rm: '\''xyzzy/plugh'\'':" msg
+'
+! test -e xyzzy || chmod 775 xyzzy
+rm -fr expect actual plugh xyzzy
+
 test_expect_success '"rm" command printed' '
 	echo frotz > test-file &&
 	git add test-file &&
-- 
1.6.5
Previous: Peter CollingbourneNext: Peter Collingbourne
Message 7 of 14 in “Improve handling of moving and removing submodules”
  1. 0/9 Improve handling of moving and removing submodulesPeter Collingbourne, Apr 10, 2010
  2. 1/9 Generate unique ID for submodules created using "git submodule add"Peter Collingbourne, Apr 10, 2010
  3. Sverre RabbelierApr 10, 2010
  4. 2/9 Implement "git mv" for submodulesPeter Collingbourne, Apr 10, 2010
  5. Junio C HamanoApr 11, 2010
  6. 3/9 git rm: test failure behaviour for multiple removalsPeter Collingbourne, Apr 10, 2010
  7. 4/9 git rm: display a warning for every unremovable filePeter Collingbourne, Apr 10, 2010
  8. 5/9 git rm: collect file modesPeter Collingbourne, Apr 10, 2010
  9. 6/9 Add a mode parameter to the remove_path functionPeter Collingbourne, Apr 10, 2010
  10. Junio C HamanoApr 11, 2010
  11. 7/9 git rm: do not abort due to an initialised submodulePeter Collingbourne, Apr 10, 2010
  12. Junio C HamanoApr 11, 2010
  13. 8/9 git submodule: infrastructure for reading .gitmodules files in arbitrary locationsPeter Collingbourne, Apr 10, 2010
  14. 9/9 git rm: remove submodule entries from .gitmodulesPeter Collingbourne, Apr 10, 2010

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.