wfxr / forgit

:zzz: A utility tool powered by fzf for using git interactively.
MIT License
4.32k stars 136 forks source link

Fix special characters in file names #388

Closed sandr01d closed 1 month ago

sandr01d commented 2 months ago

Check list

Description

Git escapes special characters in it's output when core.quotePath is true or unset. Git always expects unquoted file paths as input. This leads to issues when we consume output from git and use it to build input for other git commands. This commit ensures we always feed unqoted paths to git commands. The _forgit_list_files function is introduced to handle usage of git ls-files with the -z flag, which ensures unquoted paths. It replaces the direct calls to git ls-files in _forgit_reset_head, _forgit_stash_push and _forgit_checkout_file. In _forgit_add the current approach of using colors to separate unstaged from staged files is replaced with a call to _forgit_ls_files with the appropriate flags to only list unstaged files. In _git_reset_head the -z option is added to the git diff command to ensure unqoted paths. Since git clean does not support the -z flag, we disable core.quotePath by passing a configuration parameter in _forgit_clean. This fixes #325

Note

This PR is based on #386. I will request reviews once #386 has been merged.

Type of change

Test environment

sandr01d commented 2 months ago

I found out that my changes introduced a bug where ga would no longer display the status indicator for the files (e.g., [M] for a modified file). This also lead to an issue where a file could not be added if it matched the regex in the sed command and therefore brackets got added around part of the path. I mainly reverted changes in _forgit_add back to the state of the master branch, but feel free to rereview this if you like. I'll give this a few days of extra testing to see if anything else comes up, so please don't merge yet.