Skip to content

feat: worktree scripts#126

Open
Alessandro100 wants to merge 4 commits intomainfrom
feat/worktree-scripts
Open

feat: worktree scripts#126
Alessandro100 wants to merge 4 commits intomainfrom
feat/worktree-scripts

Conversation

@Alessandro100
Copy link
Copy Markdown
Contributor

Summary:

Working with git worktrees provides a lot of benefits for parallel work. When adding a git worktree, it excludes files that are in .gitignore. For frontend development, having files like .env, .vscode will set the worktree in a much better place to start working with.

Expected behavior:

When creating a git worktree in this repo, it should come with your .vscode settings, all of your .env and a copy of your node_modules. It should also create a branch. You should also be able to delete the worktree

Testing tips:

In the repo run yarn new-worktree feat/test-branch. It should open a vscode window (if applicable) with your .env and .vscode (if applicable) and your node_modules (if you have them installed). You should be able to run the application right away yarn start:dev

Once you're done testing, run yarn remove-worktree feat/test-branch to clean it up

Please make sure these boxes are checked before submitting your pull request - thanks!

  • Run the unit tests with yarn test to make sure you didn't break anything
  • Add or update any needed documentation to the repo
  • Format the title like "feat: [new feature short description]". Title must follow the Conventional Commit Specification(https://www.conventionalcommits.org/en/v1.0.0/).
  • Linked all relevant issues
  • Include screenshot(s) showing how this pull request works and fixes the issue(s)

@Alessandro100 Alessandro100 self-assigned this Apr 21, 2026
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 21, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
mobilitydatabase-web Ready Ready Preview, Comment Apr 22, 2026 5:09pm

Request Review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds developer-facing Yarn scripts to streamline creating/removing Git worktrees for parallel branch development, including copying common local-only setup files to make a new worktree runnable immediately. (Reviewed with the vercel-react-best-practices skill; this PR is primarily shell tooling and doesn’t touch React/Next patterns.)

Changes:

  • Add yarn new-worktree / yarn remove-worktree commands wired through package.json.
  • Introduce bash scripts to create a worktree + branch, copy .env*/.vscode, and reuse node_modules.
  • Document the workflow in README.md.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
scripts/new-worktree.sh Creates a worktree/branch and copies local dev assets to speed up setup.
scripts/remove-worktree.sh Removes the worktree directory and attempts to delete the local branch.
package.json Exposes the scripts via Yarn commands.
README.md Documents how to create/remove worktrees with the new commands.

Comment on lines +19 to +25
# Remove the worktree
git worktree remove "$WORKTREE_DIR"

# Delete the branch
git branch -d $BRANCH

echo "🗑️ Worktree $WORKTREE_DIR removed and branch $BRANCH deleted"
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git branch -d $BRANCH is unquoted and the script unconditionally prints a success message even if git worktree remove or git branch -d fails (e.g., branch not merged / branch still checked out elsewhere). Add strict error handling or conditional messaging, and pass -- plus quotes to git branch to avoid option parsing issues.

Copilot uses AI. Check for mistakes.
Comment thread scripts/new-worktree.sh
Comment thread scripts/new-worktree.sh
fi

# Create the worktree and branch
git worktree add -b $BRANCH $WORKTREE_DIR main
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git worktree add -b $BRANCH $WORKTREE_DIR main should quote/guard its arguments. Unquoted $BRANCH/$WORKTREE_DIR can be subject to word-splitting/globbing, and branch names starting with - can be parsed as options. Use -- and quote variables when passing them to git.

Copilot uses AI. Check for mistakes.
Comment thread scripts/new-worktree.sh Outdated
Comment thread scripts/new-worktree.sh
Comment on lines +28 to +34
if [ -d "$MAIN_REPO/node_modules" ]; then
echo "📦 Hard-linking node_modules..."
cp -rl "$MAIN_REPO/node_modules" "$WORKTREE_DIR/node_modules"
else
echo "📦 node_modules not found in main repo, running yarn install..."
cd $WORKTREE_DIR && yarn install
fi
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard-linking node_modules can fail (e.g., worktree on a different filesystem -> cross-device link errors), and without strict error handling the script will continue and later print success even if the copy failed. Capture the cp -rl exit status and fall back to yarn install (and quote cd/paths) when hard-linking doesn’t succeed.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented in 320335d. new-worktree.sh now detects cp -rl failure and falls back to yarn install, and the install path uses a quoted subshell (cd "$WORKTREE_DIR" && yarn install) in both fallback paths.

Comment thread scripts/new-worktree.sh Outdated
Comment on lines +15 to +44
# Create the worktree and branch
git worktree add -b $BRANCH $WORKTREE_DIR main

# Copy .vscode
cp -r "$MAIN_REPO/.vscode" "$WORKTREE_DIR/.vscode"

# 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..."
cp -rl "$MAIN_REPO/node_modules" "$WORKTREE_DIR/node_modules"
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"

No newline at end of file
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script doesn’t use strict mode (set -euo pipefail) or explicit error checks. As a result, failures in git worktree add, cp, or yarn install may still lead to the final “Worktree ready” message and leave a partially-created worktree behind. Consider enabling strict mode and/or checking command exit codes, with a cleanup trap if setup fails after creating the worktree.

Copilot uses AI. Check for mistakes.
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ Alessandro100
❌ Copilot
You have signed the CLA already but the status is still pending? Let us recheck it.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 21, 2026

*Lighthouse ran on https://mobilitydatabase-6o4qko2i3-mobility-data.vercel.app/ * (Desktop)
⚡️ HTML Report Lighthouse report for the changes in this PR:

Performance Accessibility Best Practices SEO
🟢 91 🟢 94 🟢 96 🟢 100

*Lighthouse ran on https://mobilitydatabase-6o4qko2i3-mobility-data.vercel.app/feeds * (Desktop)
⚡️ HTML Report Lighthouse report for the changes in this PR:

Performance Accessibility Best Practices SEO
🟠 81 🟠 87 🟢 96 🟢 100

*Lighthouse ran on https://mobilitydatabase-6o4qko2i3-mobility-data.vercel.app/feeds/gtfs/mdb-2126 * (Desktop)
⚡️ HTML Report Lighthouse report for the changes in this PR:

Performance Accessibility Best Practices SEO
🔴 40 🟢 94 🟢 96 🟢 100

*Lighthouse ran on https://mobilitydatabase-6o4qko2i3-mobility-data.vercel.app/feeds/gtfs_rt/mdb-2585 * (Desktop)
⚡️ HTML Report Lighthouse report for the changes in this PR:

Performance Accessibility Best Practices SEO
🟢 99 🟠 84 🟢 96 🟢 100

*Lighthouse ran on https://mobilitydatabase-6o4qko2i3-mobility-data.vercel.app/feeds/gbfs/gbfs-flamingo_porirua * (Desktop)
⚡️ HTML Report Lighthouse report for the changes in this PR:

Performance Accessibility Best Practices SEO
🟠 81 🟢 94 🟢 96 🟢 100

Alessandro100 and others added 4 commits April 22, 2026 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants