Skip to content

Commit d9e3520

Browse files
authored
Merge pull request #303 from ably/worktree-support
Add git hooks for automatic worktree setup
2 parents 91034cf + f485e58 commit d9e3520

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

.githooks/post-checkout

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/sh
2+
#
3+
# post-checkout hook: set up worktrees after creation
4+
# Copies .env from the main worktree and runs pnpm install.
5+
#
6+
# Arguments: $1=prev HEAD, $2=new HEAD, $3=branch flag (1=branch checkout, 0=file checkout)
7+
8+
# Only run on branch checkouts
9+
[ "$3" = "1" ] || exit 0
10+
11+
# Detect if this is a worktree (not the main working tree)
12+
main_worktree="$(git worktree list --porcelain | head -1 | sed 's/^worktree //')"
13+
current_worktree="$(git rev-parse --show-toplevel)"
14+
15+
[ "$main_worktree" != "$current_worktree" ] || exit 0
16+
17+
# Copy .env from the main worktree if it exists and we don't already have one
18+
if [ -f "$main_worktree/.env" ] && [ ! -f "$current_worktree/.env" ]; then
19+
cp "$main_worktree/.env" "$current_worktree/.env"
20+
echo "post-checkout: copied .env from main worktree"
21+
fi
22+
23+
# Run pnpm install if node_modules doesn't exist
24+
if [ ! -d "$current_worktree/node_modules" ]; then
25+
echo "post-checkout: running pnpm install..."
26+
cd "$current_worktree" && pnpm install
27+
fi

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ tsconfig.tsbuildinfo
5151

5252
# Claude local settings
5353
.claude/*.local.json
54+
.claude/worktrees/
5455

5556
# Playwright logs
5657
playwright-report/

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"test:coverage:report": "vitest run --coverage --reporter=html",
4949
"test:coverage:check": "vitest run --coverage",
5050
"prepack": "pnpm run build && ([ -f node_modules/.bin/oclif ] && node_modules/.bin/oclif manifest || echo 'Skipping oclif commands in production')",
51-
"prepare": "pnpm run build && CI=true ABLY_INTERACTIVE=false oclif manifest",
51+
"prepare": "[ -d .git ] && [ -d .githooks ] && git config core.hooksPath .githooks || true; pnpm run build && CI=true ABLY_INTERACTIVE=false oclif manifest",
5252
"postinstall": "[ \"$CI\" = \"true\" ] || (test -f ./dist/scripts/postinstall-welcome.js && node ./dist/scripts/postinstall-welcome.js || echo \"Skipping welcome script (not found)\")",
5353
"preversion": "pnpm run prepare",
5454
"version": "oclif readme && git add README.md",

0 commit comments

Comments
 (0)