fix: handle backslashes in filenames in _forgit_worktree_changes

Git escapes backslashes with `git status` even when
`core.quotepath=false` is set. Use `--porcelain -z` with `git status` as
a more robust approach to fix this.

Fixes #467
This commit is contained in:
sandroid 2026-03-15 17:23:42 +01:00 committed by sandr01d
parent 1bc93a2c3a
commit 2c17635d4f
2 changed files with 11 additions and 1 deletions

View file

@ -224,7 +224,8 @@ _forgit_worktree_changes() {
untracked=$(git config --get-color color.status.untracked red)
show_untracked=$(git config status.showUntrackedFiles)
git -c color.status=always -c status.relativePaths=true -c core.quotePath=false status -s --untracked="${show_untracked:-all}" |
git -c color.status=always -c status.relativePaths=true status --porcelain -zs --untracked="${show_untracked:-all}" |
tr '\0' '\n' |
grep -F -e "$changed" -e "$unmerged" -e "$untracked" |
sed -E 's/^(..[^[:space:]]*)[[:space:]]+(.*)$/[\1] \2/'
}

View file

@ -23,6 +23,7 @@
git add "staged file.txt"
touch "untracked_file.txt"
touch 'untracked_with_\backslash'
}
function test_forgit_worktree_changes_contains_modified() {
@ -56,3 +57,11 @@
assert_not_contains "tracked file.txt" "$output"
}
function test_forgit_worktree_changes_supports_backslashes() {
local output
output=$(_forgit_worktree_changes)
assert_contains 'untracked_with_\backslash' "$output"
}