From b273db3fec6f107aa5f640a5614681b6c293bd0e Mon Sep 17 00:00:00 2001 From: Zi Makki Date: Sun, 12 Jul 2026 23:47:18 +0200 Subject: [PATCH] fix(bootstrap): derive preflight root before function entry --- scripts/bootstrap/preflight.zsh | 9 +++++++-- tests/bootstrap/isolated.sh | 8 ++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/scripts/bootstrap/preflight.zsh b/scripts/bootstrap/preflight.zsh index ca98b02..70ddd35 100755 --- a/scripts/bootstrap/preflight.zsh +++ b/scripts/bootstrap/preflight.zsh @@ -3,8 +3,13 @@ # bootstrap exception. Source this file to call # bootstrap_require_canonical_checkout; execute it for the full preflight. +# Capture the source path before entering a function. With Zsh's default +# FUNCTION_ARGZERO behavior, $0 becomes the function name inside a function +# and cannot be used to locate this file reliably. +typeset -g _DOTFILES_PREFLIGHT_REPO="${${(%):-%N}:A:h:h:h}" + bootstrap_require_canonical_checkout() { - local repo="${1:-${0:A:h:h:h}}" + local repo="${1:-$_DOTFILES_PREFLIGHT_REPO}" local git_dir common_dir_raw common_dir repo="$(cd "$repo" && pwd -P)" || return 1 @@ -35,7 +40,7 @@ bootstrap_preflight_main() { set -u setopt pipe_fail - local repo="${0:A:h:h:h}" + local repo="$_DOTFILES_PREFLIGHT_REPO" if [[ "${1:-}" == "--guard-only" ]]; then (( $# <= 2 )) || { print -u2 -- "usage: $0 --guard-only [repo]" diff --git a/tests/bootstrap/isolated.sh b/tests/bootstrap/isolated.sh index 89b502a..ef531a9 100755 --- a/tests/bootstrap/isolated.sh +++ b/tests/bootstrap/isolated.sh @@ -114,7 +114,7 @@ text = re.sub( path.write_text(text) PY printf '# intentionally empty fixture\n' > "$guard_primary/BrewFile" -ln -s "$repo/scripts/bootstrap/preflight.zsh" \ +cp "$repo/scripts/bootstrap/preflight.zsh" \ "$guard_primary/scripts/bootstrap/preflight.zsh" git -C "$guard_primary" add fixture mise.toml BrewFile zshenv config/zsh/zshenv \ scripts/bootstrap/preflight.zsh scripts/bootstrap/json-overlay.py \ @@ -123,12 +123,12 @@ git -C "$guard_primary" -c user.name=Bootstrap -c user.email=bootstrap@example.i commit --quiet -m fixture git -C "$guard_primary" worktree add --quiet -b linked-test "$guard_linked" guard_linked_real="$(cd "$guard_linked" && pwd -P)" -zsh "$repo/scripts/bootstrap/preflight.zsh" --guard-only "$guard_primary" -if zsh "$repo/scripts/bootstrap/preflight.zsh" --guard-only "$guard_linked" >/dev/null 2>&1; then +zsh "$guard_primary/scripts/bootstrap/preflight.zsh" --guard-only +if zsh "$guard_linked/scripts/bootstrap/preflight.zsh" --guard-only >/dev/null 2>&1; then fail "mutation guard accepted a linked worktree" fi DOTFILES_BOOTSTRAP_TEST_ALLOW_WORKTREE=1 \ - zsh "$repo/scripts/bootstrap/preflight.zsh" --guard-only "$guard_linked" >/dev/null + zsh "$guard_linked/scripts/bootstrap/preflight.zsh" --guard-only >/dev/null pass "canonical checkout passes, linked worktree fails, explicit test override passes" guard_home="$root/guard-home"