@matheusbsbs / matheus-bagliano / commits / be15f50538
Fork 0

"git tag -u keyname" broken

Commit 396865859918e9c7bf8ce74aae137c57da134610 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>

Linus Torvalds committed Dec 10, 2007 at 20:08 UTC be15f50538afa4bfb912a86fa9d9f141010ad691
2 files changed +51 -10
builtin-tag.c
+11 -3
@@ -236,14 +236,18 @@ static const char tag_template[] =
236 "# Write a tag message\n"
237 "#\n";
238
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 +
245 static int git_tag_config(const char *var, const char *value)
246 {
247 if (!strcmp(var, "user.signingkey")) {
248 if (!value)
249 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);
251 return 0;
252 }
253
@@ -396,6 +400,10 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
400
401 argc = parse_options(argc, argv, options, git_tag_usage, 0);
402
403 + if (keyid) {
404 + sign = 1;
405 + set_signingkey(keyid);
406 + }
407 if (sign)
408 annotate = 1;
409
t/t7004-tag.sh
+40 -7
@@ -640,6 +640,46 @@ test_expect_success 'creating a signed tag with -m message should succeed' '
640 git diff expect actual
641 '
642
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 +
683 cat >sigmsgfile <<EOF
684 Another signed tag
685 message in a file.
@@ -667,13 +707,6 @@ test_expect_success 'creating a signed tag with -F - should succeed' '
707 git diff expect actual
708 '
709
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
710 get_tag_header implied-annotate $commit commit $time >expect
711 ./fakeeditor >>expect
712 echo '-----BEGIN PGP SIGNATURE-----' >>expect