Use ValueSource for git-aware line ending resolution to fix configuration cache invalidation#2915
Use ValueSource for git-aware line ending resolution to fix configuration cache invalidation#2915joshfriend wants to merge 2 commits intodiffplug:mainfrom
Conversation
98b0b1b to
c07e15a
Compare
…tion time GitRatchetGradle is instantiated eagerly when SpotlessTaskService is created, which happens during Gradle configuration. Its static initializer installs a custom JGit SystemReader that reads ~/.gitconfig. This causes Gradle's configuration cache to fingerprint the file even when no Spotless tasks are requested. Defer instantiation to getRatchet(), which is only called during task execution. This avoids loading JGit classes and reading git config files at configuration time.
c07e15a to
ca71301
Compare
|
looks like it needs a |
…tion cache The default GIT_ATTRIBUTES_FAST_ALLSAME line ending policy reads ~/.gitconfig via JGit during configuration. Gradle's configuration cache fingerprints this read, so when CI workers inject per-build auth tokens into ~/.gitconfig, the cache is invalidated every build. Wrap the git config resolution in a Gradle ValueSource. File reads inside ValueSource.obtain() are not tracked as configuration cache inputs; only the returned value is fingerprinted. This means ~/.gitconfig changes that do not affect the resolved line ending (e.g. auth tokens) no longer invalidate the cache.
058962c to
22ca994
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 22ca994fda
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| config = repoConfig; | ||
| } | ||
|
|
||
| return defaultLineEnding(config).createPolicy(); |
There was a problem hiding this comment.
Preserve .gitattributes-based line ending resolution
Returning defaultLineEnding(config).createPolicy() here drops the .gitattributes logic that LineEnding.GIT_ATTRIBUTES_FAST_ALLSAME previously used via LineEnding#createPolicy(File, Supplier). In repositories that declare per-path EOL rules (for example *.bat eol=crlf), Spotless will now treat all files as the Git config default and can rewrite files with incorrect endings, which is a behavioral regression from the prior policy implementation.
Useful? React with 👍 / 👎.
| if (dotGit.isDirectory()) { | ||
| return dotGit; |
There was a problem hiding this comment.
Support
.git indirection files when finding repo config
The repository lookup only accepts .git directories, but in common setups like linked worktrees (and some submodule layouts) .git is a file pointing to the real git dir. In those cases this method returns null, repo-local config is skipped, and core.eol/core.autocrlf from the repository are ignored, causing line-ending decisions to silently fall back to user/global config.
Useful? React with 👍 / 👎.
The default GIT_ATTRIBUTES_FAST_ALLSAME line ending policy reads ~/.gitconfig via JGit during configuration. Gradle's configuration cache fingerprints this read, so when CI workers inject per-build auth tokens into ~/.gitconfig, the cache is invalidated every build.
This wraps the git config resolution in a Gradle ValueSource. File reads inside ValueSource.obtain() are not tracked as configuration cache inputs; only the returned value is fingerprinted. ~/.gitconfig changes that do not affect the resolved line ending (e.g. auth tokens) no longer invalidate the cache.