Repository navigation
fix: preserve the source Git index during version detection - #805
Merged
Merged
Conversation
tsnaik
requested review from
hallyn,
mikemccracken,
raharper,
rchamarthy,
rchincha,
smoser and
tych0
as code owners
October 1, 2026 02:13
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #805 +/- ##
==========================================
+ Coverage 54.87% 54.97% +0.10%
==========================================
Files 55 55
Lines 5910 5910
==========================================
+ Hits 3243 3249 +6
+ Misses 2094 2088 -6
Partials 573 573 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
raharper
requested changes
Oct 1, 2026
raharper
left a comment
Contributor
There was a problem hiding this comment.
Thanks for finding this. Can we add a bats test for this one; it certainly seems like we can catch it rewriting the index today with a test case; and then with your change confirm that we no longer update the index.
tsnaik
force-pushed
the
fix-git-index-refresh
branch
from
October 1, 2026 18:16
3dde7fa to
0aca6a2
Compare
raharper
requested changes
Oct 2, 2026
raharper
left a comment
Contributor
There was a problem hiding this comment.
Thanks for updating the go test and adding the bats test. couple more things in the bats test to confirm.
During rootless builds, GitVersion runs `git status` inside the user namespace. It refreshes the index as an optional side effect, rewriting the cached uid/gid of every tracked file as 0/0. Host git then sees a stat mismatch and rereads every file. Pass --no-optional-locks so `git status` doesn't write the index. This needs git >= 2.15. test/git-index.bats fails without this change: before: uid: 1003 gid: 1002 after: uid: 0 gid: 0 Signed-off-by: Tanmay Naik <tnaik96@gmail.com>
tsnaik
force-pushed
the
fix-git-index-refresh
branch
from
October 2, 2026 17:45
0aca6a2 to
62a0ff9
Compare
raharper
approved these changes
Oct 7, 2026
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.
What type of PR is this?
bug
Which issue does this PR fix?
No issue filed. Repro steps are below.
What does this PR do / Why do we need it?
During rootless builds,
GitVersionrunsgit statusinside a user namespace.git statusrefreshes the index as an optional side effect, so it writes the namespace UID/GID (0:0) into the source repo's.git/index. After that, host Git sees a stat mismatch on every tracked file and rereads them, which is slow on large repos. File contents and ownership don't change.This passes
--no-optional-lockstogit statusso it no longer writes the index.-dirtydetection works the same as before.If an issue # is not available please add repro steps and logs showing the issue:
Run as a non-root user:
Testing done on this change:
Ran the repro above with both binaries:
Same-revision rootless builds, clean and dirty:
OCI Git annotations were correct for both clean and dirty builds.
Automation added to e2e:
test/git-index.bats(unprivileged): creates a Git repo and checks that the build user owns the committed file, then runs a rootlessstacker build -f, and checks two things: the file's cached uid/gid in the index still matches the file's real owner, and the hash of.git/indexis unchanged.TestGitVersionPreservesIndex, plus a control test,TestGitStatusRefreshesStaleIndex, which shows that plaingit statusdoes rewrite a stale index.Without the fix:
With the fix:
Will this break upgrades or downgrades?
No. No image format, config, or CLI changes.
Does this PR introduce any user-facing change?
Yes, a bug fix.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.