filter-branch: Grok special characters in tag names
The tag rewriting code used a 'sed' expression to substitute the new tag name into the corresponding field of the annotated tag object. But this is problematic if the tag name contains special characters. In particular, if the tag name contained a slash, then the 'sed' expression had a syntax error. We now protect against this by using 'printf' to assemble the tag header. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Sixt committed
Aug 21, 2008 at 16:45 UTC
a9da1663dfc869141749c768e9e0f52bb48218e3
2 files changed
+15
-5
git-filter-branch.sh
+7
-5
@@ -416,15 +416,17 @@ if [ "$filter_tag_name" ]; then
416
echo "$ref -> $new_ref ($sha1 -> $new_sha1)"
417
418
if [ "$type" = "tag" ]; then
419
- new_sha1=$(git cat-file tag "$ref" |
419
+ new_sha1=$( ( printf 'object %s\ntype commit\ntag %s\n' \
420
+ "$new_sha1" "$new_ref"
421
+ git cat-file tag "$ref" |
422
sed -n \
423
-e "1,/^$/{
422
- s/^object .*/object $new_sha1/
423
- s/^type .*/type commit/
424
- s/^tag .*/tag $new_ref/
424
+ /^object /d
425
+ /^type /d
426
+ /^tag /d
427
}" \
428
-e '/^-----BEGIN PGP SIGNATURE-----/q' \
427
- -e 'p' |
429
+ -e 'p' ) |
430
git mktag) ||
431
die "Could not create new tag object for $ref"
432
if git cat-file tag "$ref" | \
t/t7003-filter-branch.sh
+8
@@ -250,4 +250,12 @@ test_expect_success 'Tag name filtering strips gpg signature' '
250
test_cmp expect actual
251
'
252
253
+test_expect_success 'Tag name filtering allows slashes in tag names' '
254
+ git tag -m tag-with-slash X/1 &&
255
+ git cat-file tag X/1 | sed -e s,X/1,X/2, > expect &&
256
+ git filter-branch -f --tag-name-filter "echo X/2" &&
257
+ git cat-file tag X/2 > actual &&
258
+ test_cmp expect actual
259
+'
260
+
261
test_done