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

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

From
Elijah Newren <newren@gmail.com>
Date
Apr 5, 2018, 17:34 UTC
Message-ID
<20180405173446.32372-1-newren@gmail.com>

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(-)
-- 
2.17.0.7.g0b50f94d69
Next: Elijah Newren
Message 1 of 17 in “Fix `git clean` with pathspecs”
  1. 0/7 Fix `git clean` with pathspecsElijah Newren, Apr 5, 2018
  2. 7/7 If we do not want globs to recurse into subdirs without -d...Elijah Newren, Apr 5, 2018
  3. 6/7 dir: If our pathspec might match files under a dir, recurse into itElijah Newren, Apr 5, 2018
  4. 4/7 dir: Directories should be checked for matching pathspecs tooElijah Newren, Apr 5, 2018
  5. Jeff KingApr 5, 2018
  6. Elijah NewrenApr 5, 2018
  7. Jeff KingApr 5, 2018
  8. Junio C HamanoApr 9, 2018
  9. 3/7 t7300: Add some testcases showing failure to clean specified pathspecsElijah Newren, Apr 5, 2018
  10. 5/7 dir: Make the DO_MATCH_SUBMODULE code reusable for a non-submodule caseElijah Newren, Apr 5, 2018
  11. 1/7 dir.c: Fix typo in commentElijah Newren, Apr 5, 2018
  12. 2/7 dir.c: fix off-by-one error in match_pathspec_itemElijah Newren, Apr 5, 2018
  13. Jeff KingApr 5, 2018
  14. Elijah NewrenApr 5, 2018
  15. Jeff KingApr 5, 2018
  16. Elijah NewrenApr 5, 2018
  17. Jeff KingApr 6, 2018

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.