Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix special characters in file names #388

Merged
merged 3 commits into from
May 12, 2024

Conversation

sandr01d
Copy link
Collaborator

@sandr01d sandr01d commented Apr 19, 2024

Check list

  • I have performed a self-review of my code
  • I have commented my code in hard-to-understand areas
  • I have made corresponding changes to the documentation

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

  • Bug fix
  • New feature
  • Refactor
  • Breaking change
  • Documentation change

Test environment

  • Shell
    • bash
    • zsh
    • fish
  • OS
    • Linux
    • Mac OS X
    • Windows
    • Others:

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.
@sandr01d sandr01d marked this pull request as ready for review April 26, 2024 21:07
Copy link
Owner

@wfxr wfxr left a comment

Choose a reason for hiding this comment

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

LGTM

when the sed pattern matches (due to missing indicator)
@sandr01d
Copy link
Collaborator Author

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.

@sandr01d sandr01d merged commit 17394d1 into wfxr:master May 12, 2024
4 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.

Issues with special characters in filenames
3 participants