threads / patch / 42650

v2, 2 partsIntroduce log.showSignature config variable

Subject: [PATCH v2 0/2] Introduce log.showSignature config variable

## tl;dr

5 messages between Jun 18, 2016 and Jun 19, 2016. Diffs are folded; open one to read it.

replies: 4people: 2as markdown or json

Mehul Jain· Jun 18, 2016, 12:25 UTC · lore

Add a new configuratation variable "log.showSignature" for git-log and related commands. "log.showSignature=true" will enable user to see GPG signature by default for git-log and related commands.

Changes:
	* Order of patches is reversed as suggested by Junio[1].
	* A new test has been introduced for "--no-show-signature"
	  option.
Previous patch: http://thread.gmane.org/gmane.comp.version-control.git/296474
[1]: http://thread.gmane.org/gmane.comp.version-control.git/296474/focus=296476
Mehul Jain (2):
  log: add "--no-show-signature" command line option
  log: add log.showSignature configuration variable
 Documentation/git-log.txt |  4 ++++
 builtin/log.c             |  6 ++++++
 revision.c                |  2 ++
 t/t4202-log.sh            | 35 +++++++++++++++++++++++++++++++++++
 t/t7510-signed-commit.sh  |  7 +++++++
 5 files changed, 54 insertions(+)
-- 
2.9.0.rc0.dirty
Mehul Jain· Jun 18, 2016, 12:25 UTC · re: Mehul Jain · lore

[PATCH v2 2/2] 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 <mehul.jain2029@gmail.com>
---
 Documentation/git-log.txt |  4 ++++
 builtin/log.c             |  6 ++++++
 t/t4202-log.sh            | 25 +++++++++++++++++++++++++
 t/t7510-signed-commit.sh  |  7 +++++++
 4 files changed, 42 insertions(+)
Show changes to 4 files +42 −0

Documentation/git-log.txt, builtin/log.c, t/t4202-log.sh, t/t7510-signed-commit.sh

diff --git a/Documentation/git-log.txt b/Documentation/git-log.txt
index 03f9580..bbb5adc 100644
--- a/Documentation/git-log.txt
+++ b/Documentation/git-log.txt
@@ -196,6 +196,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 099f4f7..7103217 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 02384a3..63ed863 100755
--- a/t/t4202-log.sh
+++ b/t/t4202-log.sh
@@ -900,6 +900,31 @@ test_expect_success GPG '--no-show-signature overrides --show-signature' '
 	! grep "^gpg:" actual
 '
 
+test_expect_success GPG 'log.showsignature=true behaves like --show-signature' '
+	git checkout -b test_sign master &&
+	echo foo >foo &&
+	git add foo &&
+	git commit -S -m signed_commit &&
+	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_when_finished "git reset --hard && git checkout master" &&
+	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 4177a86..6e839f5 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
-- 
2.9.0.rc0.dirty
Eric Sunshine· Jun 19, 2016, 06:59 UTC · re: Mehul Jain · lore

Re: [PATCH v2 2/2] log: add log.showSignature configuration variable

On Sat, Jun 18, 2016 at 8:25 AM, Mehul Jain <mehul.jain2029@gmail.com> wrote:
Show 16 quoted lines
> 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 <mehul.jain2029@gmail.com>
> ---
> diff --git a/t/t4202-log.sh b/t/t4202-log.sh
> @@ -900,6 +900,31 @@ test_expect_success GPG '--no-show-signature overrides --show-signature' '
> +test_expect_success GPG 'log.showsignature=true behaves like --show-signature' '
> +       git checkout -b test_sign master &&

It appears that you copied the bulk of this test from the 'log --graph --show-signature' test and changed it to create a new branch named 'test_sign' rather than 'signed', however...

Show 5 quoted lines
> +       echo foo >foo &&
> +       git add foo &&
> +       git commit -S -m signed_commit &&
> +       test_config log.showsignature true &&
> +       git log -1 signed >actual &&

... you're incorrectly testing against the 'signed' branch rather than the 'test_sign' created specifically for this test.

Show 12 quoted lines
> +       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_when_finished "git reset --hard && git checkout master" &&

So, in the first of these three new tests, you're setting up some state by creating and checking out a new branch named 'test_sign', and leaving that branch checked out while these three tests run, and finally use test_when_finished() in the last of the three tests to restore sanity (by returning to the 'master' branch) when that test exits.

This is ugly and couples these three tests too tightly. It would be better to make each test more self-contained, not relying upon state left over from previous tests.

Show 5 quoted lines
> +       test_config log.showsignature false &&
> +       git log -1 --show-signature signed >actual &&
> +       grep "gpg: Signature made" actual &&
> +       grep "gpg: Good signature" actual
> +'

In fact, the original 'log --graph --show-signature' test which created the 'signed' branch, the new --no-show-signature test added in patch 1/2, and the three new tests here could all just work against the same 'signed' branch. There is no need to create a new 'test_sign' branch for these three tests, or a 'nosign' branch for the patch 1/2 test.

