Skip to content

RFC Fix `git clean` with pathspecs

Elijah Newren git 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest7 patches 9 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/7dir.c: Fix typo in commentdir.c+1 -10 replies
2/7dir.c: fix off-by-one error in match_pathspec_itemdir.c+1 -15 replies
3/7t7300: Add some testcases showing failure to clean specified pathspecst/t7300-clean.sh+32 -00 replies
4/7dir: Directories should be checked for matching pathspecs toodir.c t/t7300-clean.sh+7 -24 replies
5/7dir: Make the DO_MATCH_SUBMODULE code reusable for a non-submodule casedir.c+3 -30 replies
6/7dir: If our pathspec might match files under a dir, recurse into itdir.c dir.h t/t7300-clean.sh+11 -80 replies
7/7If we do not want globs to recurse into subdirs without -d...dir.c t/t7300-clean.sh+4 -40 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [RFC PATCH 0/7] Fix `git clean` with pathspecs

Sometimes, multiple git clean $ARGS invocations (with the exact same flags and parameters for each invocation) are needed to properly clean out the desired files. Sometimes, git clean $PATHS just refuses to clean the files it was explicitly told to clean. This patch series aims to address these (very old) problems.

I was made aware of the problems when a user brought to me the following testcase:

    mkdir d{1,2}
    touch d{1,2}/ut
    touch d1/t
    git add d1/t

With this setup, the user would need to run
git clean -ffd */ut
twice to delete both ut files. Digging further, I found multiple interesting variants.

However, I am still slightly unsure of what the correct behavior is supposed to be for one particular case, namely, if the clean command were instead:
git clean -f '*ut'
(note that the glob is quoted to protect from shell expansion, and that the -d option was removed), should the files still be cleaned? I assumed yes and implemented that in patches 5-6, but the commit message discusses this case, and patch 7 exists to change the implementation to answer this question with a 'no'. Patch 7 should NOT should not be accepted as-is -- it should either be dropped or squashed into earlier commits, but which depends on the desired behavior.

Patches 1-2 are almost independent one-line fixes that could be submitted independently. However, if we decide to keep the changes from patch 7, then this series does depend on patch 2 for the tests to pass.

Patch 3 adds four new testcases covering the variants I noticed.

Patch 4 fixes clean with explicit pathspecs and the -d option.

Patches 5-7 fixes clean with explicit pathspecs without the -d option.

Elijah Newren (7):
dir.c: Fix typo in comment
dir.c: fix off-by-one error in match_pathspec_item
t7300: Add some testcases showing failure to clean specified pathspecs
dir: Directories should be checked for matching pathspecs too
dir: Make the DO_MATCH_SUBMODULE code reusable for a non-submodule
case
dir: If our pathspec might match files under a dir, recurse into it If we do not want globs to recurse into subdirs without -d...

 dir.c            | 23 +++++++++++++++--------
 dir.h            |  5 +++--
 t/t7300-clean.sh | 32 ++++++++++++++++++++++++++++++++
 3 files changed, 50 insertions(+), 10 deletions(-)
Signature · 1 line
2.17.0.7.g0b50f94d69