Skip to content

Commit 57e30af

Browse files
authored
Add agent instructions for managing worktrees (#404)
1 parent f235e96 commit 57e30af

2 files changed

Lines changed: 87 additions & 0 deletions

File tree

dev.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ up:
2323
- protocol
2424
- platforms/react-native
2525
- platforms/web
26+
- custom:
27+
name: Copy root env into worktree
28+
met?: ./scripts/copy_worktree_env --check
29+
meet: ./scripts/copy_worktree_env
2630
- custom:
2731
name: Run Checkout Kit workspace setup
2832
met?: ./scripts/setup_dev_workspace --check --skip-optional-prompts
@@ -64,6 +68,10 @@ commands:
6468
*) echo "Usage: dev codegen <kotlin|swift|typescript>"; exit 1 ;;
6569
esac
6670
71+
copy-env:
72+
desc: Copy the root .env into the current worktree so `dev up` can regenerate sample config
73+
run: ./scripts/copy_worktree_env
74+
6775
format:
6876
desc: Auto-format and apply safe lint autocorrections across supported workspaces
6977
aliases: [fix]

scripts/copy_worktree_env

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
# Copies the repo-root .env (and other root-level machine-local config, if
6+
# present) from the main checkout into the current git worktree, so that a
7+
# subsequent `dev up` can regenerate all nested sample app configuration from it.
8+
#
9+
# Runs automatically as a `dev up` step. With --check it reports (without
10+
# copying) whether the current worktree is missing any root env files: exit 0
11+
# when nothing is needed (main checkout, or already seeded) and non-zero when a
12+
# copy is required, so it can serve as a `dev up` met? probe.
13+
#
14+
# This command prints file paths and status only; it never prints configured
15+
# values.
16+
17+
mode="copy"
18+
if [[ "${1:-}" == "--check" ]]; then
19+
mode="check"
20+
elif [[ $# -gt 0 ]]; then
21+
echo "Usage: scripts/copy_worktree_env [--check]" >&2
22+
exit 1
23+
fi
24+
25+
CURRENT_ROOT="$(git rev-parse --show-toplevel)"
26+
COMMON_GIT_DIR="$(git rev-parse --path-format=absolute --git-common-dir)"
27+
MAIN_ROOT="$(dirname "${COMMON_GIT_DIR}")"
28+
29+
if [[ "${CURRENT_ROOT}" == "${MAIN_ROOT}" ]]; then
30+
# In the main checkout there is never anything to copy.
31+
[[ "${mode}" == "check" ]] && exit 0
32+
echo "Already in the main checkout (${CURRENT_ROOT}); nothing to copy."
33+
exit 0
34+
fi
35+
36+
# Root-level, gitignored source-of-truth files. Nested sample config
37+
# (Android/Swift/RN) is intentionally omitted: `dev up` regenerates it from the
38+
# root .env via scripts/setup_storefront_env.
39+
ROOT_FILES=(
40+
".env"
41+
".dev.env"
42+
"local.properties"
43+
)
44+
45+
copied_any="false"
46+
47+
for rel in "${ROOT_FILES[@]}"; do
48+
src="${MAIN_ROOT}/${rel}"
49+
dest="${CURRENT_ROOT}/${rel}"
50+
51+
if [[ ! -e "${src}" ]]; then
52+
continue
53+
fi
54+
55+
if [[ -e "${dest}" ]]; then
56+
[[ "${mode}" == "check" ]] && continue
57+
echo "skip (exists): ${rel}"
58+
continue
59+
fi
60+
61+
# A source file exists in the main checkout but is missing here.
62+
if [[ "${mode}" == "check" ]]; then
63+
echo "missing: ${rel}"
64+
exit 1
65+
fi
66+
67+
cp "${src}" "${dest}"
68+
echo "copied: ${rel}"
69+
copied_any="true"
70+
done
71+
72+
# Check mode reached here with nothing missing: the worktree is already seeded.
73+
[[ "${mode}" == "check" ]] && exit 0
74+
75+
if [[ "${copied_any}" != "true" ]]; then
76+
echo "No new root env files to copy."
77+
fi
78+
79+
echo "Next: run \`dev up\` in this worktree to regenerate sample app config."

0 commit comments

Comments
 (0)