Skip to content

Commit 2c17635

Browse files
committed
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
1 parent 1bc93a2 commit 2c17635

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

bin/git-forgit

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ _forgit_worktree_changes() {
224224
untracked=$(git config --get-color color.status.untracked red)
225225
show_untracked=$(git config status.showUntrackedFiles)
226226

227-
git -c color.status=always -c status.relativePaths=true -c core.quotePath=false status -s --untracked="${show_untracked:-all}" |
227+
git -c color.status=always -c status.relativePaths=true status --porcelain -zs --untracked="${show_untracked:-all}" |
228+
tr '\0' '\n' |
228229
grep -F -e "$changed" -e "$unmerged" -e "$untracked" |
229230
sed -E 's/^(..[^[:space:]]*)[[:space:]]+(.*)$/[\1] \2/'
230231
}

tests/working-tree-changes.test.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
git add "staged file.txt"
2424

2525
touch "untracked_file.txt"
26+
touch 'untracked_with_\backslash'
2627
}
2728

2829
function test_forgit_worktree_changes_contains_modified() {
@@ -56,3 +57,11 @@
5657

5758
assert_not_contains "tracked file.txt" "$output"
5859
}
60+
61+
function test_forgit_worktree_changes_supports_backslashes() {
62+
local output
63+
64+
output=$(_forgit_worktree_changes)
65+
66+
assert_contains 'untracked_with_\backslash' "$output"
67+
}

0 commit comments

Comments
 (0)