Fix git_repository checkouts altered by host line-ending config - #30036
Open
rdesgroppes wants to merge 1 commit into
Open
Fix git_repository checkouts altered by host line-ending config#30036rdesgroppes wants to merge 1 commit into
git_repository checkouts altered by host line-ending config#30036rdesgroppes wants to merge 1 commit into
Conversation
rdesgroppes
force-pushed
the
git-repository-line-endings
branch
from
June 26, 2026 13:26
f3549ee to
44c9547
Compare
rdesgroppes
force-pushed
the
git-repository-line-endings
branch
4 times, most recently
from
June 26, 2026 17:09
4a7b2e3 to
2d7b879
Compare
git_repository checkout depending on host line-ending configgit_repository checkouts altered by host line-ending config
rdesgroppes
marked this pull request as ready for review
June 26, 2026 17:14
`git_repository` and `new_git_repository` shell out to the system git, so their checkout inherits the host's git configuration. `core.autocrlf` and `core.eol` then rewrite line endings on checkout: with `autocrlf=true` (the Git for Windows default), a repository stored with LF is materialized with `CRLF` on one machine and `LF` on another, so a fetch is not reproducible and byte-sensitive rules break. This pushes teams to resort to falling back to `http_archive`, but that workaround doesn't of course apply to transitive `bazel_dep`s. The present fix proposes to pin both knobs for every `git` invocation in `git_worker.bzl`'s `_execute` with both `-c core.autocrlf=false` and `-c core.eol=lf`. A `-c` override outranks every config source (`~/.gitconfig`, `/etc/gitconfig`, `$XDG_CONFIG_HOME/git/config`, ...) and works on git 1.7.2+. The checkout then reproduces the committed bytes: - `LF` stays `LF`, - an **in-tree `.gitattributes` still wins** so a repo keeping `CRLF` via `eol=crlf` is preserved, - a `CRLF` blob is never stripped (the checkout path only ever adds `CR`, never removes it). This is **not** neutralizing config sources: - `GIT_CONFIG_NOSYSTEM=1` would only drop `/etc/gitconfig`, not the user's `~/.gitconfig`, - `GIT_CONFIG_GLOBAL` and `GIT_CONFIG_SYSTEM` (set to `/dev/null`) need git 2.32+, - worse, both of the above would wipe corresponding system-wide and user configs, including environment-sensitive settings such as `core.symlinks`, `credential.helper`, `http.proxy`, etc. The `-c` overrides touch only the two line-ending knobs. There are 2 new black box tests that neutralize, in isolation, an injected host `core.autocrlf` (from `$HOME/.gitconfig`) and `core.eol` (from a `GIT_CONFIG_SYSTEM` file), asserting the checkout is byte-for-byte without shadowing corresponding in-tree `.gitattributes` settings. Fixes bazelbuild#30026 RELNOTES: `git_repository` and `new_git_repository` now check out files with the line endings stored in the repository, regardless of the host git configuration (`core.autocrlf`, `core.eol`).
rdesgroppes
force-pushed
the
git-repository-line-endings
branch
from
June 29, 2026 07:06
2d7b879 to
0faabaf
Compare
tazzledazzle
approved these changes
Aug 20, 2026
|
✅ Bazel docs preview is ready! Preview URL: https://bazel-pr-30036.mintlify.app/ Updated for |
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.
Description
The present fix proposes to pin both knobs for every
gitinvocation ingit_worker.bzl's_executewith both-c core.autocrlf=falseand-c core.eol=lf.A
-coverride outranks every config source (~/.gitconfig,/etc/gitconfig,$XDG_CONFIG_HOME/git/config, ...) and works on git 1.7.2+.The checkout then reproduces the committed bytes:
LFstaysLF,.gitattributesstill wins so a repo keepingCRLFviaeol=crlfis preserved,CRLFblob is never stripped (the checkout path only ever addsCR, never removes it).This is not neutralizing config sources:
GIT_CONFIG_NOSYSTEM=1would only drop/etc/gitconfig, not the user's~/.gitconfig,GIT_CONFIG_GLOBALandGIT_CONFIG_SYSTEM(set to/dev/null) need git 2.32+,core.symlinks,credential.helper,http.proxy, etc.The
-coverrides touch only the two line-ending knobs.There are 2 new black box tests that neutralize, in isolation, an injected host
core.autocrlf(from$HOME/.gitconfig) andcore.eol(from aGIT_CONFIG_SYSTEMfile), asserting the checkout is byte-for-byte without shadowing corresponding in-tree.gitattributessettings.Motivation
Fixes #30026.
git_repositoryandnew_git_repositoryshell out to the system git, so their checkout inherits the host's git configuration.core.autocrlfandcore.eolthen rewrite line endings on checkout: withautocrlf=true(the Git for Windows default), a repository stored with LF is materialized withCRLFon one machine andLFon another, so a fetch is not reproducible and byte-sensitive rules break.This pushes teams to fall back to
http_archive, but that workaround doesn't of course apply to transitivebazel_deps.Build API Changes
No
Checklist
Release Notes
RELNOTES:
git_repositoryandnew_git_repositorynow check out files with the line endings stored in the repository, regardless of the host git configuration (core.autocrlf,core.eol).