merge/pull: extend merge.stat configuration variable to cover --compact-summary
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>
Junio C Hamano committed
Jun 12, 2025 at 15:25 UTC
c8b4805897aa12305389c76480e1d59c4696f2ac
3 files changed
+87
-4
Documentation/config/merge.adoc
+12
-2
@@ -81,8 +81,18 @@ as `false`. Defaults to `conflict`.
81
attributes" in linkgit:gitattributes[5].
82
83
`merge.stat`::
84
- Whether to print the diffstat between `ORIG_HEAD` and the merge result
85
- at the end of the merge. True by default.
84
+ What, if anything, to print between `ORIG_HEAD` and the merge result
85
+ at the end of the merge. Possible values are:
86
++
87
+--
88
+`false`;; Show nothing.
89
+`true`;; Show `git diff --diffstat --summary ORIG_HEAD`.
90
+`compact`;; Show `git diff --compact-summary ORIG_HEAD`.
91
+--
92
++
93
+but any unrecognised value (e.g., a value added by a future version of
94
+Git) is taken as `true` instead of triggering an error. Defaults to
95
+`true`.
96
97
`merge.autoStash`::
98
When set to `true`, automatically create a temporary stash entry
builtin/merge.c
+29
-2
@@ -673,8 +673,35 @@ static int git_merge_config(const char *k, const char *v,
673
}
674
675
if (!strcmp(k, "merge.diffstat") || !strcmp(k, "merge.stat")) {
676
- show_diffstat = git_config_bool(k, v)
677
- ? MERGE_SHOW_DIFFSTAT : 0;
676
+ int val = git_parse_maybe_bool_text(v);
677
+ switch (val) {
678
+ case 0:
679
+ show_diffstat = 0;
680
+ break;
681
+ case 1:
682
+ show_diffstat = MERGE_SHOW_DIFFSTAT;
683
+ break;
684
+ default:
685
+ if (!strcmp(v, "compact"))
686
+ show_diffstat = MERGE_SHOW_COMPACTSUMMARY;
687
+ /*
688
+ * We do not need to have an explicit
689
+ *
690
+ * else if (!strcmp(v, "diffstat"))
691
+ * show_diffstat = MERGE_SHOW_DIFFSTAT;
692
+ *
693
+ * here, because the catch-all uses the
694
+ * diffstat style anyway.
695
+ */
696
+ else
697
+ /*
698
+ * A setting from a future? It is not an
699
+ * error grave enough to fail the command.
700
+ * proceed using the default one.
701
+ */
702
+ show_diffstat = MERGE_SHOW_DIFFSTAT;
703
+ break;
704
+ }
705
} else if (!strcmp(k, "merge.verifysignatures")) {
706
verify_signatures = git_config_bool(k, v);
707
} else if (!strcmp(k, "pull.twohead")) {
t/t7600-merge.sh
+46
@@ -216,6 +216,37 @@ test_expect_success 'merge c0 with c1 with --ff-only' '
216
verify_head "$c1"
217
'
218
219
+test_expect_success 'the same merge with merge.stat=diffstat' '
220
+ cat >expect <<-\EOF &&
221
+ Updating FROM..TO
222
+ Fast-forward
223
+ file | 2 +-
224
+ other | 9 +++++++++
225
+ 2 files changed, 10 insertions(+), 1 deletion(-)
226
+ create mode 100644 other
227
+ EOF
228
+
229
+ git reset --hard c0 &&
230
+ git -c merge.stat=diffstat merge c1 >out &&
231
+ sed -e "1s/^Updating [0-9a-f.]*/Updating FROM..TO/" out >actual &&
232
+ test_cmp expect actual
233
+'
234
+
235
+test_expect_success 'the same merge with compact summary' '
236
+ cat >expect <<-\EOF &&
237
+ Updating FROM..TO
238
+ Fast-forward
239
+ file | 2 +-
240
+ other (new) | 9 +++++++++
241
+ 2 files changed, 10 insertions(+), 1 deletion(-)
242
+ EOF
243
+
244
+ git reset --hard c0 &&
245
+ git merge --compact-summary c1 >out &&
246
+ sed -e "1s/^Updating [0-9a-f.]*/Updating FROM..TO/" out >actual &&
247
+ test_cmp expect actual
248
+'
249
+
250
test_expect_success 'the same merge with compact summary' '
251
cat >expect <<-\EOF &&
252
Updating FROM..TO
@@ -231,6 +262,21 @@ test_expect_success 'the same merge with compact summary' '
262
test_cmp expect actual
263
'
264
265
+test_expect_success 'the same merge with merge.stat=compact' '
266
+ cat >expect <<-\EOF &&
267
+ Updating FROM..TO
268
+ Fast-forward
269
+ file | 2 +-
270
+ other (new) | 9 +++++++++
271
+ 2 files changed, 10 insertions(+), 1 deletion(-)
272
+ EOF
273
+
274
+ git reset --hard c0 &&
275
+ git -c merge.stat=compact merge c1 >out &&
276
+ sed -e "1s/^Updating [0-9a-f.]*/Updating FROM..TO/" out >actual &&
277
+ test_cmp expect actual
278
+'
279
+
280
test_debug 'git log --graph --decorate --oneline --all'
281
282
test_expect_success 'merge from unborn branch' '