Skip to content

fix(snapshot): support non-ASCII filenames in undo/revert#10208

Closed
yimingll wants to merge 1 commit intoanomalyco:devfrom
yimingll:fix/snapshot-chinese-filename-support
Closed

fix(snapshot): support non-ASCII filenames in undo/revert#10208
yimingll wants to merge 1 commit intoanomalyco:devfrom
yimingll:fix/snapshot-chinese-filename-support

Conversation

@yimingll
Copy link
Copy Markdown

Summary

Fix undo/revert not working for files with non-ASCII characters in their names (e.g., Chinese, Japanese, Korean filenames).

Problem

On Windows (and potentially other systems), when using /undo to revert changes to files with non-ASCII filenames, the files are not actually reverted. English-named files work correctly, but files like 公共函数.cpp (Chinese) fail silently.

Root Cause

The git diff --name-only command used in Snapshot.patch() returns non-ASCII filenames as octal-escaped strings with quotes when core.quotepath is enabled (the default):

"\345\205\254\345\205\261\345\207\275\346\225\260.cpp"

Instead of:

公共函数.cpp

This escaped path is then stored in the patch data and later passed to git checkout, which fails because no file with that literal escaped name exists.

Evidence from logs

service=snapshot file=D:\sword-net-3\"\345\205\254\345\205\261\345\207\275\346\225\260.cpp" hash=... reverting

vs working English file:

service=snapshot file=D:\sword-net-3\pch.cpp hash=... reverting

Solution

Add -c core.quotepath=false to git diff commands to output non-ASCII filenames literally without escaping.

Changes

  • Snapshot.patch(): Add -c core.quotepath=false to git diff --name-only
  • Snapshot.diffFull(): Add -c core.quotepath=false to git diff --numstat

Testing

Tested on Windows 11 with Chinese filename (公共函数.cpp):

  • Before: /undo only reverts English-named files, Chinese-named files unchanged
  • After: /undo correctly reverts all files regardless of filename encoding

Checklist

  • Minimal, focused change
  • Tested on Windows with non-ASCII filenames
  • No breaking changes

Add -c core.quotepath=false to git diff commands to prevent
escaping of non-ASCII characters (e.g., Chinese, Japanese, Korean)
in file paths.

Without this fix, files with non-ASCII names are stored as
octal-escaped strings (e.g., "\345\205\254\345\205\261") in
the patch data, causing undo/revert to fail because git cannot
find these incorrectly-named files.

Tested with Chinese filename: 公共函数.cpp
- Before: undo fails silently for non-ASCII filenames
- After: undo correctly reverts files with any filename
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential Duplicate Found:

This PR appears to address the exact same issue - fixing snapshot failures with non-ASCII filenames on Windows. Both PRs target the same problem (undo/revert not working with Chinese/Japanese/Korean filenames) and likely implement the same or very similar solution (handling git's octal-escaped output).

You should check if #9844 is already merged or if there's a reason for the duplicate submission.

@yimingll
Copy link
Copy Markdown
Author

Closing as duplicate of #9844 which addresses the same issue with a more comprehensive fix (using Bun.spawn instead of dollar template).

@yimingll yimingll closed this Jan 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant