Skip to content

Commit

Permalink
filter-branch: Grok special characters in tag names
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Johannes Sixt authored and Junio C Hamano committed Aug 22, 2008
1 parent 5a4a088 commit a9da166
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
12 changes: 7 additions & 5 deletions git-filter-branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -416,15 +416,17 @@ if [ "$filter_tag_name" ]; then
echo "$ref -> $new_ref ($sha1 -> $new_sha1)"

if [ "$type" = "tag" ]; then
new_sha1=$(git cat-file tag "$ref" |
new_sha1=$( ( printf 'object %s\ntype commit\ntag %s\n' \
"$new_sha1" "$new_ref"
git cat-file tag "$ref" |
sed -n \
-e "1,/^$/{
s/^object .*/object $new_sha1/
s/^type .*/type commit/
s/^tag .*/tag $new_ref/
/^object /d
/^type /d
/^tag /d
}" \
-e '/^-----BEGIN PGP SIGNATURE-----/q' \
-e 'p' |
-e 'p' ) |
git mktag) ||
die "Could not create new tag object for $ref"
if git cat-file tag "$ref" | \
Expand Down
8 changes: 8 additions & 0 deletions t/t7003-filter-branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,12 @@ test_expect_success 'Tag name filtering strips gpg signature' '
test_cmp expect actual
'

test_expect_success 'Tag name filtering allows slashes in tag names' '
git tag -m tag-with-slash X/1 &&
git cat-file tag X/1 | sed -e s,X/1,X/2, > expect &&
git filter-branch -f --tag-name-filter "echo X/2" &&
git cat-file tag X/2 > actual &&
test_cmp expect actual
'

test_done

0 comments on commit a9da166

Please sign in to comment.