Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122#!/bin/bashset -euo pipefailcd "$(dirname "$0")/.."
if [[ $# -gt 1 || ( $# -eq 1 && $1 != --hooks-only ) ]]; then printf 'Usage: Scripts/setup.sh [--hooks-only]\n' >&2 exit 2firoot=$(git rev-parse --show-toplevel)expected=$(git rev-parse --path-format=absolute --git-path parcel-hooks)status=0current=$(git config --path --get core.hooksPath) || status=$?if (( status > 1 )); then printf 'Could not read the current hooks path.\n' >&2 exit "$status"fiif [[ -n $current && $current != /* ]]; then current="$root/$current"; finames=(pre-commit commit-msg pre-push)verify_hooks() { local directory=$1 name path signature if [[ -L $directory || ( -e $directory && ! -d $directory ) ]]; then printf 'Refusing to replace hook directory at %s.\n' "$directory" >&2 exit 1 fi if [[ -L $directory/.parcel-hook-sha256 || ( -e $directory/.parcel-hook-sha256 && ! -f $directory/.parcel-hook-sha256 ) ]]; then printf 'Refusing to replace hook signatures at %s.\n' "$directory" >&2 exit 1 fi for name in "${names[@]}"; do path="$directory/$name" if [[ -L $path || ( -e $path && ! -f $path ) ]]; then printf 'Refusing to replace hook at %s.\n' "$path" >&2 exit 1 fi if [[ -f $path ]]; then signature=$(shasum -a 256 "$path") if [[ ! -f $directory/.parcel-hook-sha256 || -L $directory/.parcel-hook-sha256 ]] || ! grep -Fxq "$signature" "$directory/.parcel-hook-sha256"; then printf 'Existing %s hook at %s; integrate lefthook there instead.\n' "$name" "$directory" >&2 exit 1 fi fi done}legacy_path=0if [[ ${current##*/} == hooks && -d $(dirname "$current") ]]; then current_parent=$(cd "$(dirname "$current")" && pwd -P) if [[ $current_parent == "$root/Scripts" ]]; then legacy_path=1; fifilegacy_empty=0if [[ $legacy_path == 1 && ! -L $current && ( ! -e $current || -d $current ) ]]; then legacy_empty=1 for path in "$current"/* "$current"/.[!.]* "$current"/..?*; do if [[ -e $path || -L $path ]]; then legacy_empty=0; break; fi donefiif [[ -n $current && $current != "$expected" && $legacy_empty == 0 ]]; then if [[ ( $current != */parcel-hooks && $legacy_path == 0 ) || ! -f $current/.parcel-hook-sha256 ]]; then printf 'Custom hooks already configured at %s; integrate lefthook there instead.\n' "$current" >&2 exit 1 fi for name in "${names[@]}"; do if [[ ! -f $current/$name ]]; then printf 'Incomplete managed hooks at %s; refusing to migrate them.\n' "$current" >&2 exit 1 fi done verify_hooks "$current" for path in "$current"/* "$current"/.[!.]* "$current"/..?*; do [[ -e $path || -L $path ]] || continue case "${path##*/}" in pre-commit|commit-msg|pre-push|.parcel-hook-sha256) ;; *) printf 'Unrelated hook at %s; refusing to migrate it.\n' "$path" >&2; exit 1 ;; esac donefifor directory in "$(git rev-parse --path-format=absolute --git-common-dir)/hooks" "$expected"; do verify_hooks "$directory"done
mise=$(command -v mise || true)if [[ -z $mise && -x ${HOME:?}/.local/bin/mise ]]; then mise="$HOME/.local/bin/mise"; fiif [[ -z $mise || ! -x $mise ]]; then printf 'Missing mise; install it before running Scripts/setup.sh.\n' >&2 exit 1fiif (( $# == 0 )); then PATH="$(dirname "$mise"):$PATH" export PATH Scripts/parcel-dev.sh install-tools "$mise" exec -- Scripts/setup.sh --hooks-only "$mise" run doctor exit 0fi"$mise" exec -- lefthook version >/dev/nullmkdir -p "$expected"for name in "${names[@]}"; do { printf '#!/bin/bash\nset -euo pipefail\n' printf 'installed_mise=%q\n' "$mise" # shellcheck disable=SC2016 printf '%s\n' \ 'mise=$(command -v mise || true)' \ 'if [[ -z $mise && -x ${HOME:?}/.local/bin/mise ]]; then mise="$HOME/.local/bin/mise"; fi' \ 'if [[ -z $mise && -x $installed_mise ]]; then mise=$installed_mise; fi' \ 'if [[ -z $mise || ! -x $mise ]]; then' \ ' printf "Parcel hooks require mise; run Scripts/setup.sh to repair them.\n" >&2' \ ' exit 1' \ 'fi' \ 'PATH="$(dirname "$mise"):$PATH"' \ 'export PATH' # shellcheck disable=SC2016 printf 'exec "$mise" exec -- lefthook run --no-auto-install %q "$@"\n' "$name" } > "$expected/$name" chmod +x "$expected/$name"doneshasum -a 256 "$expected/pre-commit" "$expected/commit-msg" "$expected/pre-push" > "$expected/.parcel-hook-sha256"# Shared hooks are left intact; only this checkout changes its configuration.git config --local extensions.worktreeConfig truegit config --worktree core.hooksPath "$expected"printf 'Installed lefthook checks for this worktree.\n'