threads / discuss / 11234

"git tag -u keyname" broken

Subject: "git tag -u keyname" broken

## tl;dr

4 messages between Dec 11, 2007 and Dec 11, 2007.

replies: 3people: 3as markdown or json

Linus Torvalds· Dec 11, 2007, 04:08 UTC · lore

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>
---

This has gotten only very minimal testing. Somebody should double-check it all, and adding a test would probably be great too.

 builtin-tag.c |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/builtin-tag.c b/builtin-tag.c
index 517419f..274901a 100644
--- a/builtin-tag.c
+++ b/builtin-tag.c
@@ -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;
 	}
 
@@ -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;
 
Jeff King· Dec 11, 2007, 04:24 UTC · re: Linus Torvalds · lore

[PATCH] t7004: test that "git-tag -u" implies "-s"

This was lost in the C conversion, but recently fixed by Linus.

Signed-off-by: Jeff King <peff@peff.net>
---
On Mon, Dec 10, 2007 at 08:08:06PM -0800, Linus Torvalds wrote:
Show 7 quoted lines
> 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 has gotten only very minimal testing. Somebody should double-check it 
> all, and adding a test would probably be great too.

Looks good to me, and here's a test. It was trivial to whip up, since I wrote a test for almost the identical bug a few days ago (that one was "-s implies -a").

 t/t7004-tag.sh |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh
index c7130c4..5393d35 100755
--- a/t/t7004-tag.sh
+++ b/t/t7004-tag.sh
@@ -682,6 +682,14 @@ test_expect_success '-s implies annotated tag' '
 	get_tag_msg implied-annotate >actual &&
 	git diff expect actual
 '
+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
+'
 
 test_expect_success \
 	'trying to create a signed tag with non-existing -F file should fail' '
-- 
1.5.3.7.2229.gd040e-dirty
Junio C Hamano· Dec 11, 2007, 04:38 UTC · re: Jeff King · lore

Re: [PATCH] t7004: test that "git-tag -u" implies "-s"

Jeff King <peff@peff.net> writes:
> Looks good to me, and here's a test. It was trivial to whip up, since I
> wrote a test for almost the identical bug a few days ago (that one was
> "-s implies -a").

Looks good to me. We should verify both common forms of key-id and also check a negative case. This squashes a few of mine on top of yours.

---
 t/t7004-tag.sh |   26 ++++++++++++++++++++++++++
 1 files changed, 26 insertions(+), 0 deletions(-)
diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh
index c7130c4..a502286 100755
--- a/t/t7004-tag.sh
+++ b/t/t7004-tag.sh
@@ -640,6 +640,32 @@ test_expect_success 'creating a signed tag with -m message should succeed' '
 	git diff expect actual
 '
 
+get_tag_header implied-sign $commit commit $time >expect
+echo 'Another signed tag' >>expect
+echo '-----BEGIN PGP SIGNATURE-----' >>expect
+test_expect_success '-u implies signed tag' '
+	git-tag -u CDDE430D -m "Another signed tag" implied-sign &&
+	get_tag_msg implied-sign >actual &&
+	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' '
+
+	! git tag -u author@example.com -m "Another message" o-signed-tag
+
+'
+
 cat >sigmsgfile <<EOF
 Another signed tag
 message in a file.
Jeff King· Dec 11, 2007, 05:22 UTC · re: Junio C Hamano · lore

Re: [PATCH] t7004: test that "git-tag -u" implies "-s"

On Mon, Dec 10, 2007 at 08:38:31PM -0800, Junio C Hamano wrote:
Show 8 quoted lines
> +get_tag_header implied-sign $commit commit $time >expect
> +echo 'Another signed tag' >>expect
> +echo '-----BEGIN PGP SIGNATURE-----' >>expect
> +test_expect_success '-u implies signed tag' '
> +	git-tag -u CDDE430D -m "Another signed tag" implied-sign &&
> +	get_tag_msg implied-sign >actual &&
> +	git diff expect actual
> +'

One thing that my original did test but this version doesn't: not only does -u imply -s, but -u implies -s which implies -a. IOW, using "-u" will put you in an editor (and a poorly done fix might have gotten this wrong, but apparently Linus is a super-genius).

Your other two tests look good.
-Peff

← back to recent threads