Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions scripts/bootstrap/preflight.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]"
Expand Down
8 changes: 4 additions & 4 deletions tests/bootstrap/isolated.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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"
Expand Down
Loading