Skip to content

Fix Git auto-sync when server-spawned Git needs the user's home…#331

Merged
inkeep-oss-sync[bot] merged 1 commit into
mainfrom
copybara/sync
Jun 26, 2026
Merged

Fix Git auto-sync when server-spawned Git needs the user's home…#331
inkeep-oss-sync[bot] merged 1 commit into
mainfrom
copybara/sync

Conversation

@inkeep-oss-sync

Copy link
Copy Markdown
Contributor

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 sync and editor sync could fail with "Could not read from remote repository" while the same git fetch or git push worked in a terminal.

Because preserving the home directory also lets server-spawned Git read the user's global config, OK now pins commit.gpgsign=false and core.autocrlf=false for 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.

…(#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

@inkeep-internal-ci inkeep-internal-ci Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@inkeep-oss-sync
inkeep-oss-sync Bot merged commit 952f877 into main Jun 26, 2026
@inkeep-oss-sync
inkeep-oss-sync Bot deleted the copybara/sync branch June 26, 2026 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant