Skip to content

refactor: collapse more duplicated paths onto single sources - #2934

Merged
max-sixty merged 1 commit into
mainfrom
simplifications
May 29, 2026
Merged

max-sixty merged 1 commit into
mainfrom
simplifications

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Round 3 of the simplification backlog: seven independent dedups, each collapsing a duplicated code path onto a single source. No behavior change — output and control flow are byte-identical, and the full suite (3868 tests), clippy, fmt, and doctests pass. Net −26 lines.

Item Change
git/repository/integration.rs Extracted merge_tree_outcome(a, b) → Clean{tree} | Conflict, the git merge-tree --write-tree exit-code dispatch that run_merge_tree and would_merge_add_to_target each open-coded. Bail strings stay byte-identical; arg order and the merge_base pre-check are preserved.
commands/worktree/switch.rs Extracted parse_ref_shortcut(s) → Option<(RefType, u32)>, folding the parse_ref_url normalization + pr:/mr: prefix-strip that resolve_switch_target and resolve_base_ref each repeated. Downstream resolution is unchanged because parse_ref_url only ever yields pr:N/mr:N (so a non-shortcut input reaches the fallback untouched).
config/user/sections.rs CommitConfig::merge_with (generation) and SwitchConfig::merge_with (picker) call the existing merge_optional helper instead of re-spelling its four-arm Option match.
git/repository/mod.rs worktree_state rebase probe stats rebase-merge / rebase-apply once each (was up to 3×) via then_some(...).or_else(...).
config/{mod,user/schema,project}.rs valid_user_config_keys / valid_project_config_keys were byte-identical but for the type param; both now delegate to a generic schema_top_level_keys::<T: JsonSchema>() in config/mod.rs. Public signatures unchanged.
shell/mod.rs + configure_shell.rs Shell::all() is the single source for the two identical scan-order vecs ([Bash, Zsh, Fish, Nushell, PowerShell]).
shell_exec.rs + 2 callers Dropped the ShellConfig::is_posix() accessor — is_posix is already a pub field read directly elsewhere. The rich POSIX doc moved to the field; the two method callers route to .is_posix.

Deliberately scoped out (kept tight, documented for later):

  • E2 (RefBaseConflict checked twice in switch.rs): deleting the outer check isn't behavior-preserving — on a GitLab repo, wt switch pr:N --base X would then surface choose_pr_provider's "use mr: instead of pr:" error ahead of the base-conflict error. Arguably a better message, but a real error-path change, so it stays out of a no-behavior-change batch.
  • B1 (unify the ExitStatus → ChildProcessExited{128+sig} translation across the two exec engines): the four sites differ in messages, side-effect interleaving, and SIGPIPE/seen_signal special cases, all inside the guarded signal-handling invariant. Warrants its own focused PR.

No CLI flags or config-file format touched (protected interfaces). Behavior-equivalence of each dedup verified by inspection and by a code-review pass (which caught one stranded doc comment, fixed here).

This was written by Claude Code on behalf of max

Round 3 of the simplification backlog: seven independent dedups, each
folding a duplicated code path onto a single source. No behavior change.

- integration.rs: extract `merge_tree_outcome`, the `git merge-tree`
  exit-code dispatch that `run_merge_tree` and `would_merge_add_to_target`
  each open-coded (bail strings byte-identical).
- switch.rs: extract `parse_ref_shortcut`, folding the URL-normalize +
  `pr:`/`mr:` strip duplicated by `resolve_switch_target` and
  `resolve_base_ref`.
- sections.rs: `CommitConfig`/`SwitchConfig` `merge_with` call the existing
  `merge_optional` helper instead of re-spelling its 4-arm match.
- repository/mod.rs: `worktree_state` rebase probe stats `rebase-merge` /
  `rebase-apply` once each (was up to 3x).
- config: `valid_user_config_keys` / `valid_project_config_keys` delegate to
  one generic `schema_top_level_keys::<T>()` (bodies were identical but for
  the type param).
- shell/mod.rs: `Shell::all()` is the single source for the two identical
  scan-order vecs in configure_shell.rs.
- shell_exec.rs: drop the `ShellConfig::is_posix()` accessor (a `pub` field
  already); doc moved to the field, two callers routed to `.is_posix`.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit 987e3e0 into main May 29, 2026
35 checks passed
@max-sixty
max-sixty deleted the simplifications branch May 29, 2026 02:15
@max-sixty max-sixty mentioned this pull request May 30, 2026
max-sixty added a commit that referenced this pull request May 30, 2026
v0.55.0.

