Repository navigation
fix(git): keep a caller's GIT_DIR out of skillshare's git commands - #854
Merged
Merged
Conversation
Git exports GIT_DIR, GIT_WORK_TREE, GIT_INDEX_FILE and related variables to hooks that run in a linked worktree. Every git process skillshare started inherited them, and those variables override the directory the command runs in. Run from a post-checkout or post-merge hook, skillshare therefore acted on the hook's repository instead of its own: install's sparse clone turned on sparse checkout there (a later merge removed every file outside the skill's path), the remote tree check's `git init --bare` made it a bare repository, install's reconcile recorded its origin and branch, and push staged and committed into it. internal/gitenv builds git commands without the variables that `git rev-parse --local-env-vars` lists for choosing a repository, work tree, index, object store or config file. GIT_CONFIG_COUNT and GIT_CONFIG_PARAMETERS stay, because users pass credentials through them and install's token auth appends to the existing count. Every git call in cmd/skillshare, internal/install, internal/git, internal/check and internal/config now goes through it, and plugin runCommand starts native CLIs from the same environment because they run git as well. The hooks service keeps its own stricter filter. Closes #852
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Each git call site converted for #852 is safe only because it goes through gitenv.Command, and about half have no test of their own. A future exec.Command("git", ...) would silently bring the bug back, so a syntactic guard now rejects one outside gitenv, hooks and testutil, mirroring the sourcefs and sourcewalk ratchets. The Environ test also checks a lowercase name, since Windows environment names are case-insensitive, and compares against literal keys so that removing one from repoVars fails it. The wiki records the rule.
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.
Type
Summary
Git exports
GIT_DIR,GIT_WORK_TREE,GIT_INDEX_FILEand related variables to hooks in a linked worktree, and they override the directory a git command runs in. Every git process skillshare started inherited them, so skillshare run from apost-checkout/post-mergehook acted on the hook's repository:installsparse subdirectory clone (#852)git init --bare+ fetch)core.bare=trueinstallreconcile of tracked repospushadd -A, commit and push land in itinternal/gitenv:Command/CommandContext/Environdrop the variablesgit rev-parse --local-env-varslists for choosing a repository, work tree, index, object store or config file.GIT_CONFIG_COUNT/GIT_CONFIG_PARAMETERS(andGIT_CONFIG_KEY_n/VALUE_n) are kept: users pass credentials through them, and install's token auth appends to the existing count.cmd/skillshare,internal/install,internal/git,internal/checkandinternal/configgoes through it.internal/pluginrunCommandstarts native CLIs from the same environment, since they run git too.internal/hookskeeps its own strictersanitizedGitEnv(it also drops config variables and forcesLC_ALL=C).Linked Issue
Closes #852
Verification
GIT_DIRas git exports to worktree hooks, against anorigin/mainbinary turned on sparse checkout in the host repo, and a forced checkout removedx/b.TestSparseCloneSubdir_IgnoresCallerGitDir,TestGetCurrentFullHash_IgnoresCallerGitDir,TestFetchRemoteTreeHashes_IgnoresCallerGitDir,TestGitRemoteOrigin_IgnoresCallerGitDir,TestRunCommandDropsTheCallersRepository, and the integration testTestPush_IgnoresCallerGitDir; plusgitenvunit tests for dropped and kept variables.make checkpassed in the devcontainer image;GOOS=windows go build ./...passed.runscripts,mcp check --liveserver probes) still inherit the caller's environment on purpose, matching what a hook running them directly would see. Windows runtime was not exercised.Merge Danger
Low. Environment handling only; no config, file format or flag changes. A user who deliberately set
GIT_DIR/GIT_WORK_TREEto steer skillshare's git commands would no longer have that effect; skillshare always names the repository it works on.Checklist
make check)