diff --git a/AGENTS.md b/AGENTS.md index 67a5fc53..adbe794c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -42,6 +42,9 @@ AWS_ATHENA_WORKGROUP= AWS_ATHENA_SPARK_WORKGROUP= ``` +In a git worktree, run `just worktree-env` once to link the main checkout's +gitignored `.env` into the worktree. + ```bash export $(cat .env | xargs) && uv run pytest tests/pyathena/test_file.py -v ``` diff --git a/justfile b/justfile index 0f89c043..e223f613 100644 --- a/justfile +++ b/justfile @@ -5,6 +5,10 @@ TOX_VERSION := "4.34.1" default: @just --list +# Link the main checkout's gitignored .env into a worktree +worktree-env: + scripts/worktree-env.sh + # Auto-fix formatting and imports format: # TODO: https://github.com/astral-sh/uv/issues/5903 diff --git a/scripts/worktree-env.sh b/scripts/worktree-env.sh new file mode 100755 index 00000000..a8fcd670 --- /dev/null +++ b/scripts/worktree-env.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +set -euo pipefail + +worktree_root=$(git rev-parse --show-toplevel) +common_dir=$(git rev-parse --path-format=absolute --git-common-dir) +main_root=$(cd "$(dirname "$common_dir")" && pwd -P) + +cd "$worktree_root" + +if [ "$(pwd -P)" = "$main_root" ]; then + echo "This is the main checkout; nothing to link." + exit 0 +fi + +if [ -e .env ] && [ ! -L .env ]; then + echo ".env is already a regular file in this worktree; nothing to link." + exit 0 +fi + +if [ ! -f "$main_root/.env" ]; then + echo "error: $main_root/.env does not exist" >&2 + exit 1 +fi + +ln -sfn "$main_root/.env" .env +echo "Linked .env -> $main_root/.env"