Stop gh re-drifting the gitconfig credential blocks - #18
Merged
Conversation
`gh auth setup-git` writes the credential helpers through `git config`,
which emits a tab indent and a trailing space after the empty
`helper =`. The source was space-indented with no trailing space, so
every run re-drifted the file and the fix was to remember to pass
`chezmoi apply --force`.
Match `git config` byte-for-byte instead, so gh's rewrite is a no-op.
A literal trailing space cannot live in the source -- the
trailing-whitespace hook strips it and would silently reintroduce the
drift -- so it is emitted by a {{ " " }} template expression.
No modify_ script needed here: unlike the JSON settings files, only
these two blocks are ever rewritten, and INI has no jq equivalent.
Verified by running `gh auth setup-git` three times; chezmoi status
stays clean and both helpers still resolve.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes the last known self-rewriting file, after #17 handled the two JSON ones.
Cause
gh auth setup-gitdoes not hand-write the credential blocks -- it goes throughgit config, which has its own canonical format. Reproduced against a scratchfile:
The source was space-indented with no trailing space, so the two never matched
and every
gh auth setup-gitre-drifted~/.gitconfig. The previous mitigationwas a comment telling you to run
chezmoi apply --force.Fix
Match
git configbyte-for-byte, so gh's rewrite is a no-op.The trailing space is the catch: it cannot exist literally in the source, because
the
trailing-whitespacepre-commit hook only excludeshome/.*/encrypted_andwould strip it on the next commit -- silently reintroducing the exact drift being
fixed. So it is emitted by a
{{ " " }}template expression, leaving the sourcefile free of literal trailing whitespace.
No
modify_script here. Unlikesettings.json, only these two blocks are everrewritten and the values are already fully managed, so there is nothing to merge
-- and INI has no
jqequivalent, which would have meantgit config -fagainsta temp file for no benefit.
Manual testing
git configbyte-for-byte (tab + trailing space)grep -n " $"on the source: no literal trailing whitespacepre-commit runpasses, and the template still renders the tab and trailing space afterwards -- the hook no longer defeats itgh auth setup-gitthree times;chezmoi status ~/.gitconfigstayed clean each timegit config --get-all), andgh auth statusstill reports logged in over https🤖 Generated with Claude Code