]> git.ipfire.org Git - thirdparty/git.git/commitdiff
merge/pull: extend merge.stat configuration variable to cover --compact-summary
authorJunio C Hamano <gitster@pobox.com>
Thu, 12 Jun 2025 22:25:37 +0000 (15:25 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 13 Jun 2025 18:54:14 +0000 (11:54 -0700)
Existing `merge.stat` configuration variable is a Boolean that
defaults to `true` to control `git merge --[no-]stat` behaviour.

Extend it to be "Boolean or text", that takes false, true, or
"compact", with the last one triggering the --compact-summary option
introduced earlier.  Any other values are taken as the same as true,
instead of signaling an error---it is not a grave enough offence to
stop their merge.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/config/merge.adoc
builtin/merge.c
t/t7600-merge.sh

index 86359f6dd2d90449790b38838df79291d396f4d5..15a4c14c38aade08ebd4258363618ad432ccb2c0 100644 (file)
@@ -81,8 +81,18 @@ as `false`. Defaults to `conflict`.
        attributes" in linkgit:gitattributes[5].
 
 `merge.stat`::
-       Whether to print the diffstat between `ORIG_HEAD` and the merge result
-       at the end of the merge.  True by default.
+       What, if anything, to print between `ORIG_HEAD` and the merge result
+       at the end of the merge.  Possible values are:
++
+--
+`false`;; Show nothing.
+`true`;; Show `git diff --diffstat --summary ORIG_HEAD`.
+`compact`;; Show `git diff --compact-summary ORIG_HEAD`.
+--
++
+but any unrecognised value (e.g., a value added by a future version of
+Git) is taken as `true` instead of triggering an error.  Defaults to
+`true`.
 
 `merge.autoStash`::
        When set to `true`, automatically create a temporary stash entry
index 3a6ece14af6a53f5f41c16f31c24ed3d37e4a255..18b22c0a26d6337a7c68075326c2367f5cfe5986 100644 (file)
@@ -673,8 +673,35 @@ static int git_merge_config(const char *k, const char *v,
        }
 
        if (!strcmp(k, "merge.diffstat") || !strcmp(k, "merge.stat")) {
-               show_diffstat = git_config_bool(k, v)
-                       ? MERGE_SHOW_DIFFSTAT : 0;
+               int val = git_parse_maybe_bool_text(v);
+               switch (val) {
+               case 0:
+                       show_diffstat = 0;
+                       break;
+               case 1:
+                       show_diffstat = MERGE_SHOW_DIFFSTAT;
+                       break;
+               default:
+                       if (!strcmp(v, "compact"))
+                               show_diffstat = MERGE_SHOW_COMPACTSUMMARY;
+                       /*
+                        * We do not need to have an explicit
+                        *
+                        * else if (!strcmp(v, "diffstat"))
+                        *      show_diffstat = MERGE_SHOW_DIFFSTAT;
+                        *
+                        * here, because the catch-all uses the
+                        * diffstat style anyway.
+                        */
+                       else
+                               /*
+                                * A setting from a future?  It is not an
+                                * error grave enough to fail the command.
+                                * proceed using the default one.
+                                */
+                               show_diffstat = MERGE_SHOW_DIFFSTAT;
+                       break;
+               }
        } else if (!strcmp(k, "merge.verifysignatures")) {
                verify_signatures = git_config_bool(k, v);
        } else if (!strcmp(k, "pull.twohead")) {
index 2972922b6a2208e4de0be03ef61ba148166ad959..9838094b66ac393e550eaabba7201ff987028a98 100755 (executable)
@@ -216,6 +216,37 @@ test_expect_success 'merge c0 with c1 with --ff-only' '
        verify_head "$c1"
 '
 
+test_expect_success 'the same merge with merge.stat=diffstat' '
+       cat >expect <<-\EOF &&
+       Updating FROM..TO
+       Fast-forward
+        file  | 2 +-
+        other | 9 +++++++++
+        2 files changed, 10 insertions(+), 1 deletion(-)
+        create mode 100644 other
+       EOF
+
+       git reset --hard c0 &&
+       git -c merge.stat=diffstat merge c1 >out &&
+       sed -e "1s/^Updating [0-9a-f.]*/Updating FROM..TO/" out >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'the same merge with compact summary' '
+       cat >expect <<-\EOF &&
+       Updating FROM..TO
+       Fast-forward
+        file        | 2 +-
+        other (new) | 9 +++++++++
+        2 files changed, 10 insertions(+), 1 deletion(-)
+       EOF
+
+       git reset --hard c0 &&
+       git merge --compact-summary c1 >out &&
+       sed -e "1s/^Updating [0-9a-f.]*/Updating FROM..TO/" out >actual &&
+       test_cmp expect actual
+'
+
 test_expect_success 'the same merge with compact summary' '
        cat >expect <<-\EOF &&
        Updating FROM..TO
@@ -231,6 +262,21 @@ test_expect_success 'the same merge with compact summary' '
        test_cmp expect actual
 '
 
+test_expect_success 'the same merge with merge.stat=compact' '
+       cat >expect <<-\EOF &&
+       Updating FROM..TO
+       Fast-forward
+        file        | 2 +-
+        other (new) | 9 +++++++++
+        2 files changed, 10 insertions(+), 1 deletion(-)
+       EOF
+
+       git reset --hard c0 &&
+       git -c merge.stat=compact merge c1 >out &&
+       sed -e "1s/^Updating [0-9a-f.]*/Updating FROM..TO/" out >actual &&
+       test_cmp expect actual
+'
+
 test_debug 'git log --graph --decorate --oneline --all'
 
 test_expect_success 'merge from unborn branch' '