Skip to content

Add worktree switching support#129

Open
goransle wants to merge 11 commits into
masterfrom
feature/worktree-support
Open

Add worktree switching support#129
goransle wants to merge 11 commits into
masterfrom
feature/worktree-support

Conversation

@goransle

@goransle goransle commented May 21, 2026

Copy link
Copy Markdown
Member
  • Add lib/worktree.js for git worktree discovery
  • Add dynamic getters (getHighchartsDir/getSamplesDir/getApiDir) to lib/arguments.js
  • Add /api/worktree endpoints (routes/worktree.js)
  • Refactor all static highchartsDir/samplesDir imports to use dynamic getters
  • Add worktree dropdown to nav bar with 🌲 label
  • Reinitialize file watchers on worktree switch
  • Add path containment security check

Test plan

  • create two branch worktrees in the highcharts repo
    git worktree add ../highcharts-worktrees/wt-master master
    git worktree add ../highcharts-worktrees/wt-feature -b test/worktree-switch
  • Locate the worktree dropdown. Ensure there's now worktrees available (including the existing repo)
  • Make a change to a sample or code in one of the worktrees and ensure it's reflected when changing worktree via the dropdown

- Add lib/worktree.js for git worktree discovery
- Add dynamic getters (getHighchartsDir/getSamplesDir/getApiDir) to lib/arguments.js
- Add /api/worktree endpoints (routes/worktree.js)
- Refactor all static highchartsDir/samplesDir imports to use dynamic getters
- Add worktree dropdown to nav bar with 🌲 label
- Reinitialize file watchers on worktree switch
- Add path containment security check
Guard readdirSync in websocket walk() with try-catch to handle
ENOENT when a worktree is deleted while the server is running.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds git worktree awareness to highcharts-utils so the running app can switch between multiple Highcharts checkouts without a server restart, including a UI selector, API endpoints, and dynamic path resolution across routes/watchers.

Changes:

  • Introduces worktree discovery (lib/worktree.js) plus /api/worktree endpoints to list/select active worktrees.
  • Refactors path usage to dynamic getters (getHighchartsDir / getSamplesDir / getApiDir) so routes/static serving follow the selected worktree.
  • Updates the UI (nav dropdown) and watcher logic to reinitialize file watching after switching worktrees; adds a Playwright-based script for scanning sample console errors.

Reviewed changes

Copilot reviewed 24 out of 24 changed files in this pull request and generated 14 comments.

Show a summary per file
File Description
views/samples/contents.hbs Minor template cleanup (whitespace/blank line).
views/partials/nav.hbs Adds worktree selector UI in the top bar next to version display.
server.js Uses dynamic Highcharts dir getter for logging and package.json resolution.
scripts/check-samples-console.mjs New script to crawl sample pages and report console/page errors via Playwright.
routes/worktree.js New API routes for listing worktrees and persisting selected worktree to config.
routes/samples/view.js Switches sample file operations to use getHighchartsDir() dynamically.
routes/samples/share.js Switches sample asset reads to use getHighchartsDir() dynamically.
routes/samples/list-samples.js Switches sample discovery to use getSamplesDir() dynamically.
routes/samples/edit.js Switches editor file reads to use getSamplesDir() dynamically.
routes/samples/data.js Serves sample data files from getSamplesDir() dynamically.
routes/samples/contents.js Passes dynamic highchartsDir to template.
routes/samples/compare-view.js Passes dynamic highchartsDir to template.
routes/bisect/commits.js Refactors to use dynamic Highcharts dir for git operations.
routes/bisect/bisect.js Updates git spawn working directory to dynamic Highcharts dir.
public/stylesheets/style.less Adds layout/styles for the worktree selector in the top bar.
public/javascripts/nav.js Fetches worktrees and posts selection to reload app on switch.
lib/worktree.test.js Adds unit tests for parsing git worktree list --porcelain -z.
lib/worktree.js Implements git worktree discovery/parsing and validity marking.
lib/websocket.js Refactors watcher initialization to support reinit on worktree switch.
lib/functions.js Replaces static dirs with dynamic getters across sample-related helpers.
lib/compile-on-demand.js Uses dynamic Highcharts dir for resolving package/master paths.
lib/arguments.js Adds dynamic getters and a containment check for selected worktree paths.
app.js Serves worktree-dependent static dirs and registers /api/worktree.
app-api.js Serves API docs from dynamically selected worktree’s build output.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/arguments.js Outdated
Comment thread routes/worktree.js
Comment thread public/javascripts/nav.js
Comment thread public/javascripts/nav.js
Comment thread routes/samples/list-samples.js
Comment thread scripts/check-samples-console.mjs Outdated
Comment thread lib/websocket.js
Comment thread app.js
Comment thread app-api.js
Comment thread lib/worktree.test.js
@MarkusBarstad

Copy link
Copy Markdown
Contributor

Works!

Messed with my head a bit that you have to npx gulp in each worktree to serve files 😆

@MarkusBarstad MarkusBarstad self-requested a review May 28, 2026 08:15
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.

3 participants