This patch allows people to set `commit.verbose` to implicitly send `--verbose`
to `git commit`. It also introduces `--no-verbose` to override the configuration
setting.

Caleb Thompson

From aa2a5d48e6cd53082613f53990bc9d0fa60809f4 Mon Sep 17 00:00:00 2001
From: Caleb Thompson <ca...@calebthompson.io>
Date: Fri, 23 May 2014 11:47:44 -0500
Subject: [PATCH] commit: support commit.verbose and --no-verbose

Add a new configuration variable commit.verbose to implicitly pass
`--verbose` to `git-commit`. Add `--no-verbose` to commit to negate that
setting.

Signed-off-by: Caleb Thompson <ca...@calebthompson.io>
---
 Documentation/config.txt               |  5 +++++
 Documentation/git-commit.txt           |  9 ++++++++-
 builtin/commit.c                       |  6 +++++-
 contrib/completion/git-completion.bash |  1 +
 t/t7507-commit-verbose.sh              | 21 +++++++++++++++++++++
 5 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 1932e9b..a245928 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1009,6 +1009,11 @@ commit.template::
        "`~/`" is expanded to the value of `$HOME` and "`~user/`" to the
        specified user's home directory.
 
+commit.verbose::
+       A boolean to enable/disable inclusion of diff information in the
+       commit message template when using an editor to prepare the commit
+       message.  Defaults to false.
+
 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 0bbc8f5..0e1f930 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -282,7 +282,14 @@ configuration variable documented in linkgit:git-config[1].
        Show unified diff between the HEAD commit and what
        would be committed at the bottom of the commit message
        template.  Note that this diff output doesn't have its
-       lines prefixed with '#'.
+       lines prefixed with '#'.  The `commit.verbose` configuration
+       variable can be set to true to implicitly send this option.
+
+-V::
+--no-verbose::
+       Do not show the unified diff  at the bottom of the commit message
+       template.  This is the default behavior, but can be used to override
+       the`commit.verbose` configuration variable.
 
 -q::
 --quiet::
diff --git a/builtin/commit.c b/builtin/commit.c
index 9cfef6c..7978d7f 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1417,6 +1417,10 @@ static int git_commit_config(const char *k, const char 
*v, void *cb)
                sign_commit = git_config_bool(k, v) ? "" : NULL;
                return 0;
        }
+       if (!strcmp(k, "commit.verbose")) {
+               verbose = git_config_bool(k, v);
+               return 0;
+       }
 
        status = git_gpg_config(k, v, NULL);
        if (status)
@@ -1484,7 +1488,7 @@ int cmd_commit(int argc, const char **argv, const char 
*prefix)
        static struct wt_status s;
        static struct option builtin_commit_options[] = {
                OPT__QUIET(&quiet, N_("suppress summary after successful 
commit")),
-               OPT__VERBOSE(&verbose, N_("show diff in commit message 
template")),
+               OPT_BOOL('v', "verbose", &verbose, N_("show diff in commit 
message template")),
 
                OPT_GROUP(N_("Commit message options")),
                OPT_FILENAME('F', "file", &logfile, N_("read message from 
file")),
diff --git a/contrib/completion/git-completion.bash 
b/contrib/completion/git-completion.bash
index 2c59a76..b8f4b94 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1976,6 +1976,7 @@ _git_config ()
                color.ui
                commit.status
                commit.template
+               commit.verbose
                core.abbrev
                core.askpass
                core.attributesfile
diff --git a/t/t7507-commit-verbose.sh b/t/t7507-commit-verbose.sh
index 2ddf28c..53f68ff 100755
--- a/t/t7507-commit-verbose.sh
+++ b/t/t7507-commit-verbose.sh
@@ -10,6 +10,12 @@ EOF
 chmod +x check-for-diff
 test_set_editor "$PWD/check-for-diff"
 
+cat >check-for-no-diff <<EOF
+#!$SHELL_PATH
+exec grep -v '^diff --git' "\$1"
+EOF
+chmod +x check-for-no-diff
+
 cat >message <<'EOF'
 subject
 
@@ -48,6 +54,21 @@ test_expect_success 'verbose diff is stripped out 
(mnemonicprefix)' '
        check_message message
 '
 
+test_expect_success 'commit shows verbose diff with set commit.verbose' '
+       echo morecontent >file &&
+       git add file &&
+       git config commit.verbose true &&
+       check_message message
+'
+
+test_expect_success 'commit does not show verbose diff with --no-verbose' '
+       echo morecontent >file &&
+       git add file &&
+       git config commit.verbose true &&
+       test_set_editor "$PWD/check-for-no-diff" &&
+       git commit --amend --no-verbose
+'
+
 cat >diff <<'EOF'
 This is an example commit message that contains a diff.
 
-- 
1.9.3

Attachment: pgp677yOblyfg.pgp
Description: PGP signature

Reply via email to