Repository navigation
Conversation
worktrunk-bot
left a comment
There was a problem hiding this comment.
The WorkingTree::run_command_output scrub is the right fix for the path this targets. I reproduced the mechanism outside worktrunk to be sure of it: with GIT_DIR pinned to a linked worktree's private gitdir, git status --porcelain run in the main worktree reports D feature.txt — exactly the phantom overlap ensure_no_target_conflicts turns into Can't push to local main branch: conflicting uncommitted changes. One gap to resolve before this lands.
WorkingTree::prepare_diff is the same class of call site and is still unscrubbed. In src/git/repository/diff.rs, PreparedDiff::command's DiffSource::Repository arm builds Cmd::new("git") … .current_dir(path) with the identical with_object_store_env + path_to_logging_context shape as run_command_output, and WorkingTree::prepare_diff hands it self.path. Two consumers produce wrong output under a !wt alias from a linked worktree:
compute_live_worktree_diffinsrc/commands/picker/items.rstakesWorktreeDiffState::TrackedOnly => worktree.prepare_diff([base]), while the sibling armHasUntracked | Unknown => worktree.prepare_diff_with_untracked(…)routes throughTempIndex, which this PR does scrub. After this change the two arms of one match read different worktrees.src/summary.rs's "Working tree diff: uncommitted changes" block (repo.worktree_at(wt_path).prepare_diff(["HEAD"])) would feed the invoking worktree's uncommitted diff into the branch summary for a different branch.
It isn't a one-liner: Repository::prepare_diff shares that same DiffSource::Repository arm and must keep the inherited context per the split you documented, so the variant has to carry which side it is on. I'm happy to push that as a commit on this branch if you'd prefer not to.
Worth deciding together with it: once the diff site is fixed the same way, three sites hand-roll the same env_remove list, where CLAUDE.md asks for Cmd::scrub_git_discovery_env or scrub_git_discovery_env_vars. The existing helper genuinely can't be reused as-is — apply_common_settings applies env-removes after envs, so it would strip both the object-store env and TempIndex's own GIT_INDEX_FILE — so the shape that does work is a helper for the worktree-selection trio (GIT_DIR, GIT_WORK_TREE, GIT_COMMON_DIR), leaving GIT_INDEX_FILE to each call site.
One process note: this changes which index every worktree-level git status reads, including the dirty gates wt remove and wt merge cleanup consult before deleting a worktree (WorkingTree::ensure_clean and is_dirty both route through run_command_output). The direction is toward correctness — the pre-fix behavior could mask a genuinely dirty target — but this repo's review guidance holds changes reaching that surface for a human, so I'm not approving; requesting @max-sixty.
|
Addressed the review in 482b825:
Still waiting on @max-sixty for the dirty-gate surface ( |
worktrunk-bot
left a comment
There was a problem hiding this comment.
Both prior findings are resolved, and I verified the substance rather than the description: WorkingTree::prepare_diff now goes through PreparedDiff::for_worktree, Repository::prepare_diff still routes through PreparedDiff::new with relocate: false (its path is discovery_path(), so the alias context is the right one to keep), and the env_remove/env ordering holds — apply_common_settings applies env_removes after envs, and the removes list never names GIT_OBJECT_DIRECTORY/GIT_ALTERNATE_OBJECT_DIRECTORIES, so with_object_store_env survives the scrub at all three sites and TempIndex's own GIT_INDEX_FILE survives at the fourth. I also checked the two #1914 regression tests in tests/integration_tests/bare_repository.rs against the new scrub: both compare an aliased invocation to a baseline with no GIT_* set, so the scrub makes the aliased path converge on the baseline rather than diverge from it.
One same-class site the split leaves behind, outside this diff. stop_fsmonitor_daemon in src/git/remove.rs runs Cmd::new("git").args(["fsmonitor--daemon", "stop"]).current_dir(worktree.path()) with no scrub, and start_fsmonitor_daemon_at in src/git/repository/mod.rs does the same with a bare std::process::Command (it applies apply_hermetic_test_env and scrub_directive_env_vars, but not the git-discovery scrub). Both relocate git into a wt-chosen worktree, so under git wt remove <other-branch> from a linked worktree the stop IPC goes to the invoking worktree's daemon and the one being removed is never asked to exit. On Unix this PR incidentally papers over it: worktree.git_dir() now resolves correctly, so force_kill_fsmonitor_via_socket finds the target's still-live socket and escalates. On Windows that function is fn force_kill_fsmonitor_via_socket(_socket: &Path) {}, so nothing catches it — which is the leaked-forever daemon the function's own doc comment exists to prevent. Pre-existing rather than introduced here, and a one-call fix at each site; happy to push it onto this branch if you'd rather keep the PR scoped as-is.
Verdict is unchanged from the last round — the dirty-gate surface is still @max-sixty's call, not mine.
|
Adding one more same-class site to the review I just posted — a different subsystem from the fsmonitor pair, and the one with a user-visible wrong result rather than a leaked process.
The fix is the shape this PR already established: Whether this and the fsmonitor sites land here or as follow-ups is your call — but I'd not ship the classification ahead of them. The Minor and separable, this one inside the diff: Reproduction of the
|
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 <[email protected]>
The same inherited GIT_DIR that fooled status also reaches the picker and branch-summary diffs. Carry relocate on DiffSource so repository diffs keep the alias context, and share the worktree-selection trio instead of repeating env_remove. Co-authored-by: Cursor <[email protected]>
Same relocate class as WorkingTree::run_command: run_git_capture, fsmonitor stop/start, and list_ignored_entries (full scrub — nothing to preserve). Extend the classification docs to name them. Co-authored-by: Cursor <[email protected]>
482b825 to
f87f615
Compare
|
Rebased onto main (clears the #4073 conflict) and addressed the follow-up sites in f87f615:
Still waiting on @max-sixty for the dirty-gate surface. |
worktrunk-bot
left a comment
There was a problem hiding this comment.
codecov/patch is red on exactly one line, and that line can't be reached by the job that measures it. 50 of 51 patch lines are hit — 98.03% against a 98.29% target — and the single miss is the new scrub_git_discovery_env_vars(&mut cmd) call in start_fsmonitor_daemon_at. That function's only caller is macOS-gated: in src/commands/list/collect/mod.rs, fsmonitor_worktrees is built under #[cfg(target_os = "macos")] from repo.is_builtin_fsmonitor_enabled(), and the #[cfg(not(target_os = "macos"))] arm hard-codes an empty vec. So on the Linux code-coverage runner the whole function is unreachable — every line of it already misses there, and this PR added one more. Two ways out, each with a cost worth weighing against simply approving the red: a unit test calling it directly would cover the line but starts a real fsmonitor daemon against the test repo, and putting #[cfg(target_os = "macos")] on the function (plus its call site) would drop the line from instrumentation entirely, at the price of no longer compile-checking it on Linux and Windows. Root CLAUDE.md → Coverage makes this check a merge gate needing explicit approval, so it is @max-sixty's call either way — recording the arithmetic so it doesn't have to be re-derived.
Separately, the fsmonitor pair ended up scrubbing two different ways: stop_fsmonitor_daemon removes the selection trio plus GIT_INDEX_FILE, start_fsmonitor_daemon_at removes all five. The two spawns are equivalent in effect — neither carries an object-store env or a TempIndex — so the split buys nothing, and it is what makes the new classification prose wrong in two places. The inline suggestions collapse it to one rule, full scrub at both fsmonitor sites, which is the same reasoning you applied when restoring list_ignored_entries to scrub_git_discovery_env().
Verdict stays COMMENT for the reason the last two rounds gave.
|
this changes way too many core fields @Duang777 additional PRs need more care, please |
|
@worktrunk-bot was there actually an underlying issue here? Make a concise issue with a reproduction if so |
|
Yes — filed as #4081 with a reproduction. Corrected 2026-09-13: this comment originally attributed the failure to Confirmed on The issue is diagnosis and reproduction only. I left the fix scope open rather than proposing one: |
|
Resubmitted as a narrower PR that only touches the #4081 path ( Sorry for the oversized first attempt. |
|
Narrow follow-up: #4082 |
`WorkingTree::prepare_diff`, `prepare_staged_diff` and `prepare_commit_diff` run `diff-index`/`diff-tree` in a worktree Worktrunk picked, but they kept inherited `GIT_DIR`, `GIT_WORK_TREE` and `GIT_INDEX_FILE`. When `wt` runs from a Git hook or a `!wt` alias in a different worktree, those diffs read the invoking worktree's index and HEAD. So `wt step commit --branch <b>` built its stats line and LLM prompt from the wrong worktree's staged changes. The picker's diff preview and the summary diff had the same problem. AGENTS.md requires this scrub for worktree-local plumbing, and the sibling paths already apply it (`WorkingTree::run_command` and `TempIndex::command`). This PR applies `scrub_git_discovery_env()` to the three `WorkingTree` diff constructors. `Repository::prepare_diff` is repo-level and keeps the inherited context, as `Repository::run_command` does. `with_object_store_env` still runs after the scrub, so a redirected repository's own `GIT_OBJECT_DIRECTORY` survives. The new `test_step_commit_show_prompt_branch_ignores_inherited_git_context` stages a file in each of two worktrees. It runs `wt step commit --show-prompt --branch feature` with the primary worktree's `GIT_DIR`/`GIT_WORK_TREE`/`GIT_INDEX_FILE`. Before the fix, the preview diffed `caller_only.txt`, the invoking worktree's file. Now it diffs `feature_only.txt`. The closed #4075 included this change in a much broader diff. It was dropped there for scope, not on approach. The narrower #4082 that landed instead covered only `WorkingTree::run_command`, `TempIndex` and the ignored-file listing. Co-authored-by: worktrunk-bot <[email protected]>
Summary
!wtgit alias from a linked worktree exportsGIT_DIRpinned to that worktree's private gitdir (git wt mergefromfeature→GIT_DIR=.git/worktrees/feature).WorkingTree::run_commandrelocated git withcurrent_dirbut still forwarded thatGIT_DIR, sostatus/read-tree/rev-parse --git-dirused the invoking worktree's index.wt merge's target conflict check then compared the feature index to the main worktree and refused a clean merge (Can't push to local main branch: conflicting uncommitted changesnaming the feature's own files).Repository::run_commandstill keeps the inherited context so the alias finds the repository (repo_pathdiffers when invoked viagit alias(git wt ...) in bare-layout repositories #1914).Test plan
cargo test --test integration test_merge_syncs_target_when_git_dir_names_the_source(red before the scrub: false conflict onfeature.txt; green after)cargo test --test integration test_merge_fast_forwardcargo test --test integration test_merge_as_git_subcommandcargo test --lib -- working_tree:: git::remove::git wt mergefrom a feature worktree (alias.wt = "!wt") — merge succeeds, main is clean and has the feature filesMade with Cursor