Skip to content

Use ValueSource for git-aware line ending resolution to fix configuration cache invalidation#2915

Open
joshfriend wants to merge 2 commits intodiffplug:mainfrom
joshfriend:jfriend/respect-git-config-global
Open

Use ValueSource for git-aware line ending resolution to fix configuration cache invalidation#2915
joshfriend wants to merge 2 commits intodiffplug:mainfrom
joshfriend:jfriend/respect-git-config-global

Conversation

@joshfriend
Copy link
Copy Markdown

@joshfriend joshfriend commented May 1, 2026

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.

@joshfriend joshfriend marked this pull request as draft May 1, 2026 18:32
@joshfriend joshfriend force-pushed the jfriend/respect-git-config-global branch 3 times, most recently from 98b0b1b to c07e15a Compare May 1, 2026 18:51
…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.
@joshfriend joshfriend force-pushed the jfriend/respect-git-config-global branch from c07e15a to ca71301 Compare May 1, 2026 19:05
@joshfriend joshfriend changed the title Respect GIT_CONFIG_GLOBAL env var in JGit SystemReader delegate Lazily initialize GitRatchetGradle to avoid reading git config at configuration time May 1, 2026
@joshfriend joshfriend changed the title Lazily initialize GitRatchetGradle to avoid reading git config at configuration time Use ValueSource for git-aware line ending resolution to fix configuration cache invalidation May 1, 2026
@nedtwigg
Copy link
Copy Markdown
Member

nedtwigg commented May 6, 2026

looks like it needs a spotlessApply

…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.
@joshfriend joshfriend force-pushed the jfriend/respect-git-config-global branch from 058962c to 22ca994 Compare May 7, 2026 21:19
@joshfriend joshfriend marked this pull request as ready for review May 7, 2026 21:21
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Comment on lines +78 to +79
if (dotGit.isDirectory()) {
return dotGit;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants