git🐮 Fix GIT_DIR for submodules via git alias
Git sets some environment variables when executing a shell command. Specifically it sets GIT_DIR when called inside a submodule. This makes git inside the subshell target the main worktree instead of the temporary one.
This commit is contained in:
@@ -60,6 +60,17 @@ until [[ -d $cwd_offset || -z $cwd_offset ]]; do
|
||||
done
|
||||
[[ -z $cwd_offset ]] || cd "$cwd_offset"
|
||||
|
||||
# Discard some environment variables that were set by git when calling this
|
||||
# script through an alias.
|
||||
#
|
||||
# Is set for submodules and will confuse git in the subshell
|
||||
unset GIT_DIR
|
||||
# Not sure if this can bring any issues, but better be safe
|
||||
unset GIT_PREFIX
|
||||
# TODO: Do we want to unset this too? Could have been set on purpose by the user
|
||||
# and not git. Maybe only for the subshell via `env`?
|
||||
#unset GIT_EXEC_PATH
|
||||
|
||||
"$SHELL" && errc=$? || errc=$?
|
||||
(( !errc )) || echo "shell exited with $errc"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user