Skip to content

Commit 7aa99ac

Browse files
committed
Add agent instructions for managing worktrees
1 parent ce29f88 commit 7aa99ac

4 files changed

Lines changed: 107 additions & 0 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
.dev.env
1313
.mint
1414

15+
# Worktrees
16+
**/worktrees/
17+
1518
# Node / pnpm
1619
node_modules/
1720
.pnpm-store/

AGENTS.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,52 @@ For cross-platform changes, use the repo-wide aggregates: `dev lint`,
3939
`dev <platform> format` for formatting; `fix` remains an alias for existing
4040
workflows.
4141
42+
## Worktrees
43+
44+
Use git worktrees to isolate feature work. **Auto-create a worktree** when
45+
starting a self-contained task that benefits from isolation (a new feature or a
46+
standalone fix) — you don't need to ask first.
47+
48+
- **Location:** create worktrees under a `worktrees/` directory at the repo
49+
root. `**/worktrees/` is gitignored, so worktree checkouts never appear as
50+
untracked changes.
51+
- **Branch naming:** name branches `<area>/<topic>`, where `<area>` is the
52+
platform or subsystem and `<topic>` is a short kebab-case description.
53+
Examples: `web/css-minify`, `swift/deeplink-cancel`,
54+
`protocol/full-envelope`, `android/maven-local-fix`, `ci/draft-pr-checks`.
55+
- **Creating:** mirror the branch in the directory path, e.g.
56+
```bash
57+
git worktree add worktrees/web/css-minify -b web/css-minify
58+
```
59+
60+
### Before running `dev up` in a new worktree
61+
62+
A fresh worktree is a clean checkout and does **not** include the gitignored
63+
root `.env` that sample app setup reads from. From inside the new worktree, run:
64+
65+
```bash
66+
dev copy-env # copies the root .env (and other root-level config) from the main checkout
67+
dev up # regenerates all nested sample config (Android/Swift/RN) from it
68+
```
69+
70+
`dev copy-env` copies only the root-level source-of-truth files; `dev up`'s
71+
`setup_storefront_env` step regenerates the nested sample configuration
72+
(Android `.env`, Swift `Storefront.xcconfig`, RN sample `.env`) from the root
73+
`.env`, so those do not need to be copied by hand. Treat all of these as
74+
sensitive (see **Sensitive configuration**) — never print or commit their
75+
contents. Remember the `shadowenv exec --dir <worktree_path> --` prefix when
76+
running these outside an interactive shell.
77+
78+
### Cleanup
79+
80+
When the branch has merged or the work is abandoned, remove the worktree and
81+
delete the branch:
82+
83+
```bash
84+
git worktree remove worktrees/<area>/<topic> # add --force if it has throwaway changes
85+
git branch -d <area>/<topic>
86+
```
87+
4288
## Swift Xcode builds
4389

4490
Prefer the `dev swift ...` commands for Swift package and sample builds. When

dev.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ commands:
6464
*) echo "Usage: dev codegen <kotlin|swift|typescript>"; exit 1 ;;
6565
esac
6666
67+
copy-env:
68+
desc: Copy the root .env into the current worktree so `dev up` can regenerate sample config
69+
run: ./scripts/copy_worktree_env
70+
6771
format:
6872
desc: Auto-format and apply safe lint autocorrections across supported workspaces
6973
aliases: [fix]

scripts/copy_worktree_env

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
# This command prints file paths and status only; it never prints configured
10+
# values.
11+
12+
CURRENT_ROOT="$(git rev-parse --show-toplevel)"
13+
COMMON_GIT_DIR="$(git rev-parse --path-format=absolute --git-common-dir)"
14+
MAIN_ROOT="$(dirname "${COMMON_GIT_DIR}")"
15+
16+
if [[ "${CURRENT_ROOT}" == "${MAIN_ROOT}" ]]; then
17+
echo "Already in the main checkout (${CURRENT_ROOT}); nothing to copy."
18+
exit 0
19+
fi
20+
21+
# Root-level, gitignored source-of-truth files. Nested sample config
22+
# (Android/Swift/RN) is intentionally omitted: `dev up` regenerates it from the
23+
# root .env via scripts/setup_storefront_env.
24+
ROOT_FILES=(
25+
".env"
26+
".dev.env"
27+
"local.properties"
28+
)
29+
30+
copied_any="false"
31+
32+
for rel in "${ROOT_FILES[@]}"; do
33+
src="${MAIN_ROOT}/${rel}"
34+
dest="${CURRENT_ROOT}/${rel}"
35+
36+
if [[ ! -e "${src}" ]]; then
37+
continue
38+
fi
39+
40+
if [[ -e "${dest}" ]]; then
41+
echo "skip (exists): ${rel}"
42+
continue
43+
fi
44+
45+
cp "${src}" "${dest}"
46+
echo "copied: ${rel}"
47+
copied_any="true"
48+
done
49+
50+
if [[ "${copied_any}" != "true" ]]; then
51+
echo "No new root env files to copy."
52+
fi
53+
54+
echo "Next: run \`dev up\` in this worktree to regenerate sample app config."

0 commit comments

Comments
 (0)