Resolve the repository from the invoking directory
A task included from the global mise config runs with the config root as its working directory - $HOME - rather than the directory the user invoked it from. Deriving the repository from the current directory therefore failed everywhere except a project-level include, which defeats the point of installing the task once and using it in every repository. mise passes the real directory as MISE_ORIGINAL_CWD, so enter it before resolving the repository, falling back to the current directory when the task is run directly rather than through mise.
This commit is contained in:
Executable
+48
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# shellcheck source-path=SCRIPTDIR
|
||||
# shellcheck source=tasks/ai/sbx
|
||||
source "$(dirname "${BASH_SOURCE[0]}")/../tasks/ai/sbx"
|
||||
|
||||
failures=0
|
||||
work="$(mktemp -d)"
|
||||
trap 'rm -rf "$work"' EXIT
|
||||
|
||||
fail() {
|
||||
printf 'FAIL: %s\n' "$1" >&2
|
||||
failures=$((failures + 1))
|
||||
}
|
||||
|
||||
mkdir -p "$work/invoked" "$work/elsewhere"
|
||||
|
||||
(
|
||||
cd "$work/elsewhere"
|
||||
MISE_ORIGINAL_CWD="$work/invoked"
|
||||
export MISE_ORIGINAL_CWD
|
||||
enter_invocation_directory
|
||||
[[ "$PWD" == "$work/invoked" ]]
|
||||
) || fail "did not enter MISE_ORIGINAL_CWD"
|
||||
|
||||
(
|
||||
cd "$work/elsewhere"
|
||||
unset MISE_ORIGINAL_CWD
|
||||
enter_invocation_directory
|
||||
[[ "$PWD" == "$work/elsewhere" ]]
|
||||
) || fail "did not stay in PWD when MISE_ORIGINAL_CWD is unset"
|
||||
|
||||
if (
|
||||
cd "$work/elsewhere"
|
||||
MISE_ORIGINAL_CWD="$work/does-not-exist"
|
||||
export MISE_ORIGINAL_CWD
|
||||
enter_invocation_directory
|
||||
) 2>/dev/null; then
|
||||
fail "an unusable MISE_ORIGINAL_CWD was accepted"
|
||||
fi
|
||||
|
||||
if ((failures)); then
|
||||
printf '%d assertion(s) failed\n' "$failures" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf 'All invocation directory assertions passed.\n'
|
||||
Reference in New Issue
Block a user