#!/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. # # Config-passing vars (GIT_CONFIG_PARAMETERS, GIT_CONFIG_COUNT) are kept on purpose: they carry `git -c` overrides apm's remote clones may need. # # 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 \ GIT_PREFIX GIT_IMPLICIT_WORK_TREE