Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
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-worktreecommands wired throughpackage.json. - Introduce bash scripts to create a worktree + branch, copy
.env*/.vscode, and reusenode_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. |
| # Remove the worktree | ||
| git worktree remove "$WORKTREE_DIR" | ||
|
|
||
| # Delete the branch | ||
| git branch -d $BRANCH | ||
|
|
||
| echo "🗑️ Worktree $WORKTREE_DIR removed and branch $BRANCH deleted" |
There was a problem hiding this comment.
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.
| fi | ||
|
|
||
| # Create the worktree and branch | ||
| git worktree add -b $BRANCH $WORKTREE_DIR main |
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@copilot apply changes based on this feedback
There was a problem hiding this comment.
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.
| # 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 |
There was a problem hiding this comment.
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.
|
|
|
*Lighthouse ran on https://mobilitydatabase-6o4qko2i3-mobility-data.vercel.app/ * (Desktop)
*Lighthouse ran on https://mobilitydatabase-6o4qko2i3-mobility-data.vercel.app/feeds * (Desktop)
*Lighthouse ran on https://mobilitydatabase-6o4qko2i3-mobility-data.vercel.app/feeds/gtfs/mdb-2126 * (Desktop)
*Lighthouse ran on https://mobilitydatabase-6o4qko2i3-mobility-data.vercel.app/feeds/gtfs_rt/mdb-2585 * (Desktop)
*Lighthouse ran on https://mobilitydatabase-6o4qko2i3-mobility-data.vercel.app/feeds/gbfs/gbfs-flamingo_porirua * (Desktop)
|
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Agent-Logs-Url: https://github.com/MobilityData/mobilitydatabase-web/sessions/b94c36ed-c130-4c94-b685-7e7ba5ecd4c9 Co-authored-by: Alessandro100 <18631060+Alessandro100@users.noreply.github.com>
320335d to
02f2870
Compare
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 awayyarn start:devOnce you're done testing, run
yarn remove-worktree feat/test-branchto clean it upPlease make sure these boxes are checked before submitting your pull request - thanks!
yarn testto make sure you didn't break anything