Repository navigation
Clear inherited GIT_DIR, GIT_INDEX_FILE and GIT_DIFF_OPTS before running git - #184
Merged
Merged
Conversation
…ing git [patch] The environment overlay set only GIT_TERMINAL_PROMPT and LC_ALL, so a process running inside a git hook passed the hook's GIT_DIR and GIT_INDEX_FILE to every git child. Those beat -C, so every verb read (and the mutating verbs wrote) the hook's repository. GIT_DIFF_OPTS likewise beat the -U that Patch() always passes, producing zero-context hunks that Apply rejects. The overlay now removes the repository-locating variables and GIT_DIFF_OPTS. Fixes #139 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01B6YhFsbKVvV6YZVxUJzexE
|
This was referenced 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.



Fixes #139
What changed
RunCommandGitProcessRunner.EnvironmentOverlaynow sets these variables tonull, which makesktsu.RunCommand(1.5.0, the version pinned inDirectory.Packages.props) remove them from the child process's environment:GIT_DIR,GIT_WORK_TREE,GIT_INDEX_FILE,GIT_OBJECT_DIRECTORY,GIT_ALTERNATE_OBJECT_DIRECTORIES,GIT_COMMON_DIR,GIT_NAMESPACE,GIT_PREFIX,GIT_DIFF_OPTS-C, and git exports them to hooks. A .NET tool running from a hook that opened a different repository read that hook's repository, and the mutating verbs would have written to it.GIT_DIFF_OPTStakes priority over the-UthatPatch()always passes. It could produce zero-context hunks, whichApplyrejects.GIT_EXTERNAL_DIFFis left alone, because--no-ext-diffalready neutralises it.Tests
GitInheritedEnvironmentTests(integration tests,[DoNotParallelize]because they set variables on the shared test process and restore them afterwards):InheritedGitDirAndIndexFileDoNotRedirectTheVerbsAsync: setsGIT_DIRandGIT_INDEX_FILEto point at another repository.Status()andPatch()still report onlyB.txtin the repository that was opened.InheritedGitDiffOptsDoesNotStripPatchContextAsync: setsGIT_DIFF_OPTS=-u0.Patch().WithContext(3)still returns@@ -1,5 +1,5 @@, andApply().ToIndex()succeeds.EnvironmentOverlayRemovesVariablesThatOverrideTheArgumentschecks that each key is in the overlay with a null value.A.txtandB.txt("Sequence contains more than one element"), and the hunk started at line 3 rather than 1. Both passed again once the change was restored.KTSU_GIT_INTEGRATION_TESTS_REQUIRED=1: 757/757 passing locally, none skipped.🤖 Generated with Claude Code
https://claude.ai/code/session_01B6YhFsbKVvV6YZVxUJzexE
Generated by Claude Code