Repository navigation
Preserve non-UTF-8 ignored paths - #4257
Conversation
worktrunk-bot
left a comment
There was a problem hiding this comment.
Now that non-UTF-8 names reach the entry list, wt step copy-ignored --format=json panics on them. Both JSON payloads in src/commands/step/copy_ignored.rs build the entry path with serde_json::json!({ "path": relative, ... }). relative is a &Path, and json! unwraps to_value, which fails with path contains invalid UTF-8 characters. I reproduced this on Linux with an ignored file named cache-\xff.bin:
$ wt step copy-ignored --dry-run --format=json
thread 'main' panicked at src/commands/step/copy_ignored.rs:187:21:
called `Result::unwrap()` on an `Err` value: Error("path contains invalid UTF-8 characters", ...)
Without --dry-run, the panic happens at the second "path": relative site. That is after the file has been copied, so the caller gets exit 101 instead of the report. Before this PR, both calls exited cleanly, because the lossy String serialized fine. The new integration test only covers text output. It doesn't catch this because text output goes through format_path_for_display.
Both sites are outside the diff, so I can't attach suggestions to them. The smallest fix is "path": relative.to_string_lossy(), at both sites, plus a --format=json case in test_copy_ignored_preserves_non_utf8_filename. I can push that as a commit if you'd like.
Superseded by the review on a later commit.
Summary
git ls-files -zwhen locating ignored entries forstep copy-ignoredandstep promote.Root cause
list_ignored_entriesdecoded Git path bytes withString::from_utf8_lossybefore using the result as a filesystem path. An invalid UTF-8 byte became a replacement character, so Worktrunk looked up a different path.Verification
cargo run -- hook pre-merge --yespassed locally.codecov/patchpassed on the current head.