fix: don't override existing ASDF_DIR (#1008)

This commit is contained in:
Eric Nielsen 2021-11-02 17:47:43 -05:00 committed by GitHub
parent 69ff2d0c9a
commit 73efc9fa97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 8 deletions

20
asdf.sh
View File

@ -3,16 +3,18 @@
# For Bash, ${BASH_SOURCE[0]} will be used to obtain this script's path.
# For Zsh and others, $0 (the path to the shell or script) will be used.
_under="$_"
if [ "${BASH_SOURCE[0]}" != "" ]; then
current_script_path="${BASH_SOURCE[0]}"
elif [[ "$_under" == *".sh" ]]; then
current_script_path="$_under"
else
current_script_path="$0"
fi
if [ -z "$ASDF_DIR" ]; then
if [ -n "${BASH_SOURCE[0]}" ]; then
current_script_path="${BASH_SOURCE[0]}"
elif [[ "$_under" == *".sh" ]]; then
current_script_path="$_under"
else
current_script_path="$0"
fi
ASDF_DIR="$(dirname "$current_script_path")"
fi
export ASDF_DIR
ASDF_DIR="$(dirname "$current_script_path")"
# shellcheck disable=SC2016
[ -d "$ASDF_DIR" ] || echo '$ASDF_DIR is not a directory'
@ -31,3 +33,5 @@ PATH="${ASDF_USER_SHIMS}:$PATH"
# shellcheck source=lib/asdf.sh
# Load the asdf wrapper function
. "${ASDF_DIR}/lib/asdf.sh"
unset _under current_script_path ASDF_BIN ASDF_USER_SHIMS

View File

@ -21,6 +21,9 @@ setup() {
mkdir -p $CHILD_DIR
cd $PROJECT_DIR
# asdf lib needed to run asdf.sh
cp -rf $BATS_TEST_DIRNAME/../{bin,lib} $ASDF_DIR/
}
teardown() {