`cargo semver-checks` reports breaking library API changes (9 inherent methods removed from `Repository` / `ShellConfig` by the dead-code cut-overs in #2931 — `is_ancestor`, `same_commit`, `has_added_changes`, `trees_match`, `head_tree_matches_branch`, `has_merge_conflicts`, `has_merge_conflicts_by_tree`, `merge_integration_probe`, `is_posix`). None are intentional public API, but they force a minor bump pre-1.0.

Headline user-visible changes:
- `wt switch` accepts forge PR/MR URLs anywhere `pr:N` / `mr:N` works (#2898, thanks @thiagowfx for the request).
- Claude Code plugin keeps unmerged branches during worktree cleanup — the `WorktreeRemove` hook drops `-D` (#2940, thanks @jbeda for reporting).
- `wt list` and `wt step prune` degrade gracefully on unborn worktrees (#2937, thanks @nedtwigg for reporting).
- `-vv` startup pointer now names `diagnostic.md` (#2919).
- Doc-site and `--help` prose cleanup (#2922, #2925); internal cut-over of duplicated/dead code paths (#2931, #2932, #2934).

Full CHANGELOG entry in this PR.

> _This was written by Claude Code on behalf of max_
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
worktrunk 0.55.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

- **`wt switch` accepts forge PR/MR URLs**: `wt switch https://github.com/owner/repo/pull/123` now resolves the same way as `wt switch pr:123`, and the URL form works anywhere a `pr:N` / `mr:N` shortcut does (positional argument and `--base`). Detection is shape-based, not host-based — any `http(s)://` URL whose path contains `/pull/N`, `/pulls/N`, `/-/merge_requests/N`, or `/pullrequest/N` matches, covering GitHub (including Enterprise), GitLab, Gitea, and Azure DevOps, including self-hosted instances. ([#2898](max-sixty/worktrunk#2898), thanks @thiagowfx for the request)

- **`-vv` startup pointer names `diagnostic.md`**: The `-vv` pointer now lists the shared log directory once with all three files it will contain — `trace.log`, `subprocess.log`, and `diagnostic.md` — so the diagnostic bundle is discoverable at startup rather than only when the gist hint fires at exit. The pointer verb reads `Writing to …` instead of `Tracing to …`. ([#2919](max-sixty/worktrunk#2919))

### Fixed

- **Claude Code plugin keeps unmerged branches during worktree cleanup**: The plugin's `WorktreeRemove` hook passed `-D` (`--force-delete`) to `wt remove`, which removes a branch even when it carries commits that aren't merged or pushed. The hook now uses the default removal: a merged or integrated branch is removed cleanly, while one with unmerged commits is kept, with a `wt remove -D <branch>` hint for deleting it deliberately. ([#2940](max-sixty/worktrunk#2940), thanks @jbeda for reporting)

- **`wt list` and `wt step prune` degrade gracefully on unborn worktrees**: A linked worktree created with `git worktree add --orphan` sits on an unborn branch whose `HEAD` is the null OID. `wt list` used to show `working-tree-diff (fatal: ambiguous argument 'HEAD')` and a merge-tree error in its columns, and `wt step prune` aborted its entire scan with `fatal: Needed a single revision`, blocking pruning of every other worktree. Both now treat an unborn worktree as having no commits: `wt list` renders `·` for the commit-dependent columns, and `wt step prune` skips it (as it does locked worktrees) and continues. ([#2937](max-sixty/worktrunk#2937), thanks @nedtwigg for reporting)

### Documentation

- **Doc-site and `--help` prose cleanup**: A writing-prose pass across the FAQ, config, list, remove, Claude Code, hook, LLM-commits, and Tips & Patterns pages (some via `--help` text in `after_long_help`). ([#2922](max-sixty/worktrunk#2922), [#2925](max-sixty/worktrunk#2925))

### Internal

- **Collapsed duplicated code paths and removed dead code left by completed cut-overs**: A net reduction across the shell, git, and command layers. ([#2931](max-sixty/worktrunk#2931), [#2932](max-sixty/worktrunk#2932), [#2934](max-sixty/worktrunk#2934))

## Install worktrunk 0.55.0

### Install prebuilt binaries via shell script

```sh
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/max-sixty/worktrunk/releases/download/v0.55.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.55.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.55.0

|  File  | Platform | Checksum |
|--------|----------|----------|
| [worktrunk-aarch64-apple-darwin.tar.xz](https://github.com/max-sixty/worktrunk/releases/download/v0.55.0/worktrunk-aarch64-apple-darwin.tar.xz) | Apple Silicon macOS | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.55.0/worktrunk-aarch64-apple-darwin.tar.xz.sha256) |
| [worktrunk-x86_64-apple-darwin.tar.xz](https://github.com/max-sixty/worktrunk/releases/download/v0.55.0/worktrunk-x86_64-apple-darwin.tar.xz) | Intel macOS | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.55.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.55.0/worktrunk-x86_64-pc-windows-msvc.zip) | x64 Windows | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.55.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.55.0/worktrunk-aarch64-unknown-linux-musl.tar.xz) | ARM64 MUSL Linux | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.55.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.55.0/worktrunk-x86_64-unknown-linux-musl.tar.xz) | x64 MUSL Linux | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.55.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.55.0">https://github.com/max-sixty/worktrunk/releases/tag/v0.55.0</a>.</p>
</details>
<hr>

See merge request: Harmonybrew/homebrew-core!9819
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.

2 participants