Fix Git auto-sync when server-spawned Git needs the user's home…#331
Merged
Conversation
…(#2197) * fix(open-knowledge): preserve git SSH and credential-helper env for server sync Reproduces #310 by Ron Ulitsky against current main. Server-spawned git rebuilt a minimal environment that dropped HOME, SSH_AUTH_SOCK, and the Windows home variables, so SSH remotes and credential helpers could not authenticate (most visibly Windows with an SSH remote). buildGitEnv now preserves the user, home, and SSH auth vars. applyGitEnv merges commit author and committer overrides into that preserved env instead of replacing it, so auth state survives into the subsequent fetch and push. * fix(open-knowledge): pin commit.gpgsign and core.autocrlf off for sync git Preserving HOME (so SSH keys and credential helpers resolve) also lets server-spawned git read the user's global ~/.gitconfig. Two of its directives are unsafe on the unattended sync path: - commit.gpgsign: the merge-resolution git commit would try to GPG-sign with no TTY. Git aborts the commit on sign failure rather than writing it unsigned, so a cache-cold sync tick fails; a success would also sign a bot-authored commit with the user's key. - core.autocrlf: would rewrite content line endings on checkout and merge, fighting OK's byte-exact LF round-trip and churning the file watcher to CRDT path. Pin both off via -c at the createGitInstance level so every server-spawned git command inherits them. -c outranks global config, and the user's own terminal and IDE git stay untouched. * docs(open-knowledge): drop stale no-gitconfig note from buildGitEnv The closing JSDoc sentence claimed server-spawned git must NOT inherit ~/.gitconfig and that the env strip stays minimal. Both are false since buildGitEnv now preserves HOME and the user/SSH auth vars, and the three hazards it listed are handled elsewhere (commit.gpgsign and core.autocrlf pinned off in createGitInstance; url.insteadOf intentionally honored). * docs(open-knowledge): address review feedback on git-handle JSDoc and tests Cloud review (no blocking issues) flagged JSDoc this PR's own changes made stale, plus two polish items: - buildGitEnv: "Four vars must survive" was wrong once the auth-env allowlist (HOME, SSH_AUTH_SOCK, Windows home vars) started surviving too; added the bullet. - RelayGhToken: dropped the "no HOME" framing (HOME is preserved now). The relay still exists because OK's helper has no gh shell-out and server-side resolution guarantees the gh tier regardless of the curated env. - Dropped change-narration "now" from the gpgsign/autocrlf comment. - Added JSDoc to applyGitEnv (merges into handle.env; .env() mutates in place). - Consolidated the test env-isolation helpers into one module-scoped withEnvEntries; removed withEnv and the manual save/restore. GitOrigin-RevId: d74508c98ab30136d4240c144e2cabab99c80485
Contributor
There was a problem hiding this comment.
Automated approval from agents-private public-mirror-sync (run: https://github.com/inkeep/agents-private/actions/runs/28255268402). Source of truth is the monorepo; direct edits on inkeep/open-knowledge are overwritten on next sync.
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.
Fix Git auto-sync when server-spawned Git needs the user's home directory, SSH agent, or credential-helper environment to reach a remote. This most visibly affected Windows repositories using SSH remotes, where
ok syncand editor sync could fail with "Could not read from remote repository" while the samegit fetchorgit pushworked in a terminal.Because preserving the home directory also lets server-spawned Git read the user's global config, OK now pins
commit.gpgsign=falseandcore.autocrlf=falsefor its own Git commands only (via-c, leaving the user's own Git untouched): the first prevents the unattended sync commit from aborting when a global signing config can't prompt for a passphrase, and the second keeps line-ending conversion from churning content against OK's byte-exact round-trip.