Fix Git sync when server-spawned Git needs SSH or credential-helper env#310
Closed
ron-ulitsky wants to merge 2 commits into
Closed
Fix Git sync when server-spawned Git needs SSH or credential-helper env#310ron-ulitsky wants to merge 2 commits into
ron-ulitsky wants to merge 2 commits into
Conversation
|
I could not sync this public PR into Patch application failed. The diff could not be applied cleanly. Try rebasing your PR on the latest base branch. |
Contributor
|
Thanks @ron-ulitsky, first contributor. We'll take a look at this asap and also check the PR bridge (context: we sync this to a private monorepo that has all projects for our company). |
Contributor
|
Hey @ron-ulitsky, thanks for the PR a fix for this will be included in the next release |
inkeep-oss-sync Bot
pushed a commit
that referenced
this pull request
Jun 26, 2026
…(#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
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.
Git auto-sync now preserves the environment Git needs to authenticate when the server fetches or pushes a repository.
The server previously spawned Git with a small environment. That worked for token-backed HTTPS paths, but it broke remotes that depend on the user's home directory, SSH agent, or credential-helper environment. On Windows with an SSH remote,
ok syncand editor sync could fail with:The same
git fetchorgit pushworked from a terminal.This change keeps the user/home/session variables Git uses to locate SSH keys, SSH agents, and credential helpers. Commit author/committer overrides now merge into that preserved environment, so auto-save commits do not drop auth state before push.
GIT_TERMINAL_PROMPT=0and locale-stable stderr behavior stay unchanged.GIT_SSH_COMMANDstill does not pass through without simple-git's explicit unsafe opt-in.Testing:
npx -y bun@1.3.13 test packages/server/src/git-handle.test.tsgit diff --checkbun install --frozen-lockfilebun run lintManual verification on Windows:
ok sync --jsonsucceeds against an SSH remoteconsecutiveFailures: 0Notes:
bun run checkin a fresh Linux container hit existing upstream failures. The samesync-engine.test.tsfailures reproduce oninkeep/open-knowledge@main, so they are not introduced by this branch.