Skip to content

Preserve non-UTF-8 ignored paths - #4257

Merged
max-sixty merged 4 commits into
max-sixty:mainfrom
Duang777:fix/copy-ignored-non-utf8-paths
Sep 25, 2026
Merged

max-sixty merged 4 commits into
max-sixty:mainfrom
Duang777:fix/copy-ignored-non-utf8-paths

Conversation

@Duang777

@Duang777 Duang777 commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Preserve raw Git path bytes from git ls-files -z when locating ignored entries for step copy-ignored and step promote.
  • Convert entry names for JSON output only, so non-UTF-8 paths can be copied without a serialization panic.
  • Cover a non-UTF-8 ignored filename in a Linux CLI regression, including dry-run and actual-copy JSON output.

Root cause

list_ignored_entries decoded Git path bytes with String::from_utf8_lossy before 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 --yes passed locally.
  • Linux CI and codecov/patch passed on the current head.

This was written by Codex on behalf of max-sixty

worktrunk-bot
worktrunk-bot previously approved these changes Sep 24, 2026

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

@worktrunk-bot
worktrunk-bot dismissed their stale review September 24, 2026 23:38

Superseded by the review on a later commit.

@max-sixty
max-sixty merged commit 2710f7a into max-sixty:main Sep 25, 2026
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants