Repository navigation
xtask: run per-checkout commands against the invoking worktree; fix switch-task --from - #932
Merged
Merged
Conversation
…k7jb11) create_worktree::repo_root() resolves the *main* checkout (the parent of --git-common-dir), which is right for placing new worktrees but wrong for commands that work on the caller's files. Four commands used it, so from a linked worktree they read and wrote the main checkout instead: - stage-doc-examples rendered the main checkout's examples/ and staged into its docs/examples/, so the worktree's own `q2 render docs` then failed on the missing resource (found in bd-73lilznv); - check-noop-rebuild built the main checkout's q2; - gen-math-spec read and (re)wrote the main checkout's commands.json; - braid-snapshot wrote the main checkout's .braid/snapshot.jsonl. They now use switch_task::current_worktree_root() (--show-toplevel), as the capture-*, pandoc-check, render-corpus-diff and pull-extension-subtree commands already did. repo_root() is renamed main_checkout_root() so the next caller sees what it returns; its remaining callers (create-worktree, render-corpus-diff's reference copy) want the main checkout on purpose. Also fix `switch-task --from <branch>`: it fetched origin/<branch> but then branched off the *local* <branch>, which is usually checked out (and stale) in another worktree, while claiming it had pulled. It now branches off the newer of the two, refuses if they have diverged, and passes --no-track so the topic branch does not track the integration branch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
cargo looks for a crate's workspace by walking up the directory tree, and skips (rather than stops at) a workspace that excludes the crate. In the main checkout there is nothing above the repo root, so the excluded crates end up standalone. A worktree lives inside the main checkout under .worktrees/, so cargo walks past the worktree's root Cargo.toml into the main checkout's, which does not list them, and fails with "current package believes it's in a workspace when it's not". From any worktree: - crates/wasm-qmd-parser could not be built at all; - crates/pampa/fuzz and crates/tree-sitter-language-wasm-shim failed `cargo metadata`, breaking xtask's check_feature_sets::discovers_the_wasm_consumers_in_this_repo. Add an empty [workspace] to each, as wasm-quarto-hub-client already has for the same reason (and as `cargo fuzz init` generates), and note the rule at the root `exclude` list. Nothing changes in the main checkout or CI, where these crates were already standalone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes bd-cvk7jb11, which turned up during bd-73lilznv (#929).
Commands that wrote to the main checkout from a worktree
create_worktree::repo_root()returns the main checkout, the parent of--git-common-dir. That is the right root for placing new worktrees, but four commands also used it to find the files they work on. Run from.worktrees/<x>/, each of them read or wrote the main checkout instead:stage-doc-examplesrendered the main checkout'sexamples/and staged into itsdocs/examples/. The worktree's ownq2 render docsthen failed with "Declared resource …/docs/examples does not exist on disk".check-noop-rebuildbuilt the main checkout's q2.gen-math-specread and rewrote the main checkout'scommands.json.braid-snapshotwrote the main checkout's.braid/snapshot.jsonl.They now use
switch_task::current_worktree_root()(--show-toplevel). The capture-*,pandoc-check,render-corpus-diffandpull-extension-subtreecommands already used it.repo_root()is renamedmain_checkout_root()so the next caller can see what it returns. Its two remaining callers,create-worktreeandrender-corpus-diff's reference copy, want the main checkout on purpose.switch-task --from <branch>branched off a stale tipIt fetched
origin/<branch>but then branched off the local<branch>, while printing "after pull". The local branch is usually checked out, and stale, in another worktree;mainin the main checkout is the common case. It now chooses the start point like this:origin/<branch>is newer.--no-track, so the topic branch never tracks the integration branch..claude/rules/worktrees.mdis updated to match.Excluded crates walked up into the main checkout's workspace
cargo finds a crate's workspace by walking up parent directories. It skips, rather than stops at, a workspace that excludes the crate. In a worktree under
.worktrees/, the walk therefore continues past the worktree's rootCargo.tomlinto the main checkout's, which doesn't list the crate. The three excluded crates without a[workspace]of their own were affected:crates/wasm-qmd-parsercould not be built from a worktree at all.crates/pampa/fuzzandcrates/tree-sitter-language-wasm-shimfailedcargo metadata. This brokecheck_feature_sets::discovers_the_wasm_consumers_in_this_repoin every worktree.Each now declares an empty
[workspace]. That is what cargo's error message suggests and whatwasm-quarto-hub-clientalready does for the same reason. A note at the rootexcludelist states the rule. Nothing changes in the main checkout or CI.Verification
cargo xtask stage-doc-examplesnow stages into that worktree, and the main checkout stays untouched and clean.cargo nextest run -p xtaskpasses 250/250 from a worktree; it was 249/250 before the[workspace]change.cargo metadatasucceeds for all three excluded crates andnpm run build:wasmpasses; hub-client builds through the shim.wasm-qmd-parsernow gets past workspace lookup. Its fullwasm-packbuild was not run locally; CI's WASM jobs cover it.cargo clippy -p xtask --all-targets -- -D warningspasses on the host and with--target x86_64-pc-windows-msvc.q2 render --strict claude-notesis clean.🤖 Generated with Claude Code