Therefore, it probably would make more sense to add a new distinct 'setup signed' test (or just enhance the existing 'setup' test) which creates the 'signed' branch and update the original 'log --graph --show-signature' to take advantage of it, as well as each of the new tests introduced by this patch series. And since each test would mention 'signed' explicitly in its git-log invocation, there's no need to leave that branch checked out, so the setup test itself only needs test_when_finished() to ensure that the current branch is restored to 'master'.

Mehul Jain· Jun 19, 2016, 11:30 UTC · re: Eric Sunshine · lore

Re: [PATCH v2 2/2] log: add log.showSignature configuration variable

Hi Eric,
Thanks for your review.
On Sun, Jun 19, 2016 at 12:29 PM, Eric Sunshine <sunshine@sunshineco.com> wrote:
Show 18 quoted lines
> On Sat, Jun 18, 2016 at 8:25 AM, Mehul Jain <mehul.jain2029@gmail.com> wrote:
>> diff --git a/t/t4202-log.sh b/t/t4202-log.sh
>> @@ -900,6 +900,31 @@ test_expect_success GPG '--no-show-signature overrides --show-signature' '
>> +test_expect_success GPG 'log.showsignature=true behaves like --show-signature' '
>> +       git checkout -b test_sign master &&
>
> It appears that you copied the bulk of this test from the 'log --graph
> --show-signature' test and changed it to create a new branch named
> 'test_sign' rather than 'signed', however...
>
>> +       echo foo >foo &&
>> +       git add foo &&
>> +       git commit -S -m signed_commit &&
>> +       test_config log.showsignature true &&
>> +       git log -1 signed >actual &&
>
> ... you're incorrectly testing against the 'signed' branch rather than
> the 'test_sign' created specifically for this test.
Yes, I made a mistake here.
Show 46 quoted lines
>> +       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_when_finished "git reset --hard && git checkout master" &&
>
> So, in the first of these three new tests, you're setting up some
> state by creating and checking out a new branch named 'test_sign', and
> leaving that branch checked out while these three tests run, and
> finally use test_when_finished() in the last of the three tests to
> restore sanity (by returning to the 'master' branch) when that test
> exits.
>
> This is ugly and couples these three tests too tightly. It would be
> better to make each test more self-contained, not relying upon state
> left over from previous tests.
>
>> +       test_config log.showsignature false &&
>> +       git log -1 --show-signature signed >actual &&
>> +       grep "gpg: Signature made" actual &&
>> +       grep "gpg: Good signature" actual
>> +'
>
> In fact, the original 'log --graph --show-signature' test which
> created the 'signed' branch, the new --no-show-signature test added in
> patch 1/2, and the three new tests here could all just work against
> the same 'signed' branch. There is no need to create a new 'test_sign'
> branch for these three tests, or a 'nosign' branch for the patch 1/2
> test.
>
> Therefore, it probably would make more sense to add a new distinct
> 'setup signed' test (or just enhance the existing 'setup' test) which
> creates the 'signed' branch and update the original 'log --graph
> --show-signature' to take advantage of it, as well as each of the new
> tests introduced by this patch series. And since each test would
> mention 'signed' explicitly in its git-log invocation, there's no need
> to leave that branch checked out, so the setup test itself only needs
> test_when_finished() to ensure that the current branch is restored to
> 'master'.

Adding a new test 'setup signed' will work, where I will create a new 'signed' branch and use that branch in new --no-show-signature test introduced in patch 1/2, and the three tests in current patch 2/2. Also by creating a preparatory patch for this series, I will modify the 'log --graph --show-signature' test, so that it can also take advantage of new 'setup signed' test.

Though I'm wondering if whether there is a need to create the new 'setup signed' test. In 'log --graph --show-signature' test, we already have the 'signed' branch, which could be used in the test introduced here. But this will couple the tests, 'log --graph ...' and new ones, tightly. Because if in future someone changes the 'log --graph ...' test, then there is a possibility of new tests (introduced in patch 1/2 and 2/2) to fail. So creating a new test for creation of 'signed' branch seems fair.

Thanks, Mehul

Mehul Jain· Jun 18, 2016, 12:25 UTC · re: Mehul Jain · lore

[PATCH v2 1/2] log: add "--no-show-signature" command line option

If an user creates an alias with "--show-signature" 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 <mehul.jain2029@gmail.com>
---
 revision.c     |  2 ++
 t/t4202-log.sh | 10 ++++++++++
 2 files changed, 12 insertions(+)
Show changes to 2 files +12 −0

revision.c, t/t4202-log.sh

diff --git a/revision.c b/revision.c
index d30d1c4..3546ff9 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 128ba93..02384a3 100755
--- a/t/t4202-log.sh
+++ b/t/t4202-log.sh
@@ -890,6 +890,16 @@ 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' '
+	test_when_finished "git reset --hard && git checkout master" &&
+	git checkout -b nosign master &&
+	echo foo >foo &&
+	git add foo &&
+	git commit -S -m signed_commit &&
+	git log -1 --show-signature --no-show-signature nosign >actual &&
+	! grep "^gpg:" actual
+'
+
 test_expect_success 'log --graph --no-walk is forbidden' '
 	test_must_fail git log --graph --no-walk
 '
-- 
2.9.0.rc0.dirty

← back to recent threads