-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew-worktree.sh
More file actions
executable file
·51 lines (41 loc) · 1.44 KB
/
new-worktree.sh
File metadata and controls
executable file
·51 lines (41 loc) · 1.44 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
#!/bin/bash
# Usage: yarn new-worktree feat/31-my-feature
BRANCH=$1
MAIN_REPO=$(pwd)
WORKTREE_DIR="../wt-$(echo $BRANCH | sed 's/\//-/g')"
if [ -z "$BRANCH" ]; then
echo "❌ Please provide a branch name"
echo "Usage: yarn new-worktree feat/my-feature"
exit 1
fi
# Create the worktree and branch
git worktree add -b $BRANCH $WORKTREE_DIR main
# Copy .vscode if present
if [ -d "$MAIN_REPO/.vscode" ]; then
cp -r "$MAIN_REPO/.vscode" "$WORKTREE_DIR/.vscode"
else
echo "ℹ️ No .vscode directory found in main repo, skipping copy."
fi
# Copy all .env files
for env_file in "$MAIN_REPO"/.env*; do
[ -f "$env_file" ] && cp "$env_file" "$WORKTREE_DIR/$(basename $env_file)"
done
# Copy node_modules via hard links (fast, minimal disk usage)
# Fall back to yarn install if node_modules doesn't exist in main repo
if [ -d "$MAIN_REPO/node_modules" ]; then
echo "📦 Hard-linking node_modules..."
if ! cp -rl "$MAIN_REPO/node_modules" "$WORKTREE_DIR/node_modules"; then
echo "⚠️ Hard-linking node_modules failed, running yarn install..."
(cd "$WORKTREE_DIR" && yarn install)
fi
else
echo "📦 node_modules not found in main repo, running yarn install..."
(cd "$WORKTREE_DIR" && yarn install)
fi
# Open in VSCode
if command -v code &> /dev/null; then
code $WORKTREE_DIR
else
echo "⚠️ VS Code CLI not found. Open the worktree manually: $WORKTREE_DIR"
fi
echo "✅ Worktree ready at $WORKTREE_DIR on branch $BRANCH"