Skip to content

fix(config): report a failed migration diff instead of rendering none - #4126

Merged
max-sixty merged 7 commits into
mainfrom
fix/issue-4118
Sep 16, 2026
Merged

max-sixty merged 7 commits into
mainfrom
fix/issue-4118

Conversation

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

Problem

format_migration_diff read only stdout after Cmd::run() handed back a
captured Output, and a nonzero child status is still Ok there. Any
git diff --no-index that failed before writing a patch — exit 128, empty
stdout — was therefore indistinguishable from two identical files, so the
Proposed diff: block vanished from wt config show and from the preview
wt config update prompts on, with nothing said about why.

The realistic trigger is the user's own git config. git diff --no-index
honors diff.external, so a broken, interactive, or GUI diff program
configured for ordinary work was being handed Worktrunk's two temp files.

Solution

Two changes, both in the renderer:

  • Branch on the exit status instead of on stdout: 0 is "identical", 1 is
    "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 git
    could not be spawned at all.
  • Pass --no-ext-diff, so diff.external is never consulted for a patch
    Worktrunk renders for itself.

Both consumers now go through one format_migration_diff_block, which
renders the patch, nothing, or a warning with git's stderr in a gutter:

▲ Could not render the proposed diff
  git diff --no-index, exit code 128
  error: unknown value for config 'diff.algorithm': bogus
  fatal: unable to parse 'diff.algorithm' from command-line config

The preview degrades rather than the command failing, because the migration
itself is computed in memory by compute_migrated_content and is unaffected
by 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, both
failing before the change:

  • test_config_show_reports_failed_migration_diff runs wt config show
    with diff.algorithm set to an unparseable value — a failure that survives
    --no-ext-diff — and asserts the warning appears. Before the change the
    command printed the deprecation warning and no diff, exit 0.
  • test_config_show_migration_diff_ignores_external_diff points
    diff.external at a nonexistent program and asserts the patch still
    renders.

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

@worktrunk-bot worktrunk-bot added the automated-fix Automated CI fix label Sep 15, 2026

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
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.
@max-sixty
max-sixty merged commit 41af9ba into main Sep 16, 2026
37 checks passed
@max-sixty
max-sixty deleted the fix/issue-4118 branch September 16, 2026 06:53
This was referenced Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automated-fix Automated CI fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

config: failed migration diff is treated as no changes

2 participants