Skip to contentSkip to conversation

Add the tag.gpgsign option to sign all created tags

PATCH Superseded Laurent Arnoud 4 participants 22 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add the tag.gpgsign option to sign all created tags

The tag.gpgsign config option allows to sign all
commits automatically.

---
 Documentation/config.txt |  3 +++
 builtin/tag.c            | 19 ++++++++++++++++---
 2 files changed, 19 insertions(+), 3 deletions(-)
Documentation/config.txt +3 -0
index 2cd6bdd..076c68a 100644
@@ -2729,6 +2729,9 @@ submodule.<name>.ignore::
 	"--ignore-submodules" option. The 'git submodule' commands are not
 	affected by this setting.
 
+tag.gpgSign::
+	A boolean to specify whether all tags created should be GPG signed.
+
 tag.sort::
 	This variable controls the sort ordering of tags when displayed by
 	linkgit:git-tag[1]. Without the "--sort=<value>" option provided, the
builtin/tag.c +16 -3
index 1705c94..53cad28 100644
@@ -29,6 +29,7 @@ static const char * const git_tag_usage[] = {
 };
 
 static unsigned int colopts;
+static const char *sign_tag;
 
 static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting, const char *format)
 {
@@ -166,6 +167,11 @@ static int git_tag_config(const char *var, const char *value, void *cb)
 	status = git_gpg_config(var, value, cb);
 	if (status)
 		return status;
+	if (!strcmp(var, "tag.gpgsign")) {
+		sign_tag = git_config_bool(var, value) ? "" : NULL;
+		return 0;
+	}
+
 	if (starts_with(var, "column."))
 		return git_column_config(var, value, "tag", &colopts);
 	return git_default_config(var, value, cb);
@@ -381,14 +387,21 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 
 	argc = parse_options(argc, argv, prefix, options, git_tag_usage, 0);
 
+	if (argc == 0 && !cmdmode)
+		cmdmode = 'l';
+
+	/* Remove config option when calling command other than create tag */
+	if (cmdmode != 0 && sign_tag)
+		sign_tag = NULL;
+
 	if (keyid) {
 		opt.sign = 1;
 		set_signing_key(keyid);
 	}
-	if (opt.sign)
+	if (opt.sign || sign_tag) {
+		opt.sign = 1;
 		annotate = 1;
-	if (argc == 0 && !cmdmode)
-		cmdmode = 'l';
+	}
 
 	if ((annotate || msg.given || msgfile || force) && (cmdmode != 0))
 		usage_with_options(git_tag_usage, options);
Signature · 5 lines
2.7.0


-- 
Laurent
#1 lore raw
Quoted 2 lines · Laurent Arnoud

The tag.gpgsign config option allows to sign all
commits automatically.

We have commit.gpgsign, so this makes some sense. Would you want to sign _all_ tags created with "git tag", including lightweight tags, or only those that would already create a tag object (i.e., annotated tags)?

Quoted 13 lines
builtin/tag.c +1 -0
index 1705c94..53cad28 100644
@@ -29,6 +29,7 @@ static const char * const git_tag_usage[] = {
 };
 
 static unsigned int colopts;
+static const char *sign_tag;
 
 static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting, const char *format)
 {

builtin/tag.c static int git_tag_config(const char *var, const char *value, void *cb) · line 173

Quoted 7 lines
builtin/tag.c +4 -0
@@ -166,6 +167,11 @@ static int git_tag_config(const char *var, const char *value, void *cb)
 	status = git_gpg_config(var, value, cb);
 	if (status)
 		return status;
+	if (!strcmp(var, "tag.gpgsign")) {
+		sign_tag = git_config_bool(var, value) ? "" : NULL;
+		return 0;
+	}

Why is "sign_tag" a pointer, and not simply an "int"?

If it is just representing the config, should it perhaps be given a more specific name, like "sign_tag_config"?

builtin/tag.c int cmd_tag(int argc, const char **argv, const char *prefix) · line 396

Quoted 11 lines
builtin/tag.c +7 -0
@@ -381,14 +387,21 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 
 	argc = parse_options(argc, argv, prefix, options, git_tag_usage, 0);
 
+	if (argc == 0 && !cmdmode)
+		cmdmode = 'l';
+
+	/* Remove config option when calling command other than create tag */
+	if (cmdmode != 0 && sign_tag)
+		sign_tag = NULL;
+

Perhaps rather than rearranging the setup of cmdmode in this function, you can just use have a conditional that makes explicit when this config option kicks in, like:

if (!cmdmode && sign_tag_config)

	opt.sign = 1;

That seems easier to follow to me (and then we don't have to check sign_tag_config later; it acts as if the user gave "-s"). Although...

Quoted 4 lines
builtin/tag.c +0 -0
 	if (keyid) {
 		opt.sign = 1;
 		set_signing_key(keyid);
 	}

builtin/tag.c int cmd_tag(int argc, const char **argv, const char *prefix) · line 407

Quoted 10 lines
builtin/tag.c +3 -3
-	if (opt.sign)
+	if (opt.sign || sign_tag) {
+		opt.sign = 1;
 		annotate = 1;
-	if (argc == 0 && !cmdmode)
-		cmdmode = 'l';
+	}
 
 	if ((annotate || msg.given || msgfile || force) && (cmdmode != 0))
 		usage_with_options(git_tag_usage, options);

How do I disable tag.gpgsign if I want an unsigned tag? I should be able to do:

  git config tag.gpgsign true
  git tag --no-sign foo

but I don't think that works with your patch. You'd need to tweak the handling of opt.sign to be able to tell the difference between "--no-sign was given" and "there was no signing-related option given", and only kick in the config in the latter case.

-Peff

#2 lore raw

Hi Jeff,

Quoted 3 lines · Jeff King

We have commit.gpgsign, so this makes some sense. Would you want to sign _all_ tags created with "git tag", including lightweight tags, or only those that would already create a tag object (i.e., annotated tags)?

Yes those that create a tag object (annotated tags). All you suggestions make sense and I will prepare a patch v2.

Cheers,

Signature · 1 line
Laurent
#3 lore raw
Quoted 9 lines · Laurent Arnoud

Hi Jeff,

Quoted 3 lines · Jeff King

We have commit.gpgsign, so this makes some sense. Would you want to sign _all_ tags created with "git tag", including lightweight tags, or only those that would already create a tag object (i.e., annotated tags)?

Yes those that create a tag object (annotated tags). All you suggestions make sense and I will prepare a patch v2.

That behavior makes more sense to me, but I don't think it's what your patch does (v1 or v2). Perhaps it would make sense to add some tests, both to verify that it is behaving as expected, and to protect that behavior from future changes?

-Peff

#4 lore raw
Quoted 4 lines · Jeff King

That behavior makes more sense to me, but I don't think it's what your patch does (v1 or v2). Perhaps it would make sense to add some tests, both to verify that it is behaving as expected, and to protect that behavior from future changes?

Yes, I will try to do so during the week.

Cheers,

Signature · 1 line
Laurent
#5 lore raw

PATCH v2 1/1 Add the tag.gpgsign option to sign all created tags

In reply to Jeff King

The tag.gpgsign config option allows to sign all commits automatically.

Support --no-sign option to countermand configuration tag.gpgsign.

---
 Documentation/config.txt  |  3 +++
 Documentation/git-tag.txt |  4 ++++
 builtin/tag.c             | 21 ++++++++++++++++-----
 3 files changed, 23 insertions(+), 5 deletions(-)
Documentation/config.txt +3 -0
index 2cd6bdd..076c68a 100644
@@ -2729,6 +2729,9 @@ submodule.<name>.ignore::
 	"--ignore-submodules" option. The 'git submodule' commands are not
 	affected by this setting.
 
+tag.gpgSign::
+	A boolean to specify whether all tags created should be GPG signed.
+
 tag.sort::
 	This variable controls the sort ordering of tags when displayed by
 	linkgit:git-tag[1]. Without the "--sort=<value>" option provided, the
Documentation/git-tag.txt +4 -0
index abab481..757baa1 100644
@@ -64,6 +64,10 @@ OPTIONS
 --sign::
 	Make a GPG-signed tag, using the default e-mail address's key.
 
+--no-sign::
+	Countermand `tag.gpgSign` configuration variable that is
+	set to force each and every tag to be signed.
+
 -u <keyid>::
 --local-user=<keyid>::
 	Make a GPG-signed tag, using the given key.
builtin/tag.c +16 -5
index 1705c94..2a7b2f2 100644
@@ -29,6 +29,7 @@ static const char * const git_tag_usage[] = {
 };
 
 static unsigned int colopts;
+static unsigned int sign_tag_config;
 
 static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting, const char *format)
 {
@@ -166,6 +167,11 @@ static int git_tag_config(const char *var, const char *value, void *cb)
 	status = git_gpg_config(var, value, cb);
 	if (status)
 		return status;
+	if (!strcmp(var, "tag.gpgsign")) {
+		sign_tag_config = git_config_bool(var, value) ? 1 : 0;
+		return 0;
+	}
+
 	if (starts_with(var, "column."))
 		return git_column_config(var, value, "tag", &colopts);
 	return git_default_config(var, value, cb);
@@ -195,7 +201,7 @@ static void write_tag_body(int fd, const unsigned char *sha1)
 
 static int build_tag_object(struct strbuf *buf, int sign, unsigned char *result)
 {
-	if (sign && do_sign(buf) < 0)
+	if (sign > 0 && do_sign(buf) < 0)
 		return error(_("unable to sign the tag"));
 	if (write_sha1_file(buf->buf, buf->len, tag_type, result) < 0)
 		return error(_("unable to write tag file"));
@@ -204,7 +210,7 @@ static int build_tag_object(struct strbuf *buf, int sign, unsigned char *result)
 
 struct create_tag_options {
 	unsigned int message_given:1;
-	unsigned int sign;
+	int sign;
 	enum {
 		CLEANUP_NONE,
 		CLEANUP_SPACE,
@@ -378,17 +384,22 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 	memset(&opt, 0, sizeof(opt));
 	memset(&filter, 0, sizeof(filter));
 	filter.lines = -1;
+	opt.sign = -1;
 
 	argc = parse_options(argc, argv, prefix, options, git_tag_usage, 0);
 
+	if (argc == 0 && !cmdmode)
+		cmdmode = 'l';
+
+	if (!cmdmode && sign_tag_config && opt.sign != 0)
+		opt.sign = 1;
+
 	if (keyid) {
 		opt.sign = 1;
 		set_signing_key(keyid);
 	}
-	if (opt.sign)
+	if (opt.sign > 0)
 		annotate = 1;
-	if (argc == 0 && !cmdmode)
-		cmdmode = 'l';
 
 	if ((annotate || msg.given || msgfile || force) && (cmdmode != 0))
 		usage_with_options(git_tag_usage, options);
Signature · 1 line
2.7.0
#6 lore raw
Quoted 2 lines · Laurent Arnoud

The tag.gpgsign config option allows to sign all commits automatically.

^^^^^^^
presumably you meant tags.

Quoted 30 lines

Support --no-sign option to countermand configuration tag.gpgsign.

---
 Documentation/config.txt  |  3 +++
 Documentation/git-tag.txt |  4 ++++
 builtin/tag.c             | 21 ++++++++++++++++-----
 3 files changed, 23 insertions(+), 5 deletions(-)
Documentation/config.txt +3 -0
index 2cd6bdd..076c68a 100644
@@ -2729,6 +2729,9 @@ submodule.<name>.ignore::
 	"--ignore-submodules" option. The 'git submodule' commands are not
 	affected by this setting.
 
+tag.gpgSign::
+	A boolean to specify whether all tags created should be GPG signed.
+
 tag.sort::
 	This variable controls the sort ordering of tags when displayed by
 	linkgit:git-tag[1]. Without the "--sort=<value>" option provided, the
Documentation/git-tag.txt +0 -0
index abab481..757baa1 100644

Documentation/git-tag.txt OPTIONS · line 70

Quoted 7 lines
Documentation/git-tag.txt +4 -0
@@ -64,6 +64,10 @@ OPTIONS
 --sign::
 	Make a GPG-signed tag, using the default e-mail address's key.
 
+--no-sign::
+	Countermand `tag.gpgSign` configuration variable that is
+	set to force each and every tag to be signed.
+

I assume that, after setting tag.gpgsign in the config, this is the only way to get a lightweight tag. Maybe here, or above in config.txt, this could be stated more obviously? dunno.

[Also, don't we normally describe --[no]-sign options together?]

ATB,
Ramsay Jones

#7 lore raw
In reply to Laurent Arnoud
Quoted 2 lines · Laurent Arnoud

The tag.gpgsign config option allows to sign all commits automatically.

I presume that you meant "all annotated tags" here. But I am not sure it this is sensible.

Quoted 1 line

Support --no-sign option to countermand configuration tag.gpgsign.

That sound quite counter-intuitive.

    $ git tag -s -m "my message" v1.0

is an explicit request to create a signed tag, as opposed to

    $ git tag -a -m "my message" v1.0

is an explicit request to create an unsigned annotated tag. So

I think a short-hand

    $ git tag -m "my message" v1.0

falls back to annotated and not signed tag, and I can understand if the patch is about allowing the user to tweak this fallback to create signed tag instead.

So I do not see why you need a new --no-sign option at all. If you have the configuration and you do want to create an unsigned annotated tag one-shot, all you need is to explicitly ask for "-a" i.e.

    $ git tag -a -m "my message" v1.0

isn't it?

If you are forcing users to always leave a message and then further forcing users to always sign with the single new configuration, i.e.

    $ git tag v1.0
    ... opens the editor to ask for a message ...
    ... then makes the user sign with GPG ...

then I would first have to say that is a bad idea.

I can sort-of understand (but do not necessarily agree that it is a good idea) adding new two configurations, i.e.

- "even without -a/-s, force the user to annotate the tag" is one configuration, and

- "even when the user did not say -s, force the user to sign an annotated tag" is the other.

And with such a system, I can see why you would need an option "--lightweight" to force creation of a light-weight tag (i.e. to countermand the first one). You can view this new option as something that sits next to existing -a/-s. The current system lets user choose among the three variants (lightweight, annotated and signed) by not giving any, giving -a, and giving -s option respectively, but with the "--lightweight" option, the user can ask for one of the three explicitly, as opposed to using "lack of either -a/-s" as a signal to create lightweight one.

And in the context of such a system, "--no-sign" may make sense to override the second configuration (i.e. "force the user to sign an annotated tag").

But otherwise, adding only "--no-sign" does not make much sense to me, as it implies "not signing always means annotated", which is not true. It is unclear between lightweight and annotated which one the user who says "--no-sign" really wants.

#8 lore raw
Quoted 5 lines · Junio C Hamano
Quoted 2 lines

The tag.gpgsign config option allows to sign all commits automatically.

I presume that you meant "all annotated tags" here. But I am not sure it this is sensible.

Yes its a mistake.

Quoted 9 lines
Quoted 1 line

Support --no-sign option to countermand configuration tag.gpgsign.

So I do not see why you need a new --no-sign option at all. If you have the configuration and you do want to create an unsigned annotated tag one-shot, all you need is to explicitly ask for "-a" i.e.

    $ git tag -a -m "my message" v1.0

isn't it?

You know that when you have sign configuration enabled globally annotate is implicite, so its difficult to join both world. I use same idea as in your patch 55ca3f99ae4895605a348322dd2fc50f2065f508.

Quoted 6 lines

If you are forcing users to always leave a message and then further forcing users to always sign with the single new configuration, i.e.

    $ git tag v1.0
    ... opens the editor to ask for a message ...
    ... then makes the user sign with GPG ...

I'm not forcing this type of user to enable global configuration, that will be annoying for them of course.
I tried to fix a need I have currently and this is a good compromise for me.

Quoted 21 lines

then I would first have to say that is a bad idea.

I can sort-of understand (but do not necessarily agree that it is a good idea) adding new two configurations, i.e.

- "even without -a/-s, force the user to annotate the tag" is one configuration, and

- "even when the user did not say -s, force the user to sign an annotated tag" is the other.

And with such a system, I can see why you would need an option "--lightweight" to force creation of a light-weight tag (i.e. to countermand the first one). You can view this new option as something that sits next to existing -a/-s. The current system lets user choose among the three variants (lightweight, annotated and signed) by not giving any, giving -a, and giving -s option respectively, but with the "--lightweight" option, the user can ask for one of the three explicitly, as opposed to using "lack of either -a/-s" as a signal to create lightweight one.

Quoted 8 lines

And in the context of such a system, "--no-sign" may make sense to override the second configuration (i.e. "force the user to sign an annotated tag").

But otherwise, adding only "--no-sign" does not make much sense to me, as it implies "not signing always means annotated", which is not true. It is unclear between lightweight and annotated which one the user who says "--no-sign" really wants.

As I said it's difficult to easily join both world, as you know with configuration and command line options. This is an override and if its really a no go for this patch without refactoring this I will stop my work on it.

Just let me know I will send a patch v3 updated with tests after this.

Cheers,

Signature · 1 line
Laurent
#9 lore raw
Quoted 6 lines · Laurent Arnoud
Quoted 6 lines
Quoted 1 line

Support --no-sign option to countermand configuration tag.gpgsign.

So I do not see why you need a new --no-sign option at all. If you have the configuration and you do want to create an unsigned annotated tag one-shot, all you need is to explicitly ask for "-a" i.e.

Quoted 6 lines
Quoted 3 lines
    $ git tag -a -m "my message" v1.0

isn't it?

You know that when you have sign configuration enabled globally annotate is implicite, so its difficult to join both world.

Sorry, I am not sure what you mean by that. It is unclear what two worlds you are referring to.

Quoted 2 lines

I use same idea as in your patch
55ca3f99ae4895605a348322dd2fc50f2065f508.

That is not a good comparison. 55ca3f99 (commit-tree: add and document --no-gpg-sign, 2013-12-13) is about signed commit, and over there there are only two choices, i.e. a commit that corresponds to an annotated tag, and a signed commit that corresponds to a signed tag. There is no "lightweight-tag" equivalent.

Quoted 9 lines
Quoted 6 lines

If you are forcing users to always leave a message and then further forcing users to always sign with the single new configuration, i.e.

    $ git tag v1.0
    ... opens the editor to ask for a message ...
    ... then makes the user sign with GPG ...

I'm not forcing this type of user to enable global configuration, that will be annoying for them of course.

Good.

If so, then the configuration is "when the user gives us a message to create a tag without explicitly saying -a/-s, we create an annotated tag by default, but create a signed tag instead in such a case", I would think. That is:

    $ git tag -m 'foo' $tagname

would create signed tag under such a configuration option, and I think such an option may make sense. And the way to override it would be

    $ git tag -a -m 'foo' $tagname

So there is no need for --no-sign option. When the user explicitly asks to create an annotated tag with

    $ git tag -a -m 'foo' $tagname

it is unreasonable to override that explicit wish with a configuration setting.

#10 lore raw
Quoted 5 lines · Junio C Hamano
Quoted 2 lines

You know that when you have sign configuration enabled globally annotate is implicite, so its difficult to join both world.

Sorry, I am not sure what you mean by that. It is unclear what two worlds you are referring to.

Command line options and configuration, but forget about it.

Quoted 35 lines
Quoted 3 lines

I use same idea as in your patch
55ca3f99ae4895605a348322dd2fc50f2065f508.

That is not a good comparison. 55ca3f99 (commit-tree: add and document --no-gpg-sign, 2013-12-13) is about signed commit, and over there there are only two choices, i.e. a commit that corresponds to an annotated tag, and a signed commit that corresponds to a signed tag. There is no "lightweight-tag" equivalent.

Quoted 9 lines
Quoted 6 lines

If you are forcing users to always leave a message and then further forcing users to always sign with the single new configuration, i.e.

    $ git tag v1.0
    ... opens the editor to ask for a message ...
    ... then makes the user sign with GPG ...

I'm not forcing this type of user to enable global configuration, that will be annoying for them of course.

Good.

If so, then the configuration is "when the user gives us a message to create a tag without explicitly saying -a/-s, we create an annotated tag by default, but create a signed tag instead in such a case", I would think. That is:

    $ git tag -m 'foo' $tagname

would create signed tag under such a configuration option, and I think such an option may make sense. And the way to override it would be

    $ git tag -a -m 'foo' $tagname
Quoted 8 lines

So there is no need for --no-sign option. When the user explicitly asks to create an annotated tag with

    $ git tag -a -m 'foo' $tagname

it is unreasonable to override that explicit wish with a configuration setting.

Ah, I think I understand now, I think this will not take to much effort to fix.

Signature · 1 line
Laurent
#11 lore raw
In reply to Junio C Hamano
Quoted 13 lines · Junio C Hamano

If so, then the configuration is "when the user gives us a message to create a tag without explicitly saying -a/-s, we create an annotated tag by default, but create a signed tag instead in such a case", I would think. That is:

    $ git tag -m 'foo' $tagname

would create signed tag under such a configuration option, and I think such an option may make sense. And the way to override it would be

    $ git tag -a -m 'foo' $tagname
Quoted 7 lines

So there is no need for --no-sign option. When the user explicitly asks to create an annotated tag with

    $ git tag -a -m 'foo' $tagname

it is unreasonable to override that explicit wish with a configuration setting.

FWIW, of the schemes discussed in this thread, this one makes the most sense to me (and is one I might actually use).

I think you could shoe-horn it into my "tag-type" config scheme as a new mode ("sign-if-message" or something), but I think it is much clearer as a standalone config variable.

Thanks for a dose of sanity.

-Peff

#12 lore raw

PATCH v4 1/1 Add the tag.gpgsign option to sign annotated tags

In reply to Junio C Hamano

The tag.gpgsign config option allows to sign annotated tags automatically.

--annotate command line option disable configuration tag.gpgsign.

---
 Documentation/config.txt |  5 +++++
 builtin/tag.c            | 20 +++++++++++++++-----
 t/t7004-tag.sh           | 33 +++++++++++++++++++++++++++++++++
 3 files changed, 53 insertions(+), 5 deletions(-)
Documentation/config.txt +5 -0
index 2cd6bdd..62f7d2a 100644
@@ -2729,6 +2729,11 @@ submodule.<name>.ignore::
 	"--ignore-submodules" option. The 'git submodule' commands are not
 	affected by this setting.
 
+tag.gpgSign::
+	A boolean to specify whether annotated tags created should be GPG signed.
+	If `--annotate` is specified on the command line, it takes
+	precedence over this option.
+
 tag.sort::
 	This variable controls the sort ordering of tags when displayed by
 	linkgit:git-tag[1]. Without the "--sort=<value>" option provided, the
builtin/tag.c +15 -5
index 1705c94..748aeac 100644
@@ -29,6 +29,7 @@ static const char * const git_tag_usage[] = {
 };
 
 static unsigned int colopts;
+static unsigned int sign_tag_config;
 
 static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting, const char *format)
 {
@@ -166,6 +167,11 @@ static int git_tag_config(const char *var, const char *value, void *cb)
 	status = git_gpg_config(var, value, cb);
 	if (status)
 		return status;
+	if (!strcmp(var, "tag.gpgsign")) {
+		sign_tag_config = git_config_bool(var, value);
+		return 0;
+	}
+
 	if (starts_with(var, "column."))
 		return git_column_config(var, value, "tag", &colopts);
 	return git_default_config(var, value, cb);
@@ -326,7 +332,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 	struct create_tag_options opt;
 	char *cleanup_arg = NULL;
 	int create_reflog = 0;
-	int annotate = 0, force = 0;
+	int annotate = -1, force = 0;
 	int cmdmode = 0;
 	const char *msgfile = NULL, *keyid = NULL;
 	struct msg_arg msg = { 0, STRBUF_INIT };
@@ -381,16 +387,20 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 
 	argc = parse_options(argc, argv, prefix, options, git_tag_usage, 0);
 
+	if (argc == 0 && !cmdmode)
+		cmdmode = 'l';
+
+	if (!cmdmode && sign_tag_config && annotate < 1)
+		opt.sign = 1;
+
 	if (keyid) {
 		opt.sign = 1;
 		set_signing_key(keyid);
 	}
 	if (opt.sign)
 		annotate = 1;
-	if (argc == 0 && !cmdmode)
-		cmdmode = 'l';
 
-	if ((annotate || msg.given || msgfile || force) && (cmdmode != 0))
+	if ((annotate > 0 || msg.given || msgfile || force) && (cmdmode != 0))
 		usage_with_options(git_tag_usage, options);
 
 	finalize_colopts(&colopts, -1);
@@ -474,7 +484,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 	else
 		die(_("Invalid cleanup mode %s"), cleanup_arg);
 
-	if (annotate)
+	if (annotate > 0)
 		create_tag(object, tag, &buf, &opt, prev, object);
 
 	transaction = ref_transaction_begin(&err);
t/t7004-tag.sh +33 -0
index cf3469b..7791d00 100755
@@ -775,6 +775,39 @@ test_expect_success GPG '-s implies annotated tag' '
 	test_cmp expect actual
 '
 
+get_tag_header config-implied-annotate $commit commit $time >expect
+./fakeeditor >>expect
+echo '-----BEGIN PGP SIGNATURE-----' >>expect
+test_expect_success GPG \
+	'git tag -s implied if configured with tag.gpgsign' \
+	'test_config tag.gpgsign true &&
+	GIT_EDITOR=./fakeeditor git tag config-implied-annotate &&
+	get_tag_msg config-implied-annotate >actual &&
+	test_cmp expect actual
+'
+
+get_tag_header config-implied-annotate-disabled $commit commit $time >expect
+echo "A message" >>expect
+test_expect_success GPG \
+	'git tag -a disable configured tag.gpgsign' \
+	'test_config tag.gpgsign true &&
+	git tag -a -m "A message" config-implied-annotate-disabled &&
+	get_tag_msg config-implied-annotate-disabled >actual &&
+	test_cmp expect actual &&
+	test_must_fail git tag -v config-implied-annotate-disabled
+'
+
+get_tag_header config-disabled-gpgsign $commit commit $time >expect
+echo "A message" >>expect
+echo '-----BEGIN PGP SIGNATURE-----' >>expect
+test_expect_success GPG \
+	'git tag --sign enable GPG sign' \
+	'test_config tag.gpgsign false &&
+	git tag --sign -m "A message" config-disabled-gpgsign &&
+	get_tag_msg config-disabled-gpgsign >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success GPG \
 	'trying to create a signed tag with non-existing -F file should fail' '
 	! test -f nonexistingfile &&
Signature · 1 line
2.7.0
#13 lore raw

Re: [PATCH v4] Add the tag.gpgsign option to sign annotated tags

Review int cmd_tag(int argc, const char **argv, const char *prefix) · line 335

Quoted 6 lines · Laurent Arnoud
(quoted diff) +1 -1
@@ -326,7 +332,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 	struct create_tag_options opt;
 	char *cleanup_arg = NULL;
 	int create_reflog = 0;
-	int annotate = 0, force = 0;
+	int annotate = -1, force = 0;

I really do not like this part of the change. The original code is already bad in the sense that it uses "annotate" to mean "we need to create a tag object, not just a lightweight tag" in some places which already needs careful reading, but with this it no longer is clear what this argument even means. It sometimes means "we are creating a tag object" and some other times means "we did not see '-a' on the command line" but only until the variable gets assigned by existing "if opt.sign is there, set it to true" tweaking.

I wonder if an approach like the following would result in a cleaner code that is easier to maintain:

- Leave this to be initialized to 0, allow it to be toggled upon seeing "-a" via the parse_options() mechanism, but redefine its meaning to be "-a option was passed". Make it never be touched by anything else (e.g. "if (opt.sign) annotate = 1;" is wrong).

- Introduce a new "create_tag_object" variable, initialized to 0. Existing code that sets "annotate = 1" (e.g. "-s" is passed, "-m/-F" is passed, etc.) will instead set this variable. The condition of if() statement to call create_tag() would also be looking at this variable, not "annotate".

- Before calling create_tag(), look at the value of your new configuration and "annotate", and set opt.sign as needed.

A patch to do so might look something like this (totally untested).

 builtin/tag.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)
builtin/tag.c +14 -6
index 1705c94..d262f92 100644
@@ -29,6 +29,7 @@ static const char * const git_tag_usage[] = {
 };
 
 static unsigned int colopts;
+static int force_sign_annotate;
 
 static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting, const char *format)
 {
@@ -168,6 +169,10 @@ static int git_tag_config(const char *var, const char *value, void *cb)
 		return status;
 	if (starts_with(var, "column."))
 		return git_column_config(var, value, "tag", &colopts);
+	if (!strcmp(var, "tag.forcesignannotated")) {
+		force_sign_annotate = git_config_bool(var, value);
+		return 0;
+	}
 	return git_default_config(var, value, cb);
 }
 
@@ -327,7 +332,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 	char *cleanup_arg = NULL;
 	int create_reflog = 0;
 	int annotate = 0, force = 0;
-	int cmdmode = 0;
+	int cmdmode = 0, create_tag_object = 0;
 	const char *msgfile = NULL, *keyid = NULL;
 	struct msg_arg msg = { 0, STRBUF_INIT };
 	struct ref_transaction *transaction;
@@ -385,12 +390,12 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 		opt.sign = 1;
 		set_signing_key(keyid);
 	}
-	if (opt.sign)
-		annotate = 1;
+	if (opt.sign || annotate)
+		create_tag_object = 1;
 	if (argc == 0 && !cmdmode)
 		cmdmode = 'l';
 
-	if ((annotate || msg.given || msgfile || force) && (cmdmode != 0))
+	if ((create_tag_object || msg.given || msgfile || force) && (cmdmode != 0))
 		usage_with_options(git_tag_usage, options);
 
 	finalize_colopts(&colopts, -1);
@@ -431,7 +436,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 	if (msg.given || msgfile) {
 		if (msg.given && msgfile)
 			die(_("only one -F or -m option is allowed."));
-		annotate = 1;
+		create_tag_object = 1;
 		if (msg.given)
 			strbuf_addbuf(&buf, &(msg.buf));
 		else {
@@ -474,8 +479,11 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 	else
 		die(_("Invalid cleanup mode %s"), cleanup_arg);
 
-	if (annotate)
+	if (create_tag_object) {
+		if (force_sign_annotate && !annotate)
+			opt.sign = 1;
 		create_tag(object, tag, &buf, &opt, prev, object);
+	}
 
 	transaction = ref_transaction_begin(&err);
 	if (!transaction ||
#18 lore raw
In reply to Junio C Hamano
Quoted 11 lines · Junio C Hamano
Quoted 9 lines
Quoted 6 lines

If you are forcing users to always leave a message and then further forcing users to always sign with the single new configuration, i.e.

    $ git tag v1.0
    ... opens the editor to ask for a message ...
    ... then makes the user sign with GPG ...

I'm not forcing this type of user to enable global configuration, that will be annoying for them of course.

Good.

Eh, it seems that your test actually expects this kind of interaction, though.

This piece from your PATCH v4:

    diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh
    index cf3469b..7791d00 100755
    --- a/t/t7004-tag.sh
    +++ b/t/t7004-tag.sh
    @@ -775,6 +775,39 @@ test_expect_success GPG '-s implies annotated tag' '
            test_cmp expect actual
     '

    +get_tag_header config-implied-annotate $commit commit $time >expect
    +./fakeeditor >>expect
    +echo '-----BEGIN PGP SIGNATURE-----' >>expect
    +test_expect_success GPG \
    +	'git tag -s implied if configured with tag.gpgsign' \
    +	'test_config tag.gpgsign true &&
    +	GIT_EDITOR=./fakeeditor git tag config-implied-annotate &&
    +	get_tag_msg config-implied-annotate >actual &&
    +	test_cmp expect actual
    +'
    +

wants to see that "git tag config-implied-annotate" (which looks exactly like "git tag v1.0" we discussed above) runs the fakeeditor and makes a signed tag.

#19 lore raw

PATCH v3 1/1 Add the tag.gpgsign option to sign annotated tags

In reply to Junio C Hamano

The tag.gpgsign config option allows to sign all annotated tags automatically.

Support --no-sign option to countermand configuration tag.gpgsign.

---
 Documentation/config.txt  |  5 +++++
 Documentation/git-tag.txt |  6 +++++-
 builtin/tag.c             | 21 ++++++++++++++++-----
 t/t7004-tag.sh            | 45 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 71 insertions(+), 6 deletions(-)
Documentation/config.txt +5 -0
index 2cd6bdd..ba9d4da 100644
@@ -2729,6 +2729,11 @@ submodule.<name>.ignore::
 	"--ignore-submodules" option. The 'git submodule' commands are not
 	affected by this setting.
 
+tag.gpgSign::
+	A boolean to specify whether annotated tags created should be GPG signed.
+	If `--no-sign` is specified on the command line, it takes
+	precedence over this option.
+
 tag.sort::
 	This variable controls the sort ordering of tags when displayed by
 	linkgit:git-tag[1]. Without the "--sort=<value>" option provided, the
Documentation/git-tag.txt +5 -1
index abab481..180edd2 100644
@@ -9,7 +9,7 @@ git-tag - Create, list, delete or verify a tag object signed with GPG
 SYNOPSIS
 --------
 [verse]
-'git tag' [-a | -s | -u <keyid>] [-f] [-m <msg> | -F <file>]
+'git tag' [-a | -s | --no-sign | -u <keyid>] [-f] [-m <msg> | -F <file>]
 	<tagname> [<commit> | <object>]
 'git tag' -d <tagname>...
 'git tag' [-n[<num>]] -l [--contains <commit>] [--points-at <object>]
@@ -64,6 +64,10 @@ OPTIONS
 --sign::
 	Make a GPG-signed tag, using the default e-mail address's key.
 
+--no-sign::
+	Countermand `tag.gpgSign` configuration variable that is
+	set to force annoted tags to be signed.
+
 -u <keyid>::
 --local-user=<keyid>::
 	Make a GPG-signed tag, using the given key.
builtin/tag.c +16 -5
index 1705c94..2a7b2f2 100644
@@ -29,6 +29,7 @@ static const char * const git_tag_usage[] = {
 };
 
 static unsigned int colopts;
+static unsigned int sign_tag_config;
 
 static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting, const char *format)
 {
@@ -166,6 +167,11 @@ static int git_tag_config(const char *var, const char *value, void *cb)
 	status = git_gpg_config(var, value, cb);
 	if (status)
 		return status;
+	if (!strcmp(var, "tag.gpgsign")) {
+		sign_tag_config = git_config_bool(var, value) ? 1 : 0;
+		return 0;
+	}
+
 	if (starts_with(var, "column."))
 		return git_column_config(var, value, "tag", &colopts);
 	return git_default_config(var, value, cb);
@@ -195,7 +201,7 @@ static void write_tag_body(int fd, const unsigned char *sha1)
 
 static int build_tag_object(struct strbuf *buf, int sign, unsigned char *result)
 {
-	if (sign && do_sign(buf) < 0)
+	if (sign > 0 && do_sign(buf) < 0)
 		return error(_("unable to sign the tag"));
 	if (write_sha1_file(buf->buf, buf->len, tag_type, result) < 0)
 		return error(_("unable to write tag file"));
@@ -204,7 +210,7 @@ static int build_tag_object(struct strbuf *buf, int sign, unsigned char *result)
 
 struct create_tag_options {
 	unsigned int message_given:1;
-	unsigned int sign;
+	int sign;
 	enum {
 		CLEANUP_NONE,
 		CLEANUP_SPACE,
@@ -378,17 +384,22 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 	memset(&opt, 0, sizeof(opt));
 	memset(&filter, 0, sizeof(filter));
 	filter.lines = -1;
+	opt.sign = -1;
 
 	argc = parse_options(argc, argv, prefix, options, git_tag_usage, 0);
 
+	if (argc == 0 && !cmdmode)
+		cmdmode = 'l';
+
+	if (!cmdmode && sign_tag_config && opt.sign != 0)
+		opt.sign = 1;
+
 	if (keyid) {
 		opt.sign = 1;
 		set_signing_key(keyid);
 	}
-	if (opt.sign)
+	if (opt.sign > 0)
 		annotate = 1;
-	if (argc == 0 && !cmdmode)
-		cmdmode = 'l';
 
 	if ((annotate || msg.given || msgfile || force) && (cmdmode != 0))
 		usage_with_options(git_tag_usage, options);
t/t7004-tag.sh +45 -0

51 lines not on this page · raw message

Signature · 1 line
2.7.0
#20 lore raw

Re: [PATCH v3] Add the tag.gpgsign option to sign annotated tags

Quoted 7 lines · Laurent Arnoud

The tag.gpgsign config option allows to sign all annotated tags automatically.

Support --no-sign option to countermand configuration tag.gpgsign.

The meaning of "Reviewed-by" in this project is generally that the mentioned person has read and approved of the change. But in this case, I have not seen v3 at all yet, and I am also not sure that the ones I _did_ review are ready for merging.

So you should probably drop that.

Documentation/config.txt submodule.<name>.ignore:: · line 2735

Quoted 4 lines
Documentation/config.txt +4 -0
+tag.gpgSign::
+	A boolean to specify whether annotated tags created should be GPG signed.
+	If `--no-sign` is specified on the command line, it takes
+	precedence over this option.

I take this to mean that we _only_ kick in signing if the created tag would otherwise be annotated (and I thought that's what you meant in your other mail, too). But that's not what happens with this patch, and your tests check for the opposite:

t/t7004-tag.sh test_expect_success GPG '-s implies annotated tag' ' · line 788

Quoted 11 lines
t/t7004-tag.sh +11 -0
+get_tag_header config-implied-annotate $commit commit $time >expect
+./fakeeditor >>expect
+echo '-----BEGIN PGP SIGNATURE-----' >>expect
+git config tag.gpgsign true
+test_expect_success GPG \
+	'git tag -s implied if configured with tag.gpgsign' \
+	'GIT_EDITOR=./fakeeditor git tag config-implied-annotate &&
+	get_tag_msg config-implied-annotate >actual &&
+	test_cmp expect actual
+'
+git config --unset tag.gpgsign

That's a lightweight tag that becomes an annotated one due to the config variable.

So I think there may be some design-level issues to work out here, but I'll comment on a few more code-specific things, in case that code does get carried through:

builtin/tag.c static int git_tag_config(const char *var, const char *value, void *cb) · line 173

Quoted 4 lines
builtin/tag.c +4 -0
+	if (!strcmp(var, "tag.gpgsign")) {
+		sign_tag_config = git_config_bool(var, value) ? 1 : 0;
+		return 0;
+	}

git_config_bool() already converts to 0/1, you can just say:

  sign_tag_config = git_config_bool(var, value);

t/t7004-tag.sh test_expect_success GPG '-s implies annotated tag' ' · line 800

Quoted 11 lines
t/t7004-tag.sh +11 -0
+get_tag_header config-implied-annotate-disabled $commit commit $time >expect
+echo "A message" >>expect
+git config tag.gpgsign true
+test_expect_success GPG \
+	'git tag --no-sign disable configured tag.gpgsign' \
+	'git tag --no-sign -m "A message" config-implied-annotate-disabled &&
+	get_tag_msg config-implied-annotate-disabled >actual &&
+	test_cmp expect actual &&
+	test_must_fail git tag -v config-implied-annotate-disabled
+'
+git config --unset tag.gpgsign

Here (and in the other tests), you can use:

test_config tag.gpgsign true &&
...

inside the test_expect_success block. That has two advantages:

1. If setting the config fails for some reason, we'll notice and the test will fail.

2. At the end of the test block, it will automatically clean up the variable for us.

-Peff

#21 lore raw
In reply to Junio C Hamano
Quoted 4 lines · Junio C Hamano
Quoted 1 line

Support --no-sign option to countermand configuration tag.gpgsign.

That sound quite counter-intuitive.
[...]

I was the one who suggested --no-sign, as we usually like to have a way to countermand the config. But having read your message, I agree that is probably not the right mental model.

In particular, this:

Quoted 9 lines

I can sort-of understand (but do not necessarily agree that it is a good idea) adding new two configurations, i.e.

- "even without -a/-s, force the user to annotate the tag" is one configuration, and

- "even when the user did not say -s, force the user to sign an annotated tag" is the other.

Quoted 9 lines

And with such a system, I can see why you would need an option "--lightweight" to force creation of a light-weight tag (i.e. to countermand the first one). You can view this new option as something that sits next to existing -a/-s. The current system lets user choose among the three variants (lightweight, annotated and signed) by not giving any, giving -a, and giving -s option respectively, but with the "--lightweight" option, the user can ask for one of the three explicitly, as opposed to using "lack of either -a/-s" as a signal to create lightweight one.

makes sense to me (though like you, I do not necessarily think it is a good idea and would not use it myself).

Another similar approach would be to collapse this down to a single variable that selects from the options. IOW:

1. Add --lightweight for explicitly adding a lightweight tag.

2. When we are creating a tag and none of "-a", "-s", or "--lightweight" is given, use the default given in tag.defaultTagType (or whatever we call it), which can be "lightweight", "annotated", or "signed".

3. tag.defaultTagType defaults to "lightweight".

That is conceptually simpler to me, with the main differences being:

- in yours, the second config would mean that an explicit "-a" implies "-s" (unless the user says --no-sign).

- in mine, there is no way to kick in the signing _only_ when we are annotating. If you configure "signed", then you have to explicitly say "--lightweight" for lightweight tags.

I dunno. It sounds like Laurent would set it to "signed", and that would do what he wants. But like I said, I would not plan to use the feature myself, and I could see it ending up a little bit annoying when you _do_ want a lightweight tag.

-Peff

#14 lore raw

PATCH v5 1/1 Add the option to force sign annotated tags

In reply to Junio C Hamano

The tag.forcesignannotated config option allows to sign annotated tags automatically.

--annotate command line option disable configuration tag.forcesignannotated.

---
 Documentation/config.txt |  5 +++++
 builtin/tag.c            | 22 ++++++++++++++++------
 t/t7004-tag.sh           | 33 +++++++++++++++++++++++++++++++++
 3 files changed, 54 insertions(+), 6 deletions(-)
Documentation/config.txt +5 -0
index 2cd6bdd..95d5c9d 100644
@@ -2729,6 +2729,11 @@ submodule.<name>.ignore::
 	"--ignore-submodules" option. The 'git submodule' commands are not
 	affected by this setting.
 
+tag.forceSignAnnotated::
+	A boolean to specify whether annotated tags created should be GPG signed.
+	If `--annotate` is specified on the command line, it takes
+	precedence over this option.
+
 tag.sort::
 	This variable controls the sort ordering of tags when displayed by
 	linkgit:git-tag[1]. Without the "--sort=<value>" option provided, the
builtin/tag.c +16 -6
index 1705c94..c447738 100644
@@ -29,6 +29,7 @@ static const char * const git_tag_usage[] = {
 };
 
 static unsigned int colopts;
+static int force_sign_annotate;
 
 static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting, const char *format)
 {
@@ -166,6 +167,11 @@ static int git_tag_config(const char *var, const char *value, void *cb)
 	status = git_gpg_config(var, value, cb);
 	if (status)
 		return status;
+	if (!strcmp(var, "tag.forcesignannotated")) {
+		force_sign_annotate = git_config_bool(var, value);
+		return 0;
+	}
+
 	if (starts_with(var, "column."))
 		return git_column_config(var, value, "tag", &colopts);
 	return git_default_config(var, value, cb);
@@ -327,7 +333,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 	char *cleanup_arg = NULL;
 	int create_reflog = 0;
 	int annotate = 0, force = 0;
-	int cmdmode = 0;
+	int cmdmode = 0, create_tag_object = 0;
 	const char *msgfile = NULL, *keyid = NULL;
 	struct msg_arg msg = { 0, STRBUF_INIT };
 	struct ref_transaction *transaction;
@@ -385,12 +391,13 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 		opt.sign = 1;
 		set_signing_key(keyid);
 	}
-	if (opt.sign)
-		annotate = 1;
+	if (opt.sign || annotate || force_sign_annotate)
+		create_tag_object = 1;
+
 	if (argc == 0 && !cmdmode)
 		cmdmode = 'l';
 
-	if ((annotate || msg.given || msgfile || force) && (cmdmode != 0))
+	if ((create_tag_object || msg.given || msgfile || force) && (cmdmode != 0))
 		usage_with_options(git_tag_usage, options);
 
 	finalize_colopts(&colopts, -1);
@@ -431,7 +438,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 	if (msg.given || msgfile) {
 		if (msg.given && msgfile)
 			die(_("only one -F or -m option is allowed."));
-		annotate = 1;
+		create_tag_object = 1;
 		if (msg.given)
 			strbuf_addbuf(&buf, &(msg.buf));
 		else {
@@ -474,8 +481,11 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 	else
 		die(_("Invalid cleanup mode %s"), cleanup_arg);
 
-	if (annotate)
+	if (create_tag_object) {
+		if (force_sign_annotate && !annotate)
+			opt.sign = 1;
 		create_tag(object, tag, &buf, &opt, prev, object);
+    }
 
 	transaction = ref_transaction_begin(&err);
 	if (!transaction ||
t/t7004-tag.sh +33 -0
index cf3469b..be95318 100755
@@ -775,6 +775,39 @@ test_expect_success GPG '-s implies annotated tag' '
 	test_cmp expect actual
 '
 
+get_tag_header config-implied-annotate $commit commit $time >expect
+./fakeeditor >>expect
+echo '-----BEGIN PGP SIGNATURE-----' >>expect
+test_expect_success GPG \
+	'git tag -s implied if configured with tag.forcesignannotated' \
+	'test_config tag.forcesignannotated true &&
+	GIT_EDITOR=./fakeeditor git tag config-implied-annotate &&
+	get_tag_msg config-implied-annotate >actual &&
+	test_cmp expect actual
+'
+
+get_tag_header config-implied-annotate-disabled $commit commit $time >expect
+echo "A message" >>expect
+test_expect_success GPG \
+	'git tag -a disable configured tag.forcesignannotated' \
+	'test_config tag.forcesignannotated true &&
+	git tag -a -m "A message" config-implied-annotate-disabled &&
+	get_tag_msg config-implied-annotate-disabled >actual &&
+	test_cmp expect actual &&
+	test_must_fail git tag -v config-implied-annotate-disabled
+'
+
+get_tag_header config-disabled-forcesignannotated $commit commit $time >expect
+echo "A message" >>expect
+echo '-----BEGIN PGP SIGNATURE-----' >>expect
+test_expect_success GPG \
+	'git tag --sign enable GPG sign' \
+	'test_config tag.forcesignannotated false &&
+	git tag --sign -m "A message" config-disabled-forcesignannotated &&
+	get_tag_msg config-disabled-forcesignannotated >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success GPG \
 	'trying to create a signed tag with non-existing -F file should fail' '
 	! test -f nonexistingfile &&
Signature · 1 line
2.7.0
#15 lore raw

Re: [PATCH v5] Add the option to force sign annotated tags

Quoted 2 lines · Laurent Arnoud

The tag.forcesignannotated config option allows to sign annotated tags automatically.

It looks like it does a lot more than that to me, though.

Quoted 10 lines
builtin/tag.c +1 -1
@@ -327,7 +333,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 	char *cleanup_arg = NULL;
 	int create_reflog = 0;
 	int annotate = 0, force = 0;
-	int cmdmode = 0;
+	int cmdmode = 0, create_tag_object = 0;
 	const char *msgfile = NULL, *keyid = NULL;
 	struct msg_arg msg = { 0, STRBUF_INIT };
 	struct ref_transaction *transaction;

builtin/tag.c int cmd_tag(int argc, const char **argv, const char *prefix) · line 395

Quoted 7 lines
builtin/tag.c +2 -2
@@ -385,12 +391,13 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 		opt.sign = 1;
 		set_signing_key(keyid);
 	}
-	if (opt.sign)
-		annotate = 1;
+	if (opt.sign || annotate || force_sign_annotate)
+		create_tag_object = 1;

This means that create_tag_object is always on if the configuration is set and there is no way to override that from the command line, doesn't it? I cannot see how a user would create a lightweight tag if this configuration variable is set with this change.

I think it makes sense to have this here instead of these two lines:

	create_tag_object = (opt.sign || annotate || msg.given || msgfile);

builtin/tag.c int cmd_tag(int argc, const char **argv, const char *prefix) · line 400

Quoted 5 lines
builtin/tag.c +1 -1
 	if (argc == 0 && !cmdmode)
 		cmdmode = 'l';
 
-	if ((annotate || msg.given || msgfile || force) && (cmdmode != 0))
+	if ((create_tag_object || msg.given || msgfile || force) && (cmdmode != 0))

and then simplify this to

	if ((create_tag_object || force) && (cmdmode != 0))

perhaps? Then ...

builtin/tag.c int cmd_tag(int argc, const char **argv, const char *prefix) · line 441

Quoted 9 lines
builtin/tag.c +1 -1
 		usage_with_options(git_tag_usage, options);
 
 	finalize_colopts(&colopts, -1);
@@ -431,7 +438,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 	if (msg.given || msgfile) {
 		if (msg.given && msgfile)
 			die(_("only one -F or -m option is allowed."));
-		annotate = 1;
+		create_tag_object = 1;

... this line can just go, as we are taking the presense of various ways to say "I'll give this message to the resulting tag" as the sign that the user wants to create a tag object much earlier.

builtin/tag.c int cmd_tag(int argc, const char **argv, const char *prefix) · line 488

Quoted 13 lines
builtin/tag.c +4 -1
 		if (msg.given)
 			strbuf_addbuf(&buf, &(msg.buf));
 		else {
@@ -474,8 +481,11 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 	else
 		die(_("Invalid cleanup mode %s"), cleanup_arg);
 
-	if (annotate)
+	if (create_tag_object) {
+		if (force_sign_annotate && !annotate)
+			opt.sign = 1;
 		create_tag(object, tag, &buf, &opt, prev, object);
+    }

And this hunk is OK.

Quoted 5 lines
t/t7004-tag.sh +0 -0
index cf3469b..be95318 100755

t/t7004-tag.sh test_expect_success GPG '-s implies annotated tag' ' · line 784

Quoted 10 lines
t/t7004-tag.sh +7 -0
@@ -775,6 +775,39 @@ test_expect_success GPG '-s implies annotated tag' '
 	test_cmp expect actual
 '
 
+get_tag_header config-implied-annotate $commit commit $time >expect
+./fakeeditor >>expect
+echo '-----BEGIN PGP SIGNATURE-----' >>expect
+test_expect_success GPG \
+	'git tag -s implied if configured with tag.forcesignannotated' \
+	'test_config tag.forcesignannotated true &&
+	GIT_EDITOR=./fakeeditor git tag config-implied-annotate &&

This contradicts with what you said earlier in your <20160321192904.GC20083@spk-laptop> aka
http://thread.gmane.org/gmane.comp.version-control.git/289322/focus=289441

Quoted 6 lines

If you are forcing users to always leave a message and then further forcing users to always sign with the single new configuration, i.e.

    $ git tag v1.0
    ... opens the editor to ask for a message ...
    ... then makes the user sign with GPG ...

I'm not forcing this type of user to enable global configuration, that will be annoying for them of course.

But this test expects that this invocation of "git tag $tagname" forces the user to give a message with editor and sign it, instead of creating a lightweight tag.

#16 lore raw

Re: [PATCH v5] Add the option to force sign annotated tags

Quoted 103 lines · Junio C Hamano
Quoted 2 lines · Laurent Arnoud

The tag.forcesignannotated config option allows to sign annotated tags automatically.

It looks like it does a lot more than that to me, though.

Quoted 10 lines
builtin/tag.c +1 -1
@@ -327,7 +333,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 	char *cleanup_arg = NULL;
 	int create_reflog = 0;
 	int annotate = 0, force = 0;
-	int cmdmode = 0;
+	int cmdmode = 0, create_tag_object = 0;
 	const char *msgfile = NULL, *keyid = NULL;
 	struct msg_arg msg = { 0, STRBUF_INIT };
 	struct ref_transaction *transaction;

builtin/tag.c int cmd_tag(int argc, const char **argv, const char *prefix) · line 395

Quoted 7 lines
builtin/tag.c +2 -2
@@ -385,12 +391,13 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 		opt.sign = 1;
 		set_signing_key(keyid);
 	}
-	if (opt.sign)
-		annotate = 1;
+	if (opt.sign || annotate || force_sign_annotate)
+		create_tag_object = 1;

This means that create_tag_object is always on if the configuration is set and there is no way to override that from the command line, doesn't it? I cannot see how a user would create a lightweight tag if this configuration variable is set with this change.

I think it makes sense to have this here instead of these two lines:

	create_tag_object = (opt.sign || annotate || msg.given || msgfile);

builtin/tag.c int cmd_tag(int argc, const char **argv, const char *prefix) · line 400

Quoted 5 lines
builtin/tag.c +1 -1
 	if (argc == 0 && !cmdmode)
 		cmdmode = 'l';
 
-	if ((annotate || msg.given || msgfile || force) && (cmdmode != 0))
+	if ((create_tag_object || msg.given || msgfile || force) && (cmdmode != 0))

and then simplify this to

	if ((create_tag_object || force) && (cmdmode != 0))

perhaps? Then ...

builtin/tag.c int cmd_tag(int argc, const char **argv, const char *prefix) · line 441

Quoted 9 lines
builtin/tag.c +1 -1
 		usage_with_options(git_tag_usage, options);
 
 	finalize_colopts(&colopts, -1);
@@ -431,7 +438,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 	if (msg.given || msgfile) {
 		if (msg.given && msgfile)
 			die(_("only one -F or -m option is allowed."));
-		annotate = 1;
+		create_tag_object = 1;

... this line can just go, as we are taking the presense of various ways to say "I'll give this message to the resulting tag" as the sign that the user wants to create a tag object much earlier.

builtin/tag.c int cmd_tag(int argc, const char **argv, const char *prefix) · line 488

Quoted 13 lines
builtin/tag.c +4 -1
 		if (msg.given)
 			strbuf_addbuf(&buf, &(msg.buf));
 		else {
@@ -474,8 +481,11 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 	else
 		die(_("Invalid cleanup mode %s"), cleanup_arg);
 
-	if (annotate)
+	if (create_tag_object) {
+		if (force_sign_annotate && !annotate)
+			opt.sign = 1;
 		create_tag(object, tag, &buf, &opt, prev, object);
+    }

And this hunk is OK.

Quoted 5 lines
t/t7004-tag.sh +0 -0
index cf3469b..be95318 100755

t/t7004-tag.sh test_expect_success GPG '-s implies annotated tag' ' · line 784

Quoted 10 lines
t/t7004-tag.sh +7 -0
@@ -775,6 +775,39 @@ test_expect_success GPG '-s implies annotated tag' '
 	test_cmp expect actual
 '
 
+get_tag_header config-implied-annotate $commit commit $time >expect
+./fakeeditor >>expect
+echo '-----BEGIN PGP SIGNATURE-----' >>expect
+test_expect_success GPG \
+	'git tag -s implied if configured with tag.forcesignannotated' \
+	'test_config tag.forcesignannotated true &&
+	GIT_EDITOR=./fakeeditor git tag config-implied-annotate &&

This contradicts with what you said earlier in your <20160321192904.GC20083@spk-laptop> aka
http://thread.gmane.org/gmane.comp.version-control.git/289322/focus=289441

Quoted 6 lines

If you are forcing users to always leave a message and then further forcing users to always sign with the single new configuration, i.e.

    $ git tag v1.0
    ... opens the editor to ask for a message ...
    ... then makes the user sign with GPG ...
Quoted 6 lines

I'm not forcing this type of user to enable global configuration, that will be annoying for them of course.

But this test expects that this invocation of "git tag $tagname" forces the user to give a message with editor and sign it, instead of creating a lightweight tag.

Yes you're right, I will fix that...

Signature · 1 line
Laurent
#17 lore raw

PATCH v6 1/1 Add the option to force sign annotated tags

In reply to Junio C Hamano

The tag.forcesignannotated config option allows to sign annotated tags automatically.

--annotate command line option disable configuration tag.forcesignannotated.

---
 Documentation/config.txt |  5 +++++
 builtin/tag.c            | 20 ++++++++++++++------
 t/t7004-tag.sh           | 41 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 60 insertions(+), 6 deletions(-)
Documentation/config.txt +5 -0
index 2cd6bdd..95d5c9d 100644
@@ -2729,6 +2729,11 @@ submodule.<name>.ignore::
 	"--ignore-submodules" option. The 'git submodule' commands are not
 	affected by this setting.
 
+tag.forceSignAnnotated::
+	A boolean to specify whether annotated tags created should be GPG signed.
+	If `--annotate` is specified on the command line, it takes
+	precedence over this option.
+
 tag.sort::
 	This variable controls the sort ordering of tags when displayed by
 	linkgit:git-tag[1]. Without the "--sort=<value>" option provided, the
builtin/tag.c +14 -6
index 1705c94..528a1ba 100644
@@ -29,6 +29,7 @@ static const char * const git_tag_usage[] = {
 };
 
 static unsigned int colopts;
+static int force_sign_annotate;
 
 static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting, const char *format)
 {
@@ -166,6 +167,11 @@ static int git_tag_config(const char *var, const char *value, void *cb)
 	status = git_gpg_config(var, value, cb);
 	if (status)
 		return status;
+	if (!strcmp(var, "tag.forcesignannotated")) {
+		force_sign_annotate = git_config_bool(var, value);
+		return 0;
+	}
+
 	if (starts_with(var, "column."))
 		return git_column_config(var, value, "tag", &colopts);
 	return git_default_config(var, value, cb);
@@ -327,7 +333,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 	char *cleanup_arg = NULL;
 	int create_reflog = 0;
 	int annotate = 0, force = 0;
-	int cmdmode = 0;
+	int cmdmode = 0, create_tag_object = 0;
 	const char *msgfile = NULL, *keyid = NULL;
 	struct msg_arg msg = { 0, STRBUF_INIT };
 	struct ref_transaction *transaction;
@@ -385,12 +391,12 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 		opt.sign = 1;
 		set_signing_key(keyid);
 	}
-	if (opt.sign)
-		annotate = 1;
+	create_tag_object = (opt.sign || annotate || msg.given || msgfile);
+
 	if (argc == 0 && !cmdmode)
 		cmdmode = 'l';
 
-	if ((annotate || msg.given || msgfile || force) && (cmdmode != 0))
+	if ((create_tag_object || force) && (cmdmode != 0))
 		usage_with_options(git_tag_usage, options);
 
 	finalize_colopts(&colopts, -1);
@@ -431,7 +437,6 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 	if (msg.given || msgfile) {
 		if (msg.given && msgfile)
 			die(_("only one -F or -m option is allowed."));
-		annotate = 1;
 		if (msg.given)
 			strbuf_addbuf(&buf, &(msg.buf));
 		else {
@@ -474,8 +479,11 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 	else
 		die(_("Invalid cleanup mode %s"), cleanup_arg);
 
-	if (annotate)
+	if (create_tag_object) {
+		if (force_sign_annotate && !annotate)
+			opt.sign = 1;
 		create_tag(object, tag, &buf, &opt, prev, object);
+	}
 
 	transaction = ref_transaction_begin(&err);
 	if (!transaction ||
t/t7004-tag.sh +41 -0

47 lines not on this page · raw message

Signature · 1 line
2.7.0