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

[PATCH 1/1] clean: show an error message when the path is too long

From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
Date
Jul 16, 2019, 14:04 UTC
Message-ID
<36677556a26cca9eafd859c88aa9b2c5a6cde309.1563285862.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.219.git.gitgitgadget@gmail.com>
From: Johannes Schindelin <johannes.schindelin@gmx.de>

Without an error message when stat() failed, e.g. `git clean` would abort without an error message, leaving the user quite puzzled.

In particular on Windows, where the default maximum path length is quite small (yet there are ways to circumvent that limit in many cases), it is very important that users be given an indication why their command failed because of too long paths when it did.

This test case makes sure that a warning is issued that would have helped the user who reported this issue:

	https://github.com/git-for-windows/git/issues/521
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 builtin/clean.c  |  3 ++-
 t/t7300-clean.sh | 11 +++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/builtin/clean.c b/builtin/clean.c
index aaba4af3c2..7be689f480 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -194,7 +194,8 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
 		strbuf_setlen(path, len);
 		strbuf_addstr(path, e->d_name);
 		if (lstat(path->buf, &st))
-			; /* fall thru */
+			warning("Could not stat path '%s': %s",
+				path->buf, strerror(errno));
 		else if (S_ISDIR(st.st_mode)) {
 			if (remove_dirs(path, prefix, force_flag, dry_run, quiet, &gone))
 				ret = 1;
diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh
index 7b36954d63..aa08443f6a 100755
--- a/t/t7300-clean.sh
+++ b/t/t7300-clean.sh
@@ -669,4 +669,15 @@ test_expect_success 'git clean -d skips untracked dirs containing ignored files'
 	test_path_is_missing foo/b/bb
 '
 
+test_expect_success MINGW 'handle clean & core.longpaths = false nicely' '
+	git config core.longpaths false &&
+	test_when_finished git config --unset core.longpaths &&
+	a50=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
+	mkdir -p $a50$a50/$a50$a50/$a50$a50 &&
+	touch $a50$a50/test.txt &&
+	touch $a50$a50/$a50$a50/$a50$a50/test.txt &&
+	test_must_fail git clean -xdf 2>.git/err &&
+	grep "too long" .git/err
+'
+
 test_done
-- 
gitgitgadget
Previous: Johannes Schindelin via GitGitGadgetNext: René Scharfe
Message 2 of 12 in “Show an error if too-long paths are seen by git clean -dfx”
  1. 0/1 Show an error if too-long paths are seen by git clean -dfxJohannes Schindelin via GitGitGadget, Jul 16, 2019
  2. 1/1 clean: show an error message when the path is too longJohannes Schindelin via GitGitGadget, Jul 16, 2019
  3. René ScharfeJul 16, 2019
  4. Junio C HamanoJul 16, 2019
  5. Junio C HamanoJul 17, 2019
  6. Johannes SchindelinJul 18, 2019
  7. SZEDER GáborJul 16, 2019
  8. 0/1 Show an error if too-long paths are seen by git clean -dfxJohannes Schindelin via GitGitGadget, Jul 18, 2019
  9. 1/1 clean: show an error message when the path is too longJohannes Schindelin via GitGitGadget, Jul 18, 2019
  10. Junio C HamanoJul 18, 2019
  11. Johannes SchindelinJul 19, 2019
  12. Junio C HamanoJul 19, 2019

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.