Skip to content

Conversation

@northword
Copy link
Contributor

First of all, thank you for this great project — it has been incredibly helpful in automating our workflow.

Summary

This PR ensures that file paths containing non-ASCII characters (e.g., Chinese) are correctly handled when running:

git diff --name-only --staged --no-renames

By default, Git escapes non-ASCII characters using octal sequences (e.g., \351\203\221) in its output. This can lead to incorrect file path handling in Node.js environments, especially when attempting to read or process such files.

Added git config core.quotepath false before invoking git diff, so Git outputs paths as human-readable UTF-8 strings rather than escaped octal sequences.

Example

This issue was encountered in a real-world use case involving the zotero-chinese/styles project, which stores hundreds of CSL-M styles—a variant of the Citation Style Language.

We use autofix-ci to automatically commit preview information for these styles (such as index.md and metadata.json) so that users can easily browse and choose the styles they need. Each style is stored in a directory named after the corresponding journal, which often contains CJK characters.

For commit: zotero-chinese/styles.dev@38c7a1d
After the CI ran: https://github.com/zotero-chinese/styles/actions/runs/15507982187

It should have recorded index.md and metadata.json as additions. However, due to the presence of Chinese characters in the directory name, Node.js failed to read the files, and the action incorrectly recorded them as deletions in the artifact:

Incorrect artifact output (before fix):

{
  "version": 1,
  "changes": {
    "additions": [],
    "deletions": [
      {
        "path": "\"src/\\351\\203\\221\\345\\267\\236\\345\\244\\247\\345\\255\\246\\357\\274\\210\\347\\240\\224\\347\\251\\266\\347\\224\\237\\357\\274\\211/index.md\""
      },
      {
        "path": "\"src/\\351\\203\\221\\345\\267\\236\\345\\244\\247\\345\\255\\246\\357\\274\\210\\347\\240\\224\\347\\251\\266\\347\\224\\237\\357\\274\\211/metadata.json\""
      }
    ]
  },
  "failFast": true
}

After fix: https://github.com/zotero-chinese/styles.dev/actions/runs/15516434383

@northword northword changed the title fix: git config core.quotepath fix: prevent escaped non-ASCII paths in git diff output Jun 8, 2025
northword added a commit to zotero-chinese/styles that referenced this pull request Jun 8, 2025
autofix-ci/action#29 合并后即可切换回上游版本
@mhils
Copy link
Member

mhils commented Jun 8, 2025

Thank you for the PR!

Do you think it would make sense to use "-c", "core.quotepath=false" on the diff invocation instead of globally setting a git option?

@northword
Copy link
Contributor Author

Great point — I agree that using -c core.quotepath=false inline is safer and avoids affecting the global or repo-level configuration. I've updated the PR accordingly. Thanks for the suggestion!

But the CI error is a bit unclear to me, it doesn't seem to be caused by this pr?

@mhils
Copy link
Member

mhils commented Jun 8, 2025

Thanks! Ignore the CI error, that seems unrelated. I'll take a look.

@mhils
Copy link
Member

mhils commented Jun 8, 2025

Thank you! Merged in ae2ac7b.

@mhils mhils closed this Jun 8, 2025
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.

2 participants