threads / patch / 41654

patchadd a commit.verbose config variable

Subject: [PATCH] add a commit.verbose config variable

## tl;dr

3 messages between Mar 9, 2016 and Mar 9, 2016. Diffs are folded; open one to read it.

replies: 2people: 2as markdown or json

Pranit Bauva· Mar 9, 2016, 18:49 UTC · lore

Since many people always run the command with this option, and would prefer not to use the argument again and again but instead specify it in the configuration file.

Also add a override-verbose option in git-commit if no verbose is required when the commit.verbose is true in the configuration file.

Signed-off-by: Pranit Bauva <pranit.bauva@gmail.com>
---
 Documentation/config.txt     | 4 ++++
 Documentation/git-commit.txt | 7 ++++++-
 builtin/commit.c             | 7 +++++++
 3 files changed, 17 insertions(+), 1 deletion(-)
Show changes to 3 files +17 −2

Documentation/config.txt, Documentation/git-commit.txt, builtin/commit.c

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 01cca0a..cf2f48b 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1110,6 +1110,10 @@ commit.template::
 	"`~/`" is expanded to the value of `$HOME` and "`~user/`" to the
 	specified user's home directory.
 
+commit.verbose::
+	A boolean to specify whether to always include the verbose option
+	with `git commit`. See linkgit:git-commit[1]
+
 credential.helper::
 	Specify an external helper to be called when a username or
 	password credential is needed; the helper may consult external
diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
index 9ec6b3c..0972b45 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -290,12 +290,17 @@ configuration variable documented in linkgit:git-config[1].
 	what changes the commit has.
 	Note that this diff output doesn't have its
 	lines prefixed with '#'. This diff will not be a part
-	of the commit message.
+	of the commit message. To activate this option permanently, the
+	configuration variable `commit.verbose` can be set to true.
 +
 If specified twice, show in addition the unified diff between
 what would be committed and the worktree files, i.e. the unstaged
 changes to tracked files.
 
+--override-verbose::
+	Disable verbose for the commit if you have activated it
+	permanently in the configuration variable `commit.verbose`.
+
 -q::
 --quiet::
 	Suppress commit summary message.
diff --git a/builtin/commit.c b/builtin/commit.c
index b3bd2d4..0577968 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -114,6 +114,7 @@ static char *fixup_message, *squash_message;
 static int all, also, interactive, patch_interactive, only, amend, signoff;
 static int edit_flag = -1; /* unspecified */
 static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship;
+static int override_verbose;
 static int no_post_rewrite, allow_empty_message;
 static char *untracked_files_arg, *force_date, *ignore_submodule_arg;
 static char *sign_commit;
@@ -1590,6 +1591,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 		OPT_BOOL('e', "edit", &edit_flag, N_("force edit of commit")),
 		OPT_STRING(0, "cleanup", &cleanup_arg, N_("default"), N_("how to strip spaces and #comments from message")),
 		OPT_BOOL(0, "status", &include_status, N_("include status in commit message template")),
+		OPT_BOOL(0, "override-verbose", &override_verbose, N_("override the verbose setting in configuration file")),
 		{ OPTION_STRING, 'S', "gpg-sign", &sign_commit, N_("key-id"),
 		  N_("GPG sign commit"), PARSE_OPT_OPTARG, NULL, (intptr_t) "" },
 		/* end commit message options */
@@ -1654,6 +1656,11 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 	argc = parse_and_validate_options(argc, argv, builtin_commit_options,
 					  builtin_commit_usage,
 					  prefix, current_head, &s);
+
+	if( !override_verbose )
+		if( !verbose )
+			git_config_get_bool("commit.verbose", &verbose);
+
 	if (dry_run)
 		return dry_run_commit(argc, argv, prefix, current_head, &s);
 	index_file = prepare_index(argc, argv, prefix, current_head, 0);

--
https://github.com/git/git/pull/204
Pranit Bauva· Mar 9, 2016, 20:32 UTC · re: Pranit Bauva · lore

Re: [PATCH] add a commit.verbose config variable

A previous version of this patch can be found at http://news.gmane.org/gmane.comp.version-control.git/287540 .

The changes in the patch are :-
 - Fix typo "git config" to "git commit"
 - Use a better commit message
 - Drop a paragraph in commit message so as to not misguide readers
 - Consider additional tests as suggested by Eric Sunshine
 - Add an option "override-verbose" to git commit to override the
"always true" setting if set in the configuration file

It took me quite some time to send this patch. I was trying to write tests for this and send the patch together but I could not find the test examples that could be used from the existing code base. If someone has an idea in mind then I could probably write the tests. Though I have tested this personally for all the cases but I think it would be preferable to automate the job.

Regards, Pranit Bauva IIT Kharagpur

Matthieu Moy· Mar 9, 2016, 21:21 UTC · re: Pranit Bauva · lore

Re: [PATCH] add a commit.verbose config variable

Hi,

This is v2, right? Then call it [PATCH v2] in the title, and summarize the diff wrt v1. As much as possible, Cc people who participated in the review of v1.

Pranit Bauva <pranit.bauva@gmail.com> writes:
> Since many people always run the command with this option, and would
> prefer not to use the argument again and again but instead specify it in
> the configuration file.

"Since ... and ..." calls for a verb to end the sentence (already noted by Eric with v1).

> +commit.verbose::
> +	A boolean to specify whether to always include the verbose option
> +	with `git commit`. See linkgit:git-commit[1]

Either say "See linkgit:git-commit[1]" between parenthesis, or add a period (.) at the end of the sentence.

> +--override-verbose::
> +	Disable verbose for the commit if you have activated it
> +	permanently in the configuration variable `commit.verbose`.

The convention is to call this --no-verbose. --override-verbose is not a good name for such option.

Look how other similar cases are managed (e.g. status.short, status.branch, am.threeway)

Show 7 quoted lines
> @@ -1654,6 +1656,11 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
>  	argc = parse_and_validate_options(argc, argv, builtin_commit_options,
>  					  builtin_commit_usage,
>  					  prefix, current_head, &s);
> +
> +	if( !override_verbose )
> +		if( !verbose )
Style: spaces between if and (, but not inside ( ).
> +			git_config_get_bool("commit.verbose", &verbose);

This is a strange way to write the "cli takes precedence over config". The usual way is to read from least precedence to highest precedence, i.e. git_config_get_bool before calling parse_option.

You dropped the "RFC" tag from the subject line, but your patch still lacks a test. It cannot be called final without.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

← back to recent threads