From 2c17635d4fff9a4abf1d43c92ccb11a21b050dcc Mon Sep 17 00:00:00 2001 From: sandroid Date: Sun, 15 Mar 2026 17:23:42 +0100 Subject: [PATCH] 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 --- bin/git-forgit | 3 ++- tests/working-tree-changes.test.sh | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/bin/git-forgit b/bin/git-forgit index 659b512..cd7b2da 100755 --- a/bin/git-forgit +++ b/bin/git-forgit @@ -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/' } diff --git a/tests/working-tree-changes.test.sh b/tests/working-tree-changes.test.sh index 4744844..03aa29c 100644 --- a/tests/working-tree-changes.test.sh +++ b/tests/working-tree-changes.test.sh @@ -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" + }