Repository navigation
Non-ASCII file paths not correctly extracted in changedFilesNames function #9114
Description
Activity
Initial Exploration
Firstly, understanding what
core.quotePathdoes:➜ touch "hello-😀-"world" ➜ git config --global core.quotepath false ➜ git status On branch wm/9114-triage Your branch is up to date with 'origin/wm/9114-triage'. Untracked files: (use "git add <file>..." to include in what will be committed) hello-😀-world nothing added to commit but untracked files present (use "git add" to track) ➜ git config --global core.quotepath true ➜ git status On branch wm/9114-triage Your branch is up to date with 'origin/wm/9114-triage'. Untracked files: (use "git add <file>..." to include in what will be committed) "hello-\360\237\230\200-world" nothing added to commit but untracked files present (use "git add" to track)I can see that
core.quotePathturned on results in the file path being quoted and the emoji replaced by its octal representation.What's the actual bug?
Firstly, thank you for the bug report, the detailed instructions and the PR. In future, it would be useful if you provided the
ghcommands as part of the reproduction as it took me a moment to figure out what you were actually doing since I am not familiar with this part of the code.By default the
pr diffcommand shows a git diff of the changes in a Pull Request. We can see that it works correctly:➜ git config --global core.quotepath true ➜ gh pr diff diff --git "a/hello-\360\237\230\200-world" "b/hello-\360\237\230\200-world" new file mode 100644 index 0000000..e69de29However the function
changedFilesNamesis called from a different path, that is hit when the--name-onlyflag is provided:Lines 148 to 150 in 105bafd
if opts.NameOnly { return changedFilesNames(opts.IO.Out, diff) } We can see that in this case, the file is not listed:
➜ gh pr diff --name-only | wc -l 0However, as far as I can tell this doesn't have anything to do with
core.quotePathset totrueas it also exhibits this behaviour when configured tofalse. For example, here isgit showwithcore.quotePathset tofalse:commit d8137798e51e2368ac9263bfb8c82ffa90e73317 (HEAD -> 9114-triage, origin/9114-triage) Author: William Martin <[email protected]> Date: Thu May 23 11:11:29 2024 +0200 Add emoji file diff --git a/hello-😀-world b/hello-😀-world new file mode 100644 index 0000000..e69de29But when we request the
patchfrom GitHub it returns the path as if it were quoted regardless:➜ gh api -H 'Accept: application/vnd.github.v3.diff' /repos/williammartin-test-org/test-repo/pulls/39 | cat diff --git "a/hello-\360\237\230\200-world" "b/hello-\360\237\230\200-world" new file mode 100644 index 0000000..e69de29So all in all I think that there is a bug here, it's just unrelated to the local configuration and entirely related to what the GitHub API returns when a diff is requested and that diff contains files that are quoted.
- addedpriority-3Affects a small number of users or is largely cosmeticAffects a small number of users or is largely cosmetichelp wantedContributions welcomeContributions welcomeand removedneeds-triageneeds to be reviewedneeds to be reviewed
on May 23, 2024
Describe the bug
The changedFilesNames function in diff.go does not correctly extract file paths that contain non-ASCII characters when the core.quotePath git parameter is set to true.
Version of GitHub CLI: gh version 2.49.2 (2024-05-13)
Steps to reproduce the behavior
Expected vs actual behavior
Expected behavior: The function should correctly extract and output the file path, even if it contains non-ASCII characters and is quoted due to the core.quotePath git parameter being set to true.
Actual behavior: The function does not correctly extract the file path if it contains non-ASCII characters and is quoted.
Additional context
The issue seems to be with the regular expression used to extract the file paths from the diff. It does not account for quoted paths.
Possible solution
Update the regular expression to correctly handle quoted paths.