fix(hooks): keep git -c overrides when scrubbing apm's git env

Why: the `git rev-parse --local-env-vars` loop in clean-git-env.sh also
unset GIT_CONFIG_PARAMETERS / GIT_CONFIG_COUNT, silently dropping `git -c`
overrides (extraHeader, credentials, safe.directory) that apm's remote
clones may need. Only the repo-locating vars caused #204.

Implementation Notes:
- clean-git-env.sh now unsets an explicit list only: GIT_DIR,
  GIT_WORK_TREE, GIT_INDEX_FILE, GIT_OBJECT_DIRECTORY, GIT_COMMON_DIR,
  GIT_PREFIX, GIT_IMPLICIT_WORK_TREE; gates.md updated to match.
- apm-pack-check-clean.sh points at the real gates.md paragraph.
- run-tests.sh's comment now says git exports GIT_DIR to hooks only from
  a linked worktree, matching LESSONS.md.
- test-apm-hooks-git-env.sh isolates from global/system git config.
- Reflow the "Two of these shell out to apm" paragraph in gates.md.

Refs #204

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
This commit is contained in:
Defame1297andClaude Opus 5.5 committed 2026-11-26 23:35:31 +00:00
1 parent f2c483ca2c
commit 190d9fb322
5 files changed
+16 -18

No files matched your search

+6 -5
View File
@@ -89,9 +89,9 @@ version-blind, so a stale key deploys fine (see [apm gates](#apm-gates)).
Two of these shell out to `apm`: `apm-audit-ci` and `apm-pack-check-clean`. The second is
`scripts/apm-pack-check-clean.sh`, a one-call wrapper, and the first is `scripts/apm-audit-ci.sh`,
which calls `apm` once per manifest, so
without the CLI on PATH the push dies on a "command not found" from inside the hook. Install with `apm-install`, or
`curl -sSL https://aka.ms/apm-unix | sh`; verify with `apm --version`.
which calls `apm` once per manifest, so without the CLI on PATH the push dies on a "command not
found" from inside the hook. Install with `apm-install`, or `curl -sSL https://aka.ms/apm-unix | sh`;
verify with `apm --version`.
### `check-skill-version-bump`
@@ -1166,8 +1166,9 @@ directory. Costs ~0.5s per package.
**apm runs with git's repo-locating env scrubbed.** Both apm hooks source
`scripts/lib/clean-git-env.sh` before calling `apm`, which unsets `GIT_DIR`, `GIT_WORK_TREE`,
`GIT_INDEX_FILE`, `GIT_OBJECT_DIRECTORY`, `GIT_COMMON_DIR` and everything else
`git rev-parse --local-env-vars` lists. The reason: `git push` from a **linked worktree** exports an
`GIT_INDEX_FILE`, `GIT_OBJECT_DIRECTORY`, `GIT_COMMON_DIR`, `GIT_PREFIX` and
`GIT_IMPLICIT_WORK_TREE`. It deliberately keeps the config-passing vars (`GIT_CONFIG_PARAMETERS`,
`GIT_CONFIG_COUNT`), because they carry `git -c` overrides apm's remote clones may need. The reason: `git push` from a **linked worktree** exports an
absolute `GIT_DIR=<main>/.git/worktrees/<name>` to its hooks, and from the main checkout it exports
none. `drift`'s install replay (apm 0.28.0) runs `git init` and `git checkout` in a temp dir with an
env copied from `os.environ`, so the inherited `GIT_DIR` wins. The `init` wrote `core.bare=true` into