#!/usr/bin/env bash # Scrubs git's repo-locating environment variables from the current shell, so # every git process it spawns -- directly or through another tool -- discovers # its repository from its own working directory. Issue #204. # # Why: `git push` from a LINKED worktree exports an absolute # GIT_DIR=
/.git/worktrees/ to its hooks (from the main checkout it # exports none). A hook that runs a tool which itself runs git in a temp dir -- # apm's drift replay does `git init` / `git checkout` there with os.environ -- # hands that GIT_DIR on, and the temp-dir git operates on THIS repo instead: # core.bare=true in the shared .git/config, and the worktree's HEAD moved to a # lock-pinned commit. Hooks run from the worktree root, so plain discovery # finds the right repo once these are gone. # # The explicit list runs first so the scrub holds even if `git rev-parse # --local-env-vars` is unavailable; that call then adds anything else git # considers repo-local (GIT_CONFIG_PARAMETERS, GIT_PREFIX, ...), making the # result a superset of the explicit list. # # Not meant to be executed directly -- source it before any git call. unset GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE GIT_OBJECT_DIRECTORY GIT_COMMON_DIR for _clean_git_env_var in $(git rev-parse --local-env-vars 2>/dev/null); do unset "$_clean_git_env_var" done unset _clean_git_env_var