Repository navigation
fix: fence user-controlled refs against git flag injection - #3317
Conversation
A branch or ref name can begin with `-` (creatable out-of-band via `update-ref`), which git then misparses as an option rather than a ref. The project already guards against this with `--end-of-options` (ranges) and `--` (branch names) in several places; this closes the sites that didn't. The diff/summary preview helper (`compute_diff_preview`) appended its options *after* the positional revs, so it structurally couldn't fence them. Restructure it to `prefix` + options + `--end-of-options` + revs — the only ordering git accepts — so a flag-like ref can't be misparsed. Current callers pass resolved SHAs, but the helper is now safe for any future name-passing caller. A codebase audit found six more gaps, all fixed to match the existing convention: - Three destructive `git branch -D <name>` → `-D -- <name>` (force-remove and the non-CAS fallback in remove.rs, the force handler in handlers.rs). Highest severity: a branch named `-d`/`-r` could otherwise redirect a delete. - Three read-only range positionals → `--end-of-options` (push.rs shortstat and commit-graph log, the shared `show_diffstat` helper). Two regression tests that fail under the old code: a flag-like ref resolving through the preview fence, and force-deleting a `-x` branch. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
worktrunk-bot
left a comment
There was a problem hiding this comment.
Traced every changed callsite — the fences are placed correctly and match the existing convention: --end-of-options after all options / before the positional revs for diff/log ranges (mod.rs, push.rs, picker/items.rs), and -- for the git branch -D name positional. The compute_diff_preview prefix + options + --end-of-options + revs restructure preserves the prior behavior for every caller (the empty-revs working-tree case included), and the two regression tests fail under the old code and pass under the new. No correctness or idiom concerns.
Holding rather than approving for one reason: this edits the data-loss surface — repo.run_command(&["branch", "-D", "--", branch_name]) in both src/git/remove.rs (force-delete and non-CAS fallback) and src/output/handlers.rs (force handler). Per this repo's review policy, force-delete changes are held for human review and not bot-approved, even when the change is strictly hardening (as it is here — the -- separator only narrows what git will misparse). Since you authored it, that human review is already in your hands; flagging the surface for the record.
worktrunk 0.64.0
Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`
---
Created with `brew bump-formula-pr`.<details>
<summary>release notes</summary>
<pre>## Release Notes
### Improved
- **`{{ git.branch.* }}` template namespace for custom columns**: `wt list` custom columns can now read a branch's own git config via `{{ git.branch.<key> }}` — both convention keys you set yourself (`branch.<name>.jira`) and the git-native `branch.<name>.description` — without re-storing the values through `wt config state vars set`. It complements `{{ vars.* }}`, which reads only worktrunk's own state namespace. ([#3319](max-sixty/worktrunk#3319), thanks @cazador481 for the request)
- **Faster warm-cache `wt list` re-runs**: A repeat `wt list` (with `.git/wt/cache/` already populated) is ~36% faster, by removing redundant per-row git subprocesses — priming the commit→tree cache from the `%ct` batch already issued, persisting merge-base results to a content-addressed on-disk cache, and seeding worktree roots and git-dirs from the single `git worktree list` instead of re-forking `git rev-parse` per worktree. ([#3334](max-sixty/worktrunk#3334))
### Fixed
- **Refs that look like flags can't inject git options**: `wt`'s `git diff` previews and diffstats (picker diff previews, `show_diffstat`, push diffstat) now fence user-controlled refs behind `--end-of-options`, and branch removal (`git branch -D`) passes them after `--`, so a branch literally named like a flag (`-x`, `--foo`) reaches git as a positional ref instead of being misparsed as an option. ([#3317](max-sixty/worktrunk#3317))
- **Statusline renders untruncated when `COLUMNS=0`**: `wt list statusline` treated `COLUMNS=0` as a zero-width budget and dropped every segment, rendering an empty line. A zero or unparsable `COLUMNS` is now treated as no detectable width, so the line renders everything untruncated — as the statusline sizing already documented for a missing width. ([#3318](max-sixty/worktrunk#3318))
- **Watchdog "still waiting" line uses the hint symbol**: The transient `Waiting for the commit message (Ns)` line shown during a slow `wt step commit` LLM call now uses the hint prefix (`↳`) instead of the info symbol (`○`), matching the convention for fully-dim status lines. ([#3330](max-sixty/worktrunk#3330))
## Install worktrunk 0.64.0
### Install prebuilt binaries via shell script
```sh
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/max-sixty/worktrunk/releases/download/v0.64.0/worktrunk-installer.sh | sh && wt config shell install
```
### Install prebuilt binaries via powershell script
```sh
powershell -ExecutionPolicy Bypass -c "irm https://github.com/max-sixty/worktrunk/releases/download/v0.64.0/worktrunk-installer.ps1 | iex"; git-wt config shell install
```
### Install prebuilt binaries via Homebrew
```sh
brew install worktrunk && wt config shell install
```
## Download worktrunk 0.64.0
| File | Platform | Checksum |
|--------|----------|----------|
| [worktrunk-aarch64-apple-darwin.tar.xz](https://github.com/max-sixty/worktrunk/releases/download/v0.64.0/worktrunk-aarch64-apple-darwin.tar.xz) | Apple Silicon macOS | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.64.0/worktrunk-aarch64-apple-darwin.tar.xz.sha256) |
| [worktrunk-x86_64-apple-darwin.tar.xz](https://github.com/max-sixty/worktrunk/releases/download/v0.64.0/worktrunk-x86_64-apple-darwin.tar.xz) | Intel macOS | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.64.0/worktrunk-x86_64-apple-darwin.tar.xz.sha256) |
| [worktrunk-x86_64-pc-windows-msvc.zip](https://github.com/max-sixty/worktrunk/releases/download/v0.64.0/worktrunk-x86_64-pc-windows-msvc.zip) | x64 Windows | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.64.0/worktrunk-x86_64-pc-windows-msvc.zip.sha256) |
| [worktrunk-aarch64-unknown-linux-musl.tar.xz](https://github.com/max-sixty/worktrunk/releases/download/v0.64.0/worktrunk-aarch64-unknown-linux-musl.tar.xz) | ARM64 MUSL Linux | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.64.0/worktrunk-aarch64-unknown-linux-musl.tar.xz.sha256) |
| [worktrunk-x86_64-unknown-linux-musl.tar.xz](https://github.com/max-sixty/worktrunk/releases/download/v0.64.0/worktrunk-x86_64-unknown-linux-musl.tar.xz) | x64 MUSL Linux | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.64.0/worktrunk-x86_64-unknown-linux-musl.tar.xz.sha256) |
### Install via Cargo
```sh
cargo install worktrunk && wt config shell install
```
### Install via Winget (Windows)
```sh
winget install max-sixty.worktrunk && git-wt config shell install
```
### Install via AUR (Arch Linux)
```sh
paru worktrunk-bin && wt config shell install
```
</pre>
<p>View the full release notes at <a href="https://github.com/max-sixty/worktrunk/releases/tag/v0.64.0">https://github.com/max-sixty/worktrunk/releases/tag/v0.64.0</a>.</p>
</details>
<hr>
See merge request: Harmonybrew/homebrew-core!13223
A branch or ref name can begin with
-(creatable out-of-band viagit update-ref, sincegit branchrejects leading-dash names). Git then misparses such a name as an option rather than a ref. The project already defends against this with--end-of-options(for ranges) and--(for branch names) in several places —repository/diff.rs,worktree/switch.rs— but a few callsites didn't. This closes them.The preview helper
compute_diff_preview(picker diff/summary panes) appended its--stat/--coloroptions after the positional revs, so it structurally couldn't place an--end-of-optionsfence (git requires all options before it). Restructured toprefix+ options +--end-of-options+revs— the only ordering git accepts. Today's callers pass resolved SHAs (which can't lead with-), but the helper is now safe for any future caller that passes a raw name.Audit findings
A sweep of every git-subprocess callsite found six more gaps, all fixed to match the existing convention:
remove.rsforce-deletebranch -D <name>branch -D -- <name>remove.rsnon-CAS fallbackbranch -D <name>branch -D -- <name>handlers.rsforce handlerbranch -D <name>branch -D -- <name>push.rsshortstat<target>..HEAD--end-of-options <target>..HEADpush.rscommit-graph log<target>..HEAD--end-of-options <target>..HEADshow_diffstathelper<range>--end-of-options <range>The three
branch -Dsites are the most serious — a branch named-d/-rcould redirect a destructive delete. Thepush.rsranges take the user'swt merge [TARGET]positional, sowt merge -- -xproduces a-x..HEADtoken that leads with-.Everything else the audit traced was already safe (SHA positionals,
refs/heads/…prefixes, option-argument values,---guarded calls). One borderline case ({remote}/HEAD) was excluded — git won't let a remote name begin with-.Testing
Two regression tests that fail under the old code:
diff_preview_fences_flag_like_refs(createsrefs/heads/-weird, asserts it resolves through the fence) andforce_delete_handles_flag_like_branch_name(force-deletes a-xbranch). Full local gate green (4296 tests), clippy + rustdoc clean.