Skip to content

Commit c8b4805

Browse files
committed
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 <[email protected]>
1 parent 3a54f5b commit c8b4805

File tree

3 files changed

+87
-4
lines changed

3 files changed

+87
-4
lines changed

Documentation/config/merge.adoc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,18 @@ as `false`. Defaults to `conflict`.
8181
attributes" in linkgit:gitattributes[5].
8282

8383
`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`.
8696

8797
`merge.autoStash`::
8898
When set to `true`, automatically create a temporary stash entry

builtin/merge.c

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,8 +673,35 @@ static int git_merge_config(const char *k, const char *v,
673673
}
674674

675675
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+
}
678705
} else if (!strcmp(k, "merge.verifysignatures")) {
679706
verify_signatures = git_config_bool(k, v);
680707
} else if (!strcmp(k, "pull.twohead")) {

t/t7600-merge.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,37 @@ test_expect_success 'merge c0 with c1 with --ff-only' '
216216
verify_head "$c1"
217217
'
218218

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+
219250
test_expect_success 'the same merge with compact summary' '
220251
cat >expect <<-\EOF &&
221252
Updating FROM..TO
@@ -231,6 +262,21 @@ test_expect_success 'the same merge with compact summary' '
231262
test_cmp expect actual
232263
'
233264

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+
234280
test_debug 'git log --graph --decorate --oneline --all'
235281

236282
test_expect_success 'merge from unborn branch' '

0 commit comments

Comments
 (0)