Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,32 @@ yarn e2e:run
yarn e2e:open
```

## Git Worktrees

The project includes scripts to manage [Git worktrees](https://git-scm.com/docs/git-worktree), allowing you to work on multiple branches simultaneously in separate directories without stashing or switching branches.

### Create a new worktree

```
yarn new-worktree feat/my-feature
```

This will:
1. Create a new branch (`feat/my-feature`) and check it out in a sibling directory named `wt-feat-my-feature`
2. Copy `.vscode` settings and all `.env*` files from the main repo
3. Hard-link `node_modules` from the main repo (fast, minimal extra disk usage) — or run `yarn install` if none exist
4. Open the new worktree in a new VS Code window

> If the new branch changes `package.json` dependencies, run `yarn install` inside the worktree directory to reconcile.

### Remove a worktree

```
yarn remove-worktree feat/my-feature
```

This will remove the worktree directory and delete the local branch. The branch must be fully merged before deletion (uses `git branch -d`).

## API Types Generation

The project includes scripts for generating TypeScript types from OpenAPI specifications:
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@
"generate:api-types:output": "node scripts/generate-api-types.mjs",
"generate:api-types": "node scripts/generate-api-types.mjs src/app/services/feeds/types.ts",
"generate:gbfs-validator-types:output": "npm exec -- openapi-typescript ./external_types/GbfsValidator.yaml -o $npm_config_output_path && eslint $npm_config_output_path --fix",
"generate:gbfs-validator-types": "npm run generate:gbfs-validator-types:output -- --output-file=src/app/services/feeds/gbfs-validator-types.ts"
"generate:gbfs-validator-types": "npm run generate:gbfs-validator-types:output -- --output-file=src/app/services/feeds/gbfs-validator-types.ts",
"new-worktree": "bash scripts/new-worktree.sh",
"remove-worktree": "bash scripts/remove-worktree.sh"
},
"resolutions": {
"tar": "^7.5.7"
Expand Down
51 changes: 51 additions & 0 deletions scripts/new-worktree.sh
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')"

Comment thread
Alessandro100 marked this conversation as resolved.
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 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.

# 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
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.


# 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"

26 changes: 26 additions & 0 deletions scripts/remove-worktree.sh
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
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.

Loading