Skip to content

Commit be15f50

Browse files
torvaldsgitster
authored andcommitted
"git tag -u keyname" broken
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>
1 parent ace9c2a commit be15f50

File tree

2 files changed

+51
-10
lines changed

2 files changed

+51
-10
lines changed

builtin-tag.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,18 @@ static const char tag_template[] =
236236
"# Write a tag message\n"
237237
"#\n";
238238

239+
static void set_signingkey(const char *value)
240+
{
241+
if (strlcpy(signingkey, value, sizeof(signingkey)) >= sizeof(signingkey))
242+
die("signing key value too long (%.10s...)", value);
243+
}
244+
239245
static int git_tag_config(const char *var, const char *value)
240246
{
241247
if (!strcmp(var, "user.signingkey")) {
242248
if (!value)
243249
die("user.signingkey without value");
244-
if (strlcpy(signingkey, value, sizeof(signingkey))
245-
>= sizeof(signingkey))
246-
die("user.signingkey value too long");
250+
set_signingkey(value);
247251
return 0;
248252
}
249253

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

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

403+
if (keyid) {
404+
sign = 1;
405+
set_signingkey(keyid);
406+
}
399407
if (sign)
400408
annotate = 1;
401409

t/t7004-tag.sh

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,46 @@ test_expect_success 'creating a signed tag with -m message should succeed' '
640640
git diff expect actual
641641
'
642642

643+
get_tag_header u-signed-tag $commit commit $time >expect
644+
echo 'Another message' >>expect
645+
echo '-----BEGIN PGP SIGNATURE-----' >>expect
646+
test_expect_success 'sign with a given key id' '
647+
648+
git tag -u committer@example.com -m "Another message" u-signed-tag &&
649+
get_tag_msg u-signed-tag >actual &&
650+
git diff expect actual
651+
652+
'
653+
654+
test_expect_success 'sign with an unknown id (1)' '
655+
656+
! git tag -u author@example.com -m "Another message" o-signed-tag
657+
658+
'
659+
660+
test_expect_success 'sign with an unknown id (2)' '
661+
662+
! git tag -u DEADBEEF -m "Another message" o-signed-tag
663+
664+
'
665+
666+
cat >fakeeditor <<'EOF'
667+
#!/bin/sh
668+
test -n "$1" && exec >"$1"
669+
echo A signed tag message
670+
echo from a fake editor.
671+
EOF
672+
chmod +x fakeeditor
673+
674+
get_tag_header implied-sign $commit commit $time >expect
675+
./fakeeditor >>expect
676+
echo '-----BEGIN PGP SIGNATURE-----' >>expect
677+
test_expect_success '-u implies signed tag' '
678+
GIT_EDITOR=./fakeeditor git-tag -u CDDE430D implied-sign &&
679+
get_tag_msg implied-sign >actual &&
680+
git diff expect actual
681+
'
682+
643683
cat >sigmsgfile <<EOF
644684
Another signed tag
645685
message in a file.
@@ -667,13 +707,6 @@ test_expect_success 'creating a signed tag with -F - should succeed' '
667707
git diff expect actual
668708
'
669709

670-
cat >fakeeditor <<'EOF'
671-
#!/bin/sh
672-
test -n "$1" && exec >"$1"
673-
echo A signed tag message
674-
echo from a fake editor.
675-
EOF
676-
chmod +x fakeeditor
677710
get_tag_header implied-annotate $commit commit $time >expect
678711
./fakeeditor >>expect
679712
echo '-----BEGIN PGP SIGNATURE-----' >>expect

0 commit comments

Comments
 (0)