M4.5: branch status-bar item and branches popup

The status bar shows the current branch (short hash when detached). Its
popup lists local, then remote branches with a filter and New branch;
checkout runs flushDirty first and toasts git's refusal. Commands
vcs.branches, vcs.newBranch and vcs.checkout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-10-26 17:40:33 +01:00
parent b3642e53ea
commit 149a6c7049
18 changed files with 1585 additions and 17 deletions

View file

@ -1,6 +1,6 @@
# Architecture
> **Status:** M0 decisions recorded, M1 workspace, desktop bridge, tabs and editor, message catalog, engine construction, settings, themes, the recovery journal, notifications, UI commands, the palette, the settings dialog, the app icon and the syntax layer documented; M2 highlighting and `editor.reveal`, plus the search backend, the Find tool window, the symbol index, the Structure tool window and the go-to popup; M3 CLI and single instance, LSP client library, toolchain (PHP detection, Phpactor download), the app menu, MCP server, autosave and `flushDirty`, integrated terminal; engine ↔ Phpactor wiring and diagnostics (M3.3), pending outcomes (M3.5), completion, hover and signature help (M3.4); C5 child process groups (H1), settings dialog string and path controls and assist settings (H4), the banner-aligned themes and diagnostic/VCS tokens (H5), Phpactor UX: fast tick, messages, progress, `php -l` (H3); Git backend (M4.1), Changes tool window (M4.2); line changes, gutter markers and status colours (M4.4), diff viewer (M4.3) · **Last updated:** 2026-10-26
> **Status:** M0 decisions recorded, M1 workspace, desktop bridge, tabs and editor, message catalog, engine construction, settings, themes, the recovery journal, notifications, UI commands, the palette, the settings dialog, the app icon and the syntax layer documented; M2 highlighting and `editor.reveal`, plus the search backend, the Find tool window, the symbol index, the Structure tool window and the go-to popup; M3 CLI and single instance, LSP client library, toolchain (PHP detection, Phpactor download), the app menu, MCP server, autosave and `flushDirty`, integrated terminal; engine ↔ Phpactor wiring and diagnostics (M3.3), pending outcomes (M3.5), completion, hover and signature help (M3.4); C5 child process groups (H1), settings dialog string and path controls and assist settings (H4), the banner-aligned themes and diagnostic/VCS tokens (H5), Phpactor UX: fast tick, messages, progress, `php -l` (H3); Git backend (M4.1), Changes tool window (M4.2); line changes, gutter markers and status colours (M4.4), diff viewer (M4.3), branches (M4.5) · **Last updated:** 2026-10-26
## Overview
@ -622,6 +622,16 @@ Watched directories: the VFS watcher is non-recursive, so `project.children` wat
- **Look:** both sides use the Lutra editor theme and the file's language; changed lines are tinted with `color-mix` of `--lt-vcs-deleted` (left) and `--lt-vcs-added` (right) into `--lt-editor-bg`, changed words more strongly, a change bar in each gutter, unchanged stretches over 8 lines collapse to a row (3 lines of context). No colour outside the tokens.
- **Tests:** `ui/tests/vcs/DiffView.test.ts` (21 Vitest tests against a fake engine: params and `git.show` parsing, EOL normalisation, index and HEAD sides, one tab per side, the palette without a path, bad params and no file as toasts, disabled without a project, edits on the right reaching `buffer.edit`, engine changes reaching the right side, the left side refresh on `gitChanged`, closing with the buffer, binary / too large / git error / deleted / new file, switching between diff and file tabs, next/previous change with wrap-around, the tree context menu by right click and by Shift+F10 with Escape).
### Branches (M4.5)
- **Where:** `ui/src/components/vcs/branches/`: `branches.ts` is the Pinia store, `BranchStatusItem.vue` the status-bar item (one line in `StatusBar.vue`, after H3's progress item), `BranchPopup.vue` the popup. The item supplies the UI commands, so they exist wherever the status bar is.
- **Status-bar item:** the current branch from the Changes store's `git.status` (no second query; it follows `gitChanged`), or the first 7 characters of HEAD when detached; hidden outside a repository, while git is missing and before the first status. A click runs `vcs.branches`.
- **Popup:** above the status bar's right end. A filter field (every word must occur in the name, ignoring case), "New branch…", then Local and Remote headings with their branches sorted by name; the current branch has a check and "current", a local branch shows its upstream. `git.branches` (through `runWaiting`) is read each time it opens; the first branch is selected once the list arrives. Up/Down/Page Up/Page Down move, Enter or a click chooses, Escape or a click outside closes and gives the focus back. Choosing the current branch only closes it. It is an exclusive modal (`ModalId` `branches`). The answer is untrusted: malformed entries are dropped, at most 10,000 per kind.
- **Checkout:** choosing a branch closes the popup and runs `vcs.checkout {branch}`: `flushDirty()` first; a failed save cancels with a warning (`notification.vcs.checkoutNotSaved`) and git is not called. Then `git.checkout`; git's refusal (local changes would be overwritten, an unknown branch) becomes an error toast `notification.vcs.checkoutFailed {branch, reason}` with git's text, success an info toast. A remote branch (`origin/x`) checks out its tracking branch (M4.1). Open buffers whose files changed reload through the watcher; the status follows `gitChanged`.
- **New branch:** "New branch…" (taking the filter text as a first name) or `vcs.newBranch` shows a name field and a "Check out" checkbox (on). Create runs `git.createBranch {name, checkout}` from HEAD; nothing is saved first because creating and switching from HEAD leaves the files alone. A blank name or git's refusal (invalid name, an existing branch) shows under the field (`role="alert"`) and the popup stays; Escape goes back to the list.
- **Commands** (UI commands, menu group Git, no default shortcuts): `vcs.branches` (Git › Branches…), `vcs.newBranch {name?, checkout?}` (Git › New Branch…; with a `name` it creates the branch without the popup, checked out unless `checkout: false`, and toasts a refusal), `vcs.checkout {branch}` (without `branch`, as from the palette, it opens the popup; a `branch` that is no non-blank string toasts an error). All are enabled while `git.branches` is (an open project).
- **Tests:** `ui/tests/vcs/Branches.test.ts` (16 Vitest tests against a fake engine: parsing, filter, head label, the item's states, popup order and marking, filtering, keyboard, checkout after `flushDirty` through `runWaiting`, a refusal toast, a cancelled checkout, creating with a blank name, a refusal and success, Escape back to the list, the commands' registration, params and enabled state).
## Decisions (M0)
| Question | Decision | Why |
@ -639,6 +649,7 @@ Watched directories: the VFS watcher is non-recursive, so `project.children` wat
| Date | Change | Summary |
|---|---|---|
| 2026-10-26 | minor | M4.5: branches (status-bar item, popup, `vcs.branches`, `vcs.newBranch`, `vcs.checkout`) |
| 2026-10-26 | minor | M4.3: diff viewer (`vcs.showDiff`, `vcs.nextChange`, `vcs.previousChange`, `@codemirror/merge` loaded lazily, the project tree's context menu) |
| 2026-10-25 | minor | M4.4: `git.lineChanges` (index cache, `similar` line diff off the lock), gutter change markers, Git status colours in the tree and tabs |
| 2026-10-25 | minor | M4.2: Changes tool window (`vcs.openChanges`, `vcs.commit`, `vcs.refresh`, staging, commit after `flushDirty`) |