-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworktree-new.sh
More file actions
executable file
·55 lines (42 loc) · 1.75 KB
/
Copy pathworktree-new.sh
File metadata and controls
executable file
·55 lines (42 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
# Usage: source worktree-new.sh <branch-name>
# Creates a git worktree with an isolated Neon DB branch.
# Must be sourced (not executed) to cd into the new worktree.
worktree_new() {
set -euo pipefail
local MAIN_REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
local BRANCH_NAME="${1:-}"
if [[ -z "$BRANCH_NAME" ]]; then
echo "Usage: source worktree-new.sh <branch-name>"
return 1
fi
local WORKTREE_PATH="$MAIN_REPO/../personal-finance-visoneer-$BRANCH_NAME"
if [[ -d "$WORKTREE_PATH" ]]; then
echo "Error: Worktree already exists at $WORKTREE_PATH"
return 1
fi
echo "Creating worktree for branch: $BRANCH_NAME"
git worktree add "$WORKTREE_PATH" -b "$BRANCH_NAME"
# Copy IDE settings
mkdir -p "$WORKTREE_PATH/.vscode"
cp "$MAIN_REPO/.vscode/settings.json" "$WORKTREE_PATH/.vscode/" 2>/dev/null && echo " ✓ .vscode/settings.json" || true
mkdir -p "$WORKTREE_PATH/.claude"
ln -sf "$MAIN_REPO/.claude/settings.local.json" "$WORKTREE_PATH/.claude/settings.local.json" 2>/dev/null && echo " ✓ .claude/settings.local.json (symlinked)" || true
# Copy .env.local (non-DB vars like auth secrets, stripe keys)
# db-branch-create.sh will replace DATABASE_URL with the branch connection
if [[ -f "$MAIN_REPO/.env.local" ]]; then
cp "$MAIN_REPO/.env.local" "$WORKTREE_PATH/.env.local"
echo " ✓ .env.local (copied)"
fi
# Install dependencies
echo "Installing dependencies..."
(cd "$WORKTREE_PATH" && bun install)
# Create isolated Neon branch + update DB connection + run migrations
(cd "$WORKTREE_PATH" && bash scripts/db-branch-create.sh)
echo ""
echo "✓ Worktree ready!"
echo " Git branch: $BRANCH_NAME"
echo " DB branch: dev/$BRANCH_NAME"
cd "$WORKTREE_PATH"
}
worktree_new "$@"