From aefc81ad38b3a6fc88a0e8db6fafe75692f0d4b3 Mon Sep 17 00:00:00 2001 From: Mehul Jain Date: Fri, 24 Jun 2016 19:42:34 +0530 Subject: [PATCH 1/3] t4202: refactor test Subsequent patches will want to reuse the 'signed' branch that the 'log --graph --show-signature' test creates and uses. Split the set-up part into a test of its own, and make the existing test into a separate one that only inspects the history on the 'signed' branch. This way, it becomes clearer that tests added by subsequent patches reuse the 'signed' branch in the same way. Signed-off-by: Mehul Jain Signed-off-by: Junio C Hamano --- t/t4202-log.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/t/t4202-log.sh b/t/t4202-log.sh index 128ba93537..b3d618c43d 100755 --- a/t/t4202-log.sh +++ b/t/t4202-log.sh @@ -860,12 +860,15 @@ test_expect_success 'dotdot is a parent directory' ' test_cmp expect actual ' -test_expect_success GPG 'log --graph --show-signature' ' +test_expect_success GPG 'setup signed branch' ' test_when_finished "git reset --hard && git checkout master" && git checkout -b signed master && echo foo >foo && git add foo && - git commit -S -m signed_commit && + git commit -S -m signed_commit +' + +test_expect_success GPG 'log --graph --show-signature' ' git log --graph --show-signature -n1 signed >actual && grep "^| gpg: Signature made" actual && grep "^| gpg: Good signature" actual From aa3799996c310da756c7845950def4f6d51cccf3 Mon Sep 17 00:00:00 2001 From: Mehul Jain Date: Wed, 22 Jun 2016 22:21:25 +0530 Subject: [PATCH 2/3] log: add "--no-show-signature" command line option If an user creates an alias with "--show-signature" early in command line, e.g. [alias] logss = log --show-signature then there is no way to countermand it through command line. Teach git-log and related commands about "--no-show-signature" command line option. This will make "git logss --no-show-signature" run without showing GPG signature. Signed-off-by: Mehul Jain Signed-off-by: Junio C Hamano --- revision.c | 2 ++ t/t4202-log.sh | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/revision.c b/revision.c index d30d1c4f80..3546ff9c1b 100644 --- a/revision.c +++ b/revision.c @@ -1871,6 +1871,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg revs->notes_opt.use_default_notes = 1; } else if (!strcmp(arg, "--show-signature")) { revs->show_signature = 1; + } else if (!strcmp(arg, "--no-show-signature")) { + revs->show_signature = 0; } else if (!strcmp(arg, "--show-linear-break") || starts_with(arg, "--show-linear-break=")) { if (starts_with(arg, "--show-linear-break=")) diff --git a/t/t4202-log.sh b/t/t4202-log.sh index b3d618c43d..449a5275d4 100755 --- a/t/t4202-log.sh +++ b/t/t4202-log.sh @@ -893,6 +893,11 @@ test_expect_success GPG 'log --graph --show-signature for merged tag' ' grep "^| | gpg: Good signature" actual ' +test_expect_success GPG '--no-show-signature overrides --show-signature' ' + git log -1 --show-signature --no-show-signature signed >actual && + ! grep "^gpg:" actual +' + test_expect_success 'log --graph --no-walk is forbidden' ' test_must_fail git log --graph --no-walk ' From fce04c3ca695d32c1b3c59e1bfc1fb4019025c72 Mon Sep 17 00:00:00 2001 From: Mehul Jain Date: Wed, 22 Jun 2016 22:21:26 +0530 Subject: [PATCH 3/3] log: add log.showSignature configuration variable Users may want to always use "--show-signature" while using git-log and related commands. When log.showSignature is set to true, git-log and related commands will behave as if "--show-signature" was given to them. Note that this config variable is meant to affect git-log, git-show, git-whatchanged and git-reflog. Other commands like git-format-patch, git-rev-list are not to be affected by this config variable. Signed-off-by: Mehul Jain Signed-off-by: Junio C Hamano --- Documentation/git-log.txt | 4 ++++ builtin/log.c | 6 ++++++ t/t4202-log.sh | 20 ++++++++++++++++++++ t/t7510-signed-commit.sh | 7 +++++++ 4 files changed, 37 insertions(+) diff --git a/Documentation/git-log.txt b/Documentation/git-log.txt index dec379b3e2..3995324024 100644 --- a/Documentation/git-log.txt +++ b/Documentation/git-log.txt @@ -198,6 +198,10 @@ log.showRoot:: `git log -p` output would be shown without a diff attached. The default is `true`. +log.showSignature:: + If `true`, `git log` and related commands will act as if the + `--show-signature` option was passed to them. + mailmap.*:: See linkgit:git-shortlog[1]. diff --git a/builtin/log.c b/builtin/log.c index 099f4f7be9..7103217505 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -33,6 +33,7 @@ static const char *default_date_mode = NULL; static int default_abbrev_commit; static int default_show_root = 1; static int default_follow; +static int default_show_signature; static int decoration_style; static int decoration_given; static int use_mailmap_config; @@ -119,6 +120,7 @@ static void cmd_log_init_defaults(struct rev_info *rev) rev->abbrev_commit = default_abbrev_commit; rev->show_root_diff = default_show_root; rev->subject_prefix = fmt_patch_subject_prefix; + rev->show_signature = default_show_signature; DIFF_OPT_SET(&rev->diffopt, ALLOW_TEXTCONV); if (default_date_mode) @@ -409,6 +411,10 @@ static int git_log_config(const char *var, const char *value, void *cb) use_mailmap_config = git_config_bool(var, value); return 0; } + if (!strcmp(var, "log.showsignature")) { + default_show_signature = git_config_bool(var, value); + return 0; + } if (grep_config(var, value, cb) < 0) return -1; diff --git a/t/t4202-log.sh b/t/t4202-log.sh index 449a5275d4..803e1e6b8f 100755 --- a/t/t4202-log.sh +++ b/t/t4202-log.sh @@ -898,6 +898,26 @@ test_expect_success GPG '--no-show-signature overrides --show-signature' ' ! grep "^gpg:" actual ' +test_expect_success GPG 'log.showsignature=true behaves like --show-signature' ' + test_config log.showsignature true && + git log -1 signed >actual && + grep "gpg: Signature made" actual && + grep "gpg: Good signature" actual +' + +test_expect_success GPG '--no-show-signature overrides log.showsignature=true' ' + test_config log.showsignature true && + git log -1 --no-show-signature signed >actual && + ! grep "^gpg:" actual +' + +test_expect_success GPG '--show-signature overrides log.showsignature=false' ' + test_config log.showsignature false && + git log -1 --show-signature signed >actual && + grep "gpg: Signature made" actual && + grep "gpg: Good signature" actual +' + test_expect_success 'log --graph --no-walk is forbidden' ' test_must_fail git log --graph --no-walk ' diff --git a/t/t7510-signed-commit.sh b/t/t7510-signed-commit.sh index 4177a8609a..6e839f5489 100755 --- a/t/t7510-signed-commit.sh +++ b/t/t7510-signed-commit.sh @@ -210,4 +210,11 @@ test_expect_success GPG 'show lack of signature with custom format' ' test_cmp expect actual ' +test_expect_success GPG 'log.showsignature behaves like --show-signature' ' + test_config log.showsignature true && + git show initial >actual && + grep "gpg: Signature made" actual && + grep "gpg: Good signature" actual +' + test_done