Skip to content

Commit 3667755

Browse files
committed
clean: show an error message when the path is too long
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: git-for-windows#521 Signed-off-by: Johannes Schindelin <[email protected]>
1 parent aa25c82 commit 3667755

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

builtin/clean.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
194194
strbuf_setlen(path, len);
195195
strbuf_addstr(path, e->d_name);
196196
if (lstat(path->buf, &st))
197-
; /* fall thru */
197+
warning("Could not stat path '%s': %s",
198+
path->buf, strerror(errno));
198199
else if (S_ISDIR(st.st_mode)) {
199200
if (remove_dirs(path, prefix, force_flag, dry_run, quiet, &gone))
200201
ret = 1;

t/t7300-clean.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,4 +669,15 @@ test_expect_success 'git clean -d skips untracked dirs containing ignored files'
669669
test_path_is_missing foo/b/bb
670670
'
671671

672+
test_expect_success MINGW 'handle clean & core.longpaths = false nicely' '
673+
git config core.longpaths false &&
674+
test_when_finished git config --unset core.longpaths &&
675+
a50=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
676+
mkdir -p $a50$a50/$a50$a50/$a50$a50 &&
677+
touch $a50$a50/test.txt &&
678+
touch $a50$a50/$a50$a50/$a50$a50/test.txt &&
679+
test_must_fail git clean -xdf 2>.git/err &&
680+
grep "too long" .git/err
681+
'
682+
672683
test_done

0 commit comments

Comments
 (0)