gh-112431: Unconditionally call `hash -r` (GH-112432)

The `activate` script calls `hash -r` in two places to make sure the shell picks
up the environment changes the script makes. Before that, it checks to
see if the shell running the script is bash or zsh.

`hash -r` is specified by POSIX and is not exclusive to bash and zsh.
This guard prevents the script from calling `hash -r` in other
`#!/bin/sh`-compatible shells like dash.
This commit is contained in:
James Morris 2023-11-28 04:24:59 -05:00 committed by GitHub
parent f14d741daa
commit a194938f33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 10 deletions

View File

@ -14,12 +14,9 @@ deactivate () {
unset _OLD_VIRTUAL_PYTHONHOME
fi
# This should detect bash and zsh, which have a hash command that must
# be called to get it to forget past commands. Without forgetting
# Call hash to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
hash -r 2> /dev/null
fi
hash -r 2> /dev/null
if [ -n "${_OLD_VIRTUAL_PS1:-}" ] ; then
PS1="${_OLD_VIRTUAL_PS1:-}"
@ -69,9 +66,6 @@ if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then
export PS1
fi
# This should detect bash and zsh, which have a hash command that must
# be called to get it to forget past commands. Without forgetting
# Call hash to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
hash -r 2> /dev/null
fi
hash -r 2> /dev/null