-
Notifications
You must be signed in to change notification settings - Fork 0
feat: worktree scripts #126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,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 | ||
|
Comment on lines
+32
to
+41
|
||
|
|
||
| # 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" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Usage: yarn remove-worktree feat/31-my-feature | ||
|
|
||
| BRANCH=$1 | ||
| WORKTREE_DIR="../wt-$(echo $BRANCH | sed 's/\//-/g')" | ||
|
|
||
| if [ -z "$BRANCH" ]; then | ||
| echo "❌ Please provide a branch name" | ||
| echo "Usage: yarn remove-worktree feat/my-feature" | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [ ! -d "$WORKTREE_DIR" ]; then | ||
| echo "❌ Worktree directory $WORKTREE_DIR does not exist" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Remove the worktree | ||
| git worktree remove "$WORKTREE_DIR" | ||
|
|
||
| # Delete the branch | ||
| git branch -d $BRANCH | ||
|
|
||
| echo "🗑️ Worktree $WORKTREE_DIR removed and branch $BRANCH deleted" | ||
|
Comment on lines
+19
to
+25
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.