Merge branch 'la/tag-force-signing-annotated-tags'
"git tag" can create an annotated tag without explicitly given an "-a" (or "-s") option (i.e. when a tag message is given). A new configuration variable, tag.forceSignAnnotated, can be used to tell the command to create signed tag in such a situation. * la/tag-force-signing-annotated-tags: tag: add the option to force signing of annotated tags
This commit is contained in:
commit
a2595f05c7
@ -2744,6 +2744,11 @@ submodule.fetchJobs::
|
|||||||
in parallel. A value of 0 will give some reasonable default.
|
in parallel. A value of 0 will give some reasonable default.
|
||||||
If unset, it defaults to 1.
|
If unset, it defaults to 1.
|
||||||
|
|
||||||
|
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::
|
tag.sort::
|
||||||
This variable controls the sort ordering of tags when displayed by
|
This variable controls the sort ordering of tags when displayed by
|
||||||
linkgit:git-tag[1]. Without the "--sort=<value>" option provided, the
|
linkgit:git-tag[1]. Without the "--sort=<value>" option provided, the
|
||||||
|
@ -29,6 +29,7 @@ static const char * const git_tag_usage[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static unsigned int colopts;
|
static unsigned int colopts;
|
||||||
|
static int force_sign_annotate;
|
||||||
|
|
||||||
static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting, const char *format)
|
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);
|
status = git_gpg_config(var, value, cb);
|
||||||
if (status)
|
if (status)
|
||||||
return status;
|
return status;
|
||||||
|
if (!strcmp(var, "tag.forcesignannotated")) {
|
||||||
|
force_sign_annotate = git_config_bool(var, value);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (starts_with(var, "column."))
|
if (starts_with(var, "column."))
|
||||||
return git_column_config(var, value, "tag", &colopts);
|
return git_column_config(var, value, "tag", &colopts);
|
||||||
return git_default_config(var, value, cb);
|
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;
|
char *cleanup_arg = NULL;
|
||||||
int create_reflog = 0;
|
int create_reflog = 0;
|
||||||
int annotate = 0, force = 0;
|
int annotate = 0, force = 0;
|
||||||
int cmdmode = 0;
|
int cmdmode = 0, create_tag_object = 0;
|
||||||
const char *msgfile = NULL, *keyid = NULL;
|
const char *msgfile = NULL, *keyid = NULL;
|
||||||
struct msg_arg msg = { 0, STRBUF_INIT };
|
struct msg_arg msg = { 0, STRBUF_INIT };
|
||||||
struct ref_transaction *transaction;
|
struct ref_transaction *transaction;
|
||||||
@ -385,12 +391,12 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
|
|||||||
opt.sign = 1;
|
opt.sign = 1;
|
||||||
set_signing_key(keyid);
|
set_signing_key(keyid);
|
||||||
}
|
}
|
||||||
if (opt.sign)
|
create_tag_object = (opt.sign || annotate || msg.given || msgfile);
|
||||||
annotate = 1;
|
|
||||||
if (argc == 0 && !cmdmode)
|
if (argc == 0 && !cmdmode)
|
||||||
cmdmode = 'l';
|
cmdmode = 'l';
|
||||||
|
|
||||||
if ((annotate || msg.given || msgfile || force) && (cmdmode != 0))
|
if ((create_tag_object || force) && (cmdmode != 0))
|
||||||
usage_with_options(git_tag_usage, options);
|
usage_with_options(git_tag_usage, options);
|
||||||
|
|
||||||
finalize_colopts(&colopts, -1);
|
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) {
|
||||||
if (msg.given && msgfile)
|
if (msg.given && msgfile)
|
||||||
die(_("only one -F or -m option is allowed."));
|
die(_("only one -F or -m option is allowed."));
|
||||||
annotate = 1;
|
|
||||||
if (msg.given)
|
if (msg.given)
|
||||||
strbuf_addbuf(&buf, &(msg.buf));
|
strbuf_addbuf(&buf, &(msg.buf));
|
||||||
else {
|
else {
|
||||||
@ -474,8 +479,11 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
|
|||||||
else
|
else
|
||||||
die(_("Invalid cleanup mode %s"), cleanup_arg);
|
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);
|
create_tag(object, tag, &buf, &opt, prev, object);
|
||||||
|
}
|
||||||
|
|
||||||
transaction = ref_transaction_begin(&err);
|
transaction = ref_transaction_begin(&err);
|
||||||
if (!transaction ||
|
if (!transaction ||
|
||||||
|
@ -775,6 +775,47 @@ test_expect_success GPG '-s implies annotated tag' '
|
|||||||
test_cmp expect actual
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
get_tag_header forcesignannotated-implied-sign $commit commit $time >expect
|
||||||
|
echo "A message" >>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 tag -m "A message" forcesignannotated-implied-sign &&
|
||||||
|
get_tag_msg forcesignannotated-implied-sign >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success GPG \
|
||||||
|
'lightweight with no message when configured with tag.forcesignannotated' \
|
||||||
|
'test_config tag.forcesignannotated true &&
|
||||||
|
git tag forcesignannotated-lightweight &&
|
||||||
|
tag_exists forcesignannotated-lightweight &&
|
||||||
|
test_must_fail git tag -v forcesignannotated-no-message
|
||||||
|
'
|
||||||
|
|
||||||
|
get_tag_header forcesignannotated-annotate $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" forcesignannotated-annotate &&
|
||||||
|
get_tag_msg forcesignannotated-annotate >actual &&
|
||||||
|
test_cmp expect actual &&
|
||||||
|
test_must_fail git tag -v forcesignannotated-annotate
|
||||||
|
'
|
||||||
|
|
||||||
|
get_tag_header forcesignannotated-disabled $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" forcesignannotated-disabled &&
|
||||||
|
get_tag_msg forcesignannotated-disabled >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success GPG \
|
test_expect_success GPG \
|
||||||
'trying to create a signed tag with non-existing -F file should fail' '
|
'trying to create a signed tag with non-existing -F file should fail' '
|
||||||
! test -f nonexistingfile &&
|
! test -f nonexistingfile &&
|
||||||
|
Loading…
Reference in New Issue
Block a user