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>
Junio C Hamano committed
Feb 15, 2008 at 23:57 UTC
1fe32cb9d0807e6da468dc7bf96d427b2f38c1c4
2 files changed
+19
-4
git-filter-branch.sh
+5
-4
@@ -276,10 +276,11 @@ while read commit parents; do
276
eval "$filter_tree" < /dev/null ||
277
die "tree filter failed: $filter_tree"
278
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
284
fi
285
286
eval "$filter_index" < /dev/null ||
t/t7003-filter-branch.sh
+14
@@ -165,4 +165,18 @@ test_expect_success '"map" works in commit filter' '
165
git rev-parse --verify master
166
'
167
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
+
182
test_done