Repository navigation
fix(config): report a failed migration diff instead of rendering none - #4126
Conversation
worktrunk-bot
left a comment
There was a problem hiding this comment.
Three things, two of which I've pushed fixes for along with a changelog entry, since this is a bot-authored PR.
The warning drops the cause for every failure that isn't git's own nonzero exit. format_migration_diff_block renders e.to_string(), and for an anyhow error that prints only the outermost context. The bail! arm carries its whole payload inline so that one reads fine, but a Cmd::run() spawn failure (git missing from PATH, a cancelled background command) or a tempdir/write failure reaches the user as the bare line failed to run git diff --no-index, with the No such file or directory (os error 2) underneath it discarded — the same shape of silence this PR exists to remove. Pushed: render {e:#}, matching warning_message(format!("Failed to spawn pending hooks: {err:#}")) in src/commands/hooks.rs.
The new unit test spawns git without the hermetic config floor. test_migration_diff_block_separates_identical_from_changed runs the real git diff, and no fixture constructor runs in that process, so shell_exec::enable_hermetic_test_env is never latched and the child reads the developer's own global config. That is the one thing tests/CLAUDE.md → Git Config Isolation states without exception: "No git the suite runs reads the developer's ~/.gitconfig, whatever the test drives it through and wherever the fixture lives." Any unparsable diff.* value in a developer's config turns the identical-content assertion into the new failure arm, i.e. reports the change under test as broken. Pushed: latch the floor at the top of the test.
Reproduction
$ printf '[diff]\n\talgorithm = wt-bogus-algorithm\n' > /tmp/hostile/gitconfig
$ GIT_CONFIG_GLOBAL=/tmp/hostile/gitconfig cargo test --lib test_migration_diff_block_separates_identical_from_changed
assertion `left == right` failed: identical content renders nothing
left: "▲ Could not render the proposed diff\n git diff --no-index, exit status: 128\n error: unknown value for config 'diff.algorithm': wt-bogus-algorithm\n …"
right: ""
With the latch in place the same command passes. The two new integration tests are unaffected — wt_command() already applies the floor to the wt child.
No changelog entry. The behavior is user-visible and the sibling config fixes in flight all carry one, so I added one under Unreleased → Fixed.
One thing I deliberately left alone, as a trade rather than a defect: the failure arm hand-rolls bail!("git diff --no-index, {}\n{}", output.status, stderr), where the git-capture sites under src/git/repository/ all build CommandError::from_failed_output("git", &args, &output). That type normalizes \r out of the captured streams (its doc notes a raw \r overprints exactly the gutter this message renders into), keeps stdout — git writes some errors there — and records the terminating signal, which is what ErrorExt::interrupt_signal() reads. As written, a Ctrl-C landing on this child renders as Could not render the proposed diff … signal: 2 and wt config update proceeds to its Apply updates? prompt instead of treating the interrupt as one. The window is milliseconds wide and the hand-rolled message is the more readable of the two, so the current choice is defensible — but it is a choice, and it is the one place this change steps outside the repo's structured-error plumbing.
The warning rendered `e.to_string()`, which for an anyhow error prints only
the outermost context: the `bail!` arm carries git's status and stderr
inline, but a spawn or tempfile failure reached the user as a bare
`failed to run git diff --no-index` with its cause dropped. Render `{e:#}`.
The new unit test spawns the real `git diff` and no fixture constructor runs
in that process, so the hermetic floor was never latched and the child read
the developer's own global config — a single unparsable `diff.*` value there
turns the identical-content assertion into the failure arm. Latch it.
Add the changelog entry for the fix.
worktrunk-bot
left a comment
There was a problem hiding this comment.
fast-checks is red on this head, in the doc gate (RUSTDOCFLAGS='-Dwarnings' cargo doc --no-deps --document-private-items). The new docstring on the public format_migration_diff_block opens with an intra-doc link to format_migration_diff, which is private, so rustdoc rejects it under -D warnings:
error: public documentation for `format_migration_diff_block` links to private item `format_migration_diff`
--> src/config/deprecation.rs:1645:29
= note: this link resolves only because you passed `--document-private-items`, but will break without
= note: `-D rustdoc::private-intra-doc-links` implied by `-D warnings`
I reproduced it locally and it clears by dropping the link brackets — a plain code span, which is what the sibling public functions in this file already use for private helpers (check_and_migrate refers to format_deprecation_details that way). Pushing that. doctest was unaffected: the lint only fires when the private item is documented, which is exactly what --document-private-items does and cargo test --doc doesn't.
Everything else on this head is green, including codecov/patch and the three test legs.
`format_migration_diff_block` is public and `format_migration_diff` is not, so the link tripped `rustdoc::private_intra_doc_links` under the `doc` pre-merge gate's `-Dwarnings`, failing `fast-checks`. A plain code span is what the sibling public functions here already use for private helpers.
# Conflicts: # CHANGELOG.md
Drop this PR's CHANGELOG.md entry. Changelog entries are written from the commits at release time (CLAUDE.md, Releases), so an open PR carrying an entry drops it rather than resolving a conflict on it.
Problem
format_migration_diffread only stdout afterCmd::run()handed back acaptured
Output, and a nonzero child status is stillOkthere. Anygit diff --no-indexthat failed before writing a patch — exit 128, emptystdout — was therefore indistinguishable from two identical files, so the
Proposed diff:block vanished fromwt config showand from the previewwt config updateprompts on, with nothing said about why.The realistic trigger is the user's own git config.
git diff --no-indexhonors
diff.external, so a broken, interactive, or GUI diff programconfigured for ordinary work was being handed Worktrunk's two temp files.
Solution
Two changes, both in the renderer:
"differs", and everything else is a failure carrying git's stderr. The
helper returns
anyhow::Result<Option<String>>, which also retires the.expect("git diff --no-index failed")that would have panicked when gitcould not be spawned at all.
--no-ext-diff, sodiff.externalis never consulted for a patchWorktrunk renders for itself.
Both consumers now go through one
format_migration_diff_block, whichrenders the patch, nothing, or a warning with git's stderr in a gutter:
The preview degrades rather than the command failing, because the migration
itself is computed in memory by
compute_migrated_contentand is unaffectedby the renderer. The deprecation warnings that describe each change still
print, so a user prompted with a degraded preview can see that the patch is
missing and decline.
Testing
Two integration tests in
tests/integration_tests/config_show.rs, bothfailing before the change:
test_config_show_reports_failed_migration_diffrunswt config showwith
diff.algorithmset to an unparseable value — a failure that survives--no-ext-diff— and asserts the warning appears. Before the change thecommand printed the deprecation warning and no diff, exit 0.
test_config_show_migration_diff_ignores_external_diffpointsdiff.externalat a nonexistent program and asserts the patch stillrenders.
Both drive the real binary and set the git config per-child via
GIT_CONFIG_COUNT, so nothing global is touched.Closes #4118 — automated triage