Repository navigation
Conversation
A !wt alias from a linked worktree pins GIT_DIR to that worktree's admin dir. WorkingTree::run_command forwarded it, so merge's target conflict check compared the feature index to the main worktree and refused a clean merge. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Evidence for the review note about That makes the gate change a correction of a Not a review verdict — the merge call is still @max-sixty's. |
max-sixty
left a comment
There was a problem hiding this comment.
please review this much more thoroughly
worktrunk-bot
left a comment
There was a problem hiding this comment.
Holding the verdict for @max-sixty rather than approving. This diff changes what wt remove's deletion gate observes: ensure_clean → dirty_files → WorkingTree::run_command_output in src/git/repository/working_tree.rs is that gate, and the scrub added there decides whether a worktree holding uncommitted work gets deleted. The direction is right — the gate now reads the worktree being removed instead of the invoking one, and a genuinely dirty target still blocks — but a change to the deletion surface isn't mine to approve.
Two gaps worth closing whichever way that call goes.
The changelog entry covers only the merge symptom. The same scrub also closes a silent-data-loss path in wt remove (evidence) — the more severe of the two fixes, and the one a user scanning ### Fixed would most want to find. Suggested entry inline.
Nothing pins the removal gate. test_merge_syncs_target_when_git_dir_names_the_source asserts the merge succeeds, so it pins the conflict gate; no test sets GIT_DIR and exercises wt remove at all. That leaves the data-safety behavior resting on a test whose assertion is about merge output — it would stay green if ensure_clean / dirty_files were later routed through an unscrubbed path (a Repository-level status call, a new helper) while merge kept working. CLAUDE.md → Data Safety ("Prefer failure over silent loss") makes this the behavior most worth its own regression test: set GIT_DIR to the invoking worktree's private gitdir, leave the target dirty on a path the invoking index agrees about, and assert the removal is refused and the file survives.
|
One correction to the premise this PR is described against, since it affects how narrow the fix looks: I'd reported #4081 as a The diff here is unaffected — the scrub covers the inherited variable regardless of what set it — so this is about the title and body wording reading narrower than the failure, not about the change itself. |
Lead with wt command names in the changelog, add the wt remove data-safety half, split worktree-local plumbing from user-command relocation in CLAUDE.md, and pin the dirty gate with a GIT_DIR regression test. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Addressed the review in 24a83d4:
CI re-running. Still holding for @max-sixty on the deletion-gate surface. |
worktrunk-bot
left a comment
There was a problem hiding this comment.
Two follow-ups on 24a83d4, both inline.
The new wt remove regression asserts only that the command failed, so it stays green whenever the removal errors for any reason at all — including a future change that never reaches the dirty gate under an inherited GIT_DIR, which is exactly the silent-deletion path the test is there to pin. Asserting the gate's own message closes that.
The CLAUDE.md classification now reads as though both worktree-local sites remove GIT_INDEX_FILE. TempIndex::command sets it, and since env-removes run last — the ordering the same sentence documents — an implementer who brings that site in line with the doc would drop the temp index and point register_untracked's git add --intent-to-add . at the user's real index.
The verdict still sits with @max-sixty: this diff decides what wt remove's deletion gate observes (ensure_clean → dirty_files → WorkingTree::run_command_output), and the branch's checks are still running.
|
Confirming the two gaps I raised are closed in 24a83d4, with the removal test checked by execution rather than by reading it. I checked out the head, reverted only the four That result bears on the assertion-strength point in the review just posted: the unscrubbed path today succeeds rather than errors, so The changelog's second
|
Assert the gate's own "has uncommitted changes" text so the regression fails if removal errors for another reason under an inherited GIT_DIR. Document that TempIndex sets GIT_INDEX_FILE rather than removing it. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Addressed the two follow-ups on 24a83d4 in 08591da:
Still holding for @max-sixty on the deletion-gate surface. |
|
Both follow-ups are closed in 08591da, and the assertion lands on the right message: Checks at this head: Nothing further from me — the verdict is still @max-sixty's, and the |
Every review on a PR added three `tend-mention` rows to its checks, and on a fork PR all three were skipped — e.g. max-sixty/worktrunk#4082. GitHub lists every job of a PR event's run among the PR's checks, skipped jobs included, and a `pull_request_review` run of `tend-mention` could only ever execute `relay`: `verify` and `handle` run on the `repository_dispatch` the relay sends. The relay now lives in a generated `tend-mention-relay.yaml`, the only workflow subscribed to `pull_request_review` and `pull_request_review_comment`. A review adds one row: green on a same-repo PR, skipped on a fork PR. One row is the floor while anything listens to review events, since `on:` can't filter forks and a workflow has no top-level `if`. - `generate_all` emits the relay alongside `mention` and drops it when `mention` is disabled. Like `codex-auth-refresh`, it sits outside `GENERATORS` (it runs no agent) and has its own `workflows.mention-relay` key for `enabled` and job overrides; an existing `workflows.mention.jobs.relay` override now warns as not found. - The relay job is unchanged apart from its `if`, which loses the event-name check the split makes redundant. The trigger comment on why `pull_request_review_comment` skips `created` is rewritten: its old rationale, a cancelled `handle` posting on the PR head, predates the relay. - Tests that assume every generated file runs the agent filter through a `without_relay` helper, and a new snapshot covers the relay file. Adopters pick up the new file on their nightly regen after the next release. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01CxRxDRznNJKdTBwHB5kwHt > _This was written by Claude Code on behalf of max-sixty_ --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
|
Both answers below; the second one turns out to be a When we scrubThe discriminator is who chose the child's working directory, and after this PR it splits four sites two ways: Scrub — the cwd names a worktree
Keep — the child runs where the user already was, so the inherited context is the user's context:
The The generalizable list already existsIt's The 3-and-4-var hand-rolls aren't a narrower policy. They're a workaround for an ordering artifact in Making I have this building and green locally on Diff--- a/src/shell_exec.rs
+++ b/src/shell_exec.rs
@@ struct Cmd
- envs: Vec<(OsString, OsString)>,
- env_removes: Vec<OsString>,
+ /// Environment mutations in call order: `Some(value)` sets, `None`
+ /// removes. One ordered list rather than a set list plus a remove list so
+ /// a later [`Cmd::env`] overrides an earlier [`Cmd::env_remove`] — the
+ /// property [`Cmd::scrub_git_discovery_env`] relies on when a caller
+ /// scrubs the whole inherited git context and then supplies its own.
+ env_ops: Vec<(OsString, Option<OsString>)>,
@@ fn apply_common_settings
- for (key, val) in &self.envs {
- cmd.env(key, val);
- }
- for key in &self.env_removes {
- cmd.env_remove(key);
+ // In call order, so the last mutation naming a variable wins.
+ for (key, val) in &self.env_ops {
+ match val {
+ Some(val) => cmd.env(key, val),
+ None => cmd.env_remove(key),
+ };
}
--- a/src/git/repository/working_tree.rs
+++ b/src/git/repository/working_tree.rs
@@ fn run_command_output
- .env_remove("GIT_DIR")
- .env_remove("GIT_WORK_TREE")
- .env_remove("GIT_COMMON_DIR")
- .env_remove("GIT_INDEX_FILE"),
+ .scrub_git_discovery_env(),
@@ impl TempIndex fn command
- .env_remove("GIT_DIR")
- .env_remove("GIT_WORK_TREE")
- .env_remove("GIT_COMMON_DIR")
+ .scrub_git_discovery_env()
.env("GIT_INDEX_FILE", self.path());
One call it surfacesUsing the whole list means worktree-local plumbing now also drops an inherited Separately and independent of this PR: |
|
ok so can we simplify; canonicalize this? |
`apply_common_settings` applied every `env` and then every `env_remove`, so on one `Cmd` a removal beat a set no matter what order the builder was called in. That is why the worktree-local scrub sites hand-rolled a 3- or 4-var subset of `INHERITED_GIT_PATH_VARS` instead of calling the shared helper: both set one of the five themselves (`TempIndex` its own `GIT_INDEX_FILE`, `with_object_store_env` a redirected repository's `GIT_OBJECT_DIRECTORY`), and the full scrub would have clobbered their own values, not just the inherited ones. Hold one call-ordered list of env mutations instead. Then `.scrub_git_discovery_env()` followed by `.env(...)` means exactly "drop whatever was inherited, keep what I chose", every site uses the one list, and the `CLAUDE.md` paragraph shrinks back to the single rule. No existing `Cmd` sets and removes the same variable, so the reordering is a no-op for every current caller. One behavior delta: worktree-local plumbing now also drops an *inherited* `GIT_OBJECT_DIRECTORY`, which the hand-rolled list kept. A redirected repository re-sets its own immediately after the scrub, so the delta is the non-redirected case with an inherited value, which git supplies to push-quarantine hooks. It is pinned to the invoking context exactly as `GIT_DIR` is, so dropping it is consistent with the rest of the list; recorded as a deliberate call in `scrub_git_discovery_env_vars`'s spec. `test_env_mutations_apply_in_call_order` pins the ordering property the collapse rests on — it fails under the old set-then-remove application.
|
Done — pushed as 932d8cc0c. All three hand-rolled lists are gone; every scrub site now calls What changed
The three sites collapse to one line each, and the The
|
worktrunk-bot
left a comment
There was a problem hiding this comment.
The collapse itself checks out: apply_common_settings runs the inherited-GIT_* absolutization loop before env_ops, so a scrub anywhere in the builder chain still beats it, and the redirected-repository path re-sets both object-store vars after the scrub. One finding on the rewritten classification.
The exemption for Repository::run_command is justified by a cwd fact the code contradicts. Both CLAUDE.md and the scrub_git_discovery_env_vars spec now say its cwd is discovery_path, "wherever the user invoked wt". discovery_path is whatever Repository::at was handed, and several production sites hand it a worktree wt chose rather than the user's cwd — Repository::at(&worktree_path) for the post-switch hook repo in src/commands/worktree/switch.rs, Repository::at(&spec.worktree_path) in src/commands/run_pipeline.rs, Repository::at(&destination_path) in src/commands/worktree/finish.rs, and Repository::at(ctx.worktree_path) for the pre-remove render repo in src/output/handlers.rs.
The classification's outcome is still right, which is why this is a doc fix rather than a code one: repo-level questions are worktree-agnostic within one repository, and every worktree-scoped answer routes through WorkingTree (current_worktree() is worktree_at(discovery_path)), which this PR makes scrub. But the reason given is what the next implementer applies. Stated as it is, the single rule reads "cwd names a wt-chosen worktree → scrub" with Repository::run_command exempt by construction — so a new repo-level call added at one of those sites looks covered by the exemption when the rule's own test says it isn't. Suggestions inline on both copies naming the real reason.
Verdict still @max-sixty's: the diff decides what wt remove's deletion gate observes, and the GIT_OBJECT_DIRECTORY question the author raised on 932d8cc0c is still open.
…ope, not cwd Both the `CLAUDE.md` rule and the `scrub_git_discovery_env_vars` spec said repo-level plumbing's cwd is `discovery_path`, "wherever the user invoked `wt`". That is what the exemption was resting on, and it is false for several production sites: `Repository::at` is handed a `wt`-chosen worktree in `commands/worktree/switch.rs` (both hook repos), `commands/run_pipeline.rs`, `commands/worktree/finish.rs`, and `output/handlers.rs` (the `pre-remove` render repo), and `run_command_bounded` runs with `current_dir(&self.discovery_path)`. The classification's outcome is unchanged — repo-level questions are worktree-agnostic within one repository, and every worktree-scoped answer routes through `WorkingTree` (`current_worktree()` is `worktree_at(discovery_path)`), which this PR makes scrub. But stated as it was, the single rule read "cwd names a `wt`-chosen worktree → scrub" with `Repository::run_command` exempt by construction, so a new repo-level call at one of those sites would look covered by an exemption the rule's own test says it isn't. Name the real reason instead. Doc-only; no behavior change.
worktrunk 0.78.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 - **Hook scripts read renamed context keys**: the JSON piped to every hook drops `worktree`, `repo_root`, `main_worktree`, and `main_worktree_path` in favour of `worktree_path`, `repo_path`, `repo`, and `primary_worktree_path`. Config templates migrate on load, so hooks written with the old names keep working; scripts reading the JSON, `--execute` templates, and `--var` overrides need updating. (Breaking.) ([#4080](max-sixty/worktrunk#4080)) - **`wt config plugins pi` installs for Pi; oh-my-pi moves to `wt config plugins omp`**: `pi install` wrote an oh-my-pi hook, which Pi never loads; Pi users re-run it to get a Pi extension. Existing oh-my-pi hooks keep working, listed as outdated until `wt config plugins omp install`. (Breaking: scripts that run `wt config plugins pi` for oh-my-pi need `omp`.) [Docs](https://worktrunk.dev/claude-code/#oh-my-pi) ([#4135](max-sixty/worktrunk#4135), thanks @ashebanow) - **Interactive prompts no longer open with a blank line**: `wt config shell install`, `wt config plugins claude install`, and the commit-message setup offer in `wt merge` began with one. ([#4059](max-sixty/worktrunk#4059)) - **`wt config show` gives a single `wt config shell install` hint**: an outdated wrapper, a fish wrapper at the deprecated `conf.d` path, and missing fish completions each printed their own hint. The zsh `compinit` snippet is now syntax-highlighted. ([#4059](max-sixty/worktrunk#4059)) - **`wt config update --output <path>` confirms the write**: it now prints `✓ Wrote user config migration @ ~/migrated.toml` where it printed nothing. `--output=-` stays silent. ([#4053](max-sixty/worktrunk#4053)) ### Fixed - **Removal no longer discards untracked files hidden by `status.showUntrackedFiles = no`**: under that setting, a worktree holding only untracked files looked clean, so `wt remove`, `wt merge`, and `wt step prune` removed it without `--force`. Safety checks now always count untracked files, and auto-staging warnings list every file they stage. ([#4111](max-sixty/worktrunk#4111), thanks @Duang777) - **`wt remove` and `wt merge` check the right worktree under an inherited `GIT_DIR`**: run from a `!wt` git alias or a git hook, which pass `GIT_DIR` down, `wt remove` could delete a dirty worktree without `--force`, and `wt merge` could refuse a clean merge. Both now check the worktree they act on. ([#4082](max-sixty/worktrunk#4082), thanks @Duang777) - **`wt merge` no longer deletes a worktree locked with `git worktree lock`**: the merge completes and prints `Worktree preserved (locked)`. Every Worktrunk removal refuses a locked worktree, even with `--force`; run `git worktree unlock <path>` first. ([#4073](max-sixty/worktrunk#4073), thanks @Duang777) - **`wt config update` no longer overwrites a config edited while its prompt is open**: it wrote the pre-prompt snapshot over the newer file and reported success. It now fails with the path and leaves the newer file; re-running previews the current contents. ([#4127](max-sixty/worktrunk#4127), thanks @zach-hammad-vs for reporting) - **`wt step prune` no longer deletes a branch created minutes ago from an older commit**: `--min-age` aged a branch without a worktree by its commit's date, so a new branch off a day-old commit was pruned on the next run. Age now comes from the branch's oldest reflog entry. ([#4077](max-sixty/worktrunk#4077)) - **A comment or blank line above an inline config section no longer breaks the config**: a save or migration that rewrote `commit = { … }` as `[commit]` put that line inside the brackets. `wt switch`, `wt merge`, `wt remove`, and several `wt step` commands then failed with `Failed to load config`; `wt list` warned and ran without the config. Saves also dropped unrecognized keys from inline sections. ([#4120](max-sixty/worktrunk#4120), thanks @zach-hammad-vs for reporting) - **Config saves keep the trailing comment on a value they rewrite**: a save such as answering the commit-generation offer dropped the comment after each value it rewrote, including one after an inline section's closing brace. ([#4138](max-sixty/worktrunk#4138)) - **Ignored project-config keys warn from every worktree**: an unknown key in `.config/wt.toml`, or one that belongs in user config such as `[merge]`, warned only in the main worktree, so `wt merge` from a linked worktree ignored it silently. ([#4145](max-sixty/worktrunk#4145), thanks @ee-prog for reporting) - **`wt merge` skips `post-commit` when it removes that hook's worktree**: before, the hook ran in the primary worktree when the removed one sat inside the repository, and otherwise didn't run. The merge now prints `▲ Skipped post-commit`; move work that must finish there to `pre-remove`. ([#4049](max-sixty/worktrunk#4049)) - **`wt switch` recovers from a removed worktree in a bare repository**: `wt switch` and the picker surfaced git's raw `fatal: Unable to read current working directory` instead, and the removed-directory message lacked `wt switch ^`. ([#4067](max-sixty/worktrunk#4067)) - **`wt config shell install fish` puts the wrapper where fish reads it under a custom `$XDG_CONFIG_HOME`**: the wrapper always went to `~/.config/fish/functions/`, so install reported success while `wt switch` changed no directory. On Windows, the fish completion moves from `%APPDATA%\fish\completions` to the wrapper's directory. ([#4107](max-sixty/worktrunk#4107)) - **`wt config shell install zsh` honours `$ZDOTDIR` only when it is absolute**: an empty or relative value resolved against the current directory, so install appended to a `.zshrc` under the current directory and reported success while the file zsh reads went untouched. A non-absolute value now falls back to `$HOME`. ([#4085](max-sixty/worktrunk#4085)) - **`wt config shell install` for Nushell no longer deletes a `wt.nu` under the current directory**: an empty or relative `$XDG_CONFIG_HOME` resolved against it, so install removed a `nushell/vendor/autoload/wt.nu` beneath it unread, as a stale wrapper. It now falls back to `~/.config`, which also fixes unread `tea` logins that let `wt switch pr:<n>` treat a Gitea host as GitHub. ([#4104](max-sixty/worktrunk#4104)) - **`wt switch --create` names the branch a failed worktree add leaves behind**: `git worktree add -b` writes the branch ref before populating the worktree, so a failure in between left the branch with no worktree, and the next attempt reported a name collision. The error now says how to delete or reuse it. ([#4109](max-sixty/worktrunk#4109), thanks @technicalpickles for reporting) - **`wt config shell install` no longer tells an already-wrapped shell to restart**: reinstalling from a shell with the wrapper loaded, such as after a version bump, printed `↳ Restart shell to activate shell integration`. ([#4059](max-sixty/worktrunk#4059)) - **`wt config shell install` migrates a deprecated `conf.d` fish wrapper when `~/.config/fish/functions` is missing**: before, only `wt config shell install fish` migrated it. `wt config show` now reports that wrapper even when fish isn't on `PATH`. ([#4059](max-sixty/worktrunk#4059)) - **Plugin status and uninstall checks ask the agent CLIs**: `wt config show` could list an installed Claude Code plugin or Gemini CLI extension as not installed, and `wt config plugins claude|codex uninstall` could report success over a marketplace still configured. A repeat Claude uninstall now runs both removals instead of stopping at `Plugin not installed`. ([#4048](max-sixty/worktrunk#4048), [#4054](max-sixty/worktrunk#4054)) - **`wt config plugins opencode install` no longer writes the plugin into the current directory**: with `OPENCODE_CONFIG_DIR` set but empty, it wrote `plugins/worktrunk.ts` there, typically inside a repository, reporting success though OpenCode never saw it. An empty value now counts as unset. ([#4084](max-sixty/worktrunk#4084)) - **The OpenCode plugin clears its activity marker when OpenCode 1 disposes it**: only explicit session deletion cleared it, so a finished session kept its `💬` and `wt list` showed it as active until `wt config state marker clear` was run by hand. ([#4129](max-sixty/worktrunk#4129), thanks @drewdas for reporting) - **`wt config update` migrates `[ci] platform` into a `[forge]` section that only sets `hostname`**: that config, common with GitHub Enterprise and self-hosted GitLab, kept the deprecated key with no deprecation warning. ([#4061](max-sixty/worktrunk#4061)) - **Deprecated keys in an inline `[projects]` entry now migrate**: `"example.com/org/repo" = { merge = { no-ff = true } }` skipped the migration the section form got, so the per-project setting was ignored. ([#4122](max-sixty/worktrunk#4122), thanks @zach-hammad-vs for reporting) - **A deprecated config section the migration can't rewrite now warns**: `select = "not a table"`, or a `[select]` whose `[switch.picker]` destination is already set, was ignored without a message. It now reports `unknown field select (will be ignored)`. ([#4121](max-sixty/worktrunk#4121), thanks @zach-hammad-vs for reporting) - **`wt config update` no longer changes what a template renders**: it could rename `{{ repo_root }}` inside a quoted s See merge request: Harmonybrew/homebrew-core!20435
Summary
wtinheritsGIT_DIRpinned to the invoking worktree — a!wtgit alias from a linked worktree is one source; git also exports discovery vars to hooks it spawns — worktree-local git forwarded it andwt merge/wt removeconsulted the wrong index.GIT_DIR/GIT_WORK_TREE/GIT_COMMON_DIR/GIT_INDEX_FILE) on worktree-local plumbing (WorkingTree::run_command,TempIndex, one ignored-file listing). Hand-rolled removes, not the full scrub —GIT_OBJECT_DIRECTORYfrom redirected repos must survive.Repository::run_commandstill keeps the inherited context (repo_pathdiffers when invoked viagit alias(git wt ...) in bare-layout repositories #1914).prepare_diff, commit-prompt capture, fsmonitor left for follow-ups).Review note
ensure_clean/is_dirtyroute throughWorkingTree::run_command. Under an inheritedGIT_DIRthe gate previously read the invoking index while standing in the target worktree — a silent data-loss path forwt remove, not merely a wrong-tree answer. Regression:test_remove_refuses_dirty_target_when_git_dir_names_invoking_worktree.Test plan
cargo test --test integration git_dir_nameswt merge/wt removecommand names (notgit wt)CLAUDE.mdsplits user-command relocation from worktree-local plumbing