Skip to content

Commit

Permalink
"git tag -u keyname" broken
Browse files Browse the repository at this point in the history
Commit 3968658 broke signed tags using
the "-u" flag when it made builtin-tag.c use parse_options() to parse its
arguments (but it quite possibly was broken even before that, by the
builtin rewrite).

It used to be that passing the signing ID with the -u parameter also
(obviously!) implied that you wanted to sign and annotate the tag, but
that logic got dropped. It also totally ignored the actual key ID that was
passed in.

This reinstates it all.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Linus Torvalds authored and Junio C Hamano committed Dec 11, 2007
1 parent ace9c2a commit be15f50
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 10 deletions.
14 changes: 11 additions & 3 deletions builtin-tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,18 @@ static const char tag_template[] =
"# Write a tag message\n"
"#\n";

static void set_signingkey(const char *value)
{
if (strlcpy(signingkey, value, sizeof(signingkey)) >= sizeof(signingkey))
die("signing key value too long (%.10s...)", value);
}

static int git_tag_config(const char *var, const char *value)
{
if (!strcmp(var, "user.signingkey")) {
if (!value)
die("user.signingkey without value");
if (strlcpy(signingkey, value, sizeof(signingkey))
>= sizeof(signingkey))
die("user.signingkey value too long");
set_signingkey(value);
return 0;
}

Expand Down Expand Up @@ -396,6 +400,10 @@ int cmd_tag(int argc, const char **argv, const char *prefix)

argc = parse_options(argc, argv, options, git_tag_usage, 0);

if (keyid) {
sign = 1;
set_signingkey(keyid);
}
if (sign)
annotate = 1;

Expand Down
47 changes: 40 additions & 7 deletions t/t7004-tag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,46 @@ test_expect_success 'creating a signed tag with -m message should succeed' '
git diff expect actual
'

get_tag_header u-signed-tag $commit commit $time >expect
echo 'Another message' >>expect
echo '-----BEGIN PGP SIGNATURE-----' >>expect
test_expect_success 'sign with a given key id' '
git tag -u committer@example.com -m "Another message" u-signed-tag &&
get_tag_msg u-signed-tag >actual &&
git diff expect actual
'

test_expect_success 'sign with an unknown id (1)' '
! git tag -u author@example.com -m "Another message" o-signed-tag
'

test_expect_success 'sign with an unknown id (2)' '
! git tag -u DEADBEEF -m "Another message" o-signed-tag
'

cat >fakeeditor <<'EOF'
#!/bin/sh
test -n "$1" && exec >"$1"
echo A signed tag message
echo from a fake editor.
EOF
chmod +x fakeeditor

get_tag_header implied-sign $commit commit $time >expect
./fakeeditor >>expect
echo '-----BEGIN PGP SIGNATURE-----' >>expect
test_expect_success '-u implies signed tag' '
GIT_EDITOR=./fakeeditor git-tag -u CDDE430D implied-sign &&
get_tag_msg implied-sign >actual &&
git diff expect actual
'

cat >sigmsgfile <<EOF
Another signed tag
message in a file.
Expand Down Expand Up @@ -667,13 +707,6 @@ test_expect_success 'creating a signed tag with -F - should succeed' '
git diff expect actual
'

cat >fakeeditor <<'EOF'
#!/bin/sh
test -n "$1" && exec >"$1"
echo A signed tag message
echo from a fake editor.
EOF
chmod +x fakeeditor
get_tag_header implied-annotate $commit commit $time >expect
./fakeeditor >>expect
echo '-----BEGIN PGP SIGNATURE-----' >>expect
Expand Down

0 comments on commit be15f50

Please sign in to comment.