Skip to content

Fix some git clean issues

Elijah Newren git 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest12 patches 8 repliesIn review
  2. v312 patches 6 repliesSuperseded
  3. v2 RFC12 patches 5 repliesSuperseded

Changes in v4 from the cover letter

* Clarified a couple commit messages highlighted by Junio.

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/12t7300: add testcases showing failure to clean specified pathspecst/t7300-clean.sh+32 -00 replies
2/12dir: fix typo in commentdir.c+1 -10 replies
3/12dir: fix off-by-one error in match_pathspec_itemdir.c+2 -10 replies
4/12dir: also check directories for matching pathspecsdir.c t/t7300-clean.sh+7 -219 replies
5/12dir: make the DO_MATCH_SUBMODULE code reusable for a non-submodule casedir.c+3 -30 replies
6/12dir: if our pathspec might match files under a dir, recurse into itdir.c dir.h t/t7300-clean.sh+11 -80 replies
7/12dir: add commentary explaining match_pathspec_item's return valuedir.c+19 -80 replies
8/12git-clean.txt: do not claim we will delete files with -n/--dry-runDocumentation/git-clean.txt+1 -10 replies
9/12clean: disambiguate the definition of -dDocumentation/git-clean.txt builtin/clean.c t/t7300-clean.sh+16 -40 replies
10/12clean: avoid removing untracked files in a nested git repositoryDocumentation/git-clean.txt builtin/clean.c dir.c +2 more+22 -90 replies
11/12clean: rewrap overly long linebuiltin/clean.c+2 -10 replies
12/12clean: fix theoretical path corruptionbuiltin/clean.c+1 -10 replies

Reviews trailers per patch

None of the 12 patches has a Reviewed-by or Acked-by.

PatchDenton LiuSZEDER Gábor
1/12
2/12
3/12
4/12Helped-by Co-authored-by Co-authored-by Helped-by Co-authored-by Co-authored-by
5/12
6/12
7/12
8/12
9/12
10/12
11/12
12/12

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v4 thread

Cover letter [PATCH v4 00/12] Fix some git clean issues

This patch series fixes a few issues with git-clean:
* Failure to clean when multiple pathspecs are specified, reported both

    in April 2018[1] and again in May 2019[2].

* Failure to preserve both tracked and untracked files within a nested Git repository reported a few weeks ago by SZEDER[3].
It builds on sg/clean-nested-repo-with-ignored.

[1] https://public-inbox.org/git/[email protected]/
[2] https://public-inbox.org/git/[email protected]/
[3] https://public-inbox.org/git/[email protected]/

Changes since v3:
* Clarified a couple commit messages highlighted by Junio.

Elijah Newren (12):
t7300: add testcases showing failure to clean specified pathspecs
dir: fix typo in comment
dir: fix off-by-one error in match_pathspec_item
dir: also check directories for matching pathspecs
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
dir: add commentary explaining match_pathspec_item's return value git-clean.txt: do not claim we will delete files with -n/--dry-run
clean: disambiguate the definition of -d
clean: avoid removing untracked files in a nested git repository
clean: rewrap overly long line
clean: fix theoretical path corruption

 Documentation/git-clean.txt | 16 +++++-----
 builtin/clean.c             | 15 +++++++--
 dir.c                       | 63 +++++++++++++++++++++++++++----------
 dir.h                       |  8 +++--
 t/t7300-clean.sh            | 44 +++++++++++++++++++++++---
 5 files changed, 112 insertions(+), 34 deletions(-)

Range-diff:
1: fe35ab8cc3 ! 1: a48d4e7faf t7300: add testcases showing failure to clean specified pathspecs
@@ -28,9 +28,15 @@
showed that the same buggy behavior exists without using that flag, and has in fact existed since before cf424f5fd89b.

- Add testcases showing that multiple untracked files within entirely
- untracked directories cannot be cleaned when specifying these files to
- git clean via pathspecs.
+ Although these problems at first are perceived to be different (e.g.
+ never clearing out the requested files vs. taking multiple invocations
+ to get everything cleared out), they are actually just different
+ manifestations of the same problem. The case with multiple directories
+ that have no tracked files is the more general case; solving it will
+ solve all the others. So, I concentrate on it. Add testcases showing
+ that multiple untracked files within entirely untracked directories
+ cannot be cleaned when specifying these files to git clean via
+ pathspecs.

 2:  707d287d79 =  2:  eb00b46822 dir: fix typo in comment
 3:  bb316e82b2 !  3:  c0e5b820a9 dir: fix off-by-one error in match_pathspec_item

@@ -6,11 +6,22 @@
namelen will be 4, and match[namelen] will be 'b'. The correct location of the directory separator is namelen-1.

- The reason the code worked anyway was that the following code immediately
- checked whether the first matchlen characters matched (which they do) and
- then bailed and return MATCHED_RECURSIVELY anyway since wildmatch doesn't
- have the ability to check if "name" can be matched as a directory (or
- prefix) against the pathspec.
+ However, other callers of match_pathspec_item() such as builtin/grep.c's
+ submodule_path_match() will compare against a path named "foo" instead of
+ "foo/". It might be better to change all the callers to be consistent,
+ as discussed at
+ https://public-inbox.org/git/[email protected]/
+ and
+ https://public-inbox.org/git/CABPp-BERWUPCPq-9fVW1LNocqkrfsoF4BPj3gJd9+En43vEkTQ@mail.gmail.com/
+ but there are many cases to audit, so for now just make sure we handle
+ both cases with and without a trailing slash.
+
+ The reason the code worked despite this sometimes-off-by-one error was
+ that the subsequent code immediately checked whether the first matchlen
+ characters matched (which they do) and then bailed and return
+ MATCHED_RECURSIVELY anyway since wildmatch doesn't have the ability to
+ check if "name" can be matched as a directory (or prefix) against the
+ pathspec.

 4:  56319f934a =  4:  397775ec35 dir: also check directories for matching pathspecs
 5:  81593a565c =  5:  b836de82c0 dir: make the DO_MATCH_SUBMODULE code reusable for a non-submodule case
 6:  9566823a0f =  6:  feb317d090 dir: if our pathspec might match files under a dir, recurse into it
 7:  7821898ba7 =  7:  0a574d6779 dir: add commentary explaining match_pathspec_item's return value
 8:  13def5df57 =  8:  0eaa08537c git-clean.txt: do not claim we will delete files with -n/--dry-run
 9:  e6b274abf7 =  9:  a1438301bb clean: disambiguate the definition of -d
10:  5f4ef14765 = 10:  8dc21923ee clean: avoid removing untracked files in a nested git repository
11:  4e30e62eb1 = 11:  707b6a5509 clean: rewrap overly long line
12:  de2444f7cb = 12:  84a90010ed clean: fix theoretical path corruption
Signature · 1 line
2.22.1.17.g6e632477f7.dirty