Skip to content

Add GitIgnore utility for gitignored-and-untracked checks#7215

Merged
sambsnyd merged 2 commits intomainfrom
add-git-ignore-utility
Mar 31, 2026
Merged

Add GitIgnore utility for gitignored-and-untracked checks#7215
sambsnyd merged 2 commits intomainfrom
add-git-ignore-utility

Conversation

@pdelagrave
Copy link
Copy Markdown
Contributor

Adds org.openrewrite.internal.GitIgnore with a static isIgnoredAndUntracked(Repository, String) method that checks whether a file matches .gitignore rules AND is not tracked in the git index.

Both rewrite-gradle-plugin and rewrite-maven-plugin had their own inline implementations of this check with identical bugs. This shared utility provides a single correct implementation using JGit's DirCacheIterator to consult the index, matching git's own behavior: .gitignore has no effect on tracked files.

Add a shared utility in rewrite-core that checks whether a file is
matched by .gitignore rules AND is not tracked in the git index.

This addresses the fact that three separate codebases (rewrite-polyglot,
rewrite-gradle-plugin, rewrite-maven-plugin) each had their own
implementation of this check, with varying degrees of correctness.
The utility uses JGit's TreeWalk with both FileTreeIterator and
DirCacheIterator to match git's own behavior: .gitignore has no
effect on files that are already tracked.
@github-project-automation github-project-automation bot moved this from In Progress to Ready to Review in OpenRewrite Mar 31, 2026
@sambsnyd sambsnyd merged commit 68ef641 into main Mar 31, 2026
1 check passed
@sambsnyd sambsnyd deleted the add-git-ignore-utility branch March 31, 2026 18:21
@github-project-automation github-project-automation bot moved this from Ready to Review to Done in OpenRewrite Mar 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants