Skip to content

Commit 1fe32cb

Browse files
committed
filter-branch: handle filenames that need quoting
The command used a very old fashioned construct to extract filenames out of diff-index and ended up corrupting the output. We can simply use --name-only and pipe into --stdin mode of update-index. It's been like that for the past 2 years or so since a94d994 (update-index: work with c-quoted name). Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 0ef617f commit 1fe32cb

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

git-filter-branch.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,11 @@ while read commit parents; do
276276
eval "$filter_tree" < /dev/null ||
277277
die "tree filter failed: $filter_tree"
278278

279-
git diff-index -r $commit | cut -f 2- | tr '\012' '\000' | \
280-
xargs -0 git update-index --add --replace --remove
281-
git ls-files -z --others | \
282-
xargs -0 git update-index --add --replace --remove
279+
(
280+
git diff-index -r --name-only $commit
281+
git ls-files --others
282+
) |
283+
git update-index --add --replace --remove --stdin
283284
fi
284285

285286
eval "$filter_index" < /dev/null ||

t/t7003-filter-branch.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,18 @@ test_expect_success '"map" works in commit filter' '
165165
git rev-parse --verify master
166166
'
167167

168+
test_expect_success 'Name needing quotes' '
169+
170+
git checkout -b rerere A &&
171+
mkdir foo &&
172+
name="れれれ" &&
173+
>foo/$name &&
174+
git add foo &&
175+
git commit -m "Adding a file" &&
176+
git filter-branch --tree-filter "rm -fr foo" &&
177+
! git ls-files --error-unmatch "foo/$name" &&
178+
test $(git rev-parse --verify rerere) != $(git rev-parse --verify A)
179+
180+
'
181+
168182
test_done

0 commit comments

Comments
 (0)