Skip to content

Commit 6e6029a

Browse files
committed
fmt-merge-msg: allow merge destination to be omitted again
In Git 2.28, we stopped special casing 'master' when producing the default merge message by just removing the code to squelch "into 'master'" at the end of the message. Introduce multi-valued merge.suppressDest configuration variable that gives a set of globs to match against the name of the branch into which the merge is being made, to let users specify for which branch fmt-merge-msg's output should be shortened. When it is not set, 'master' is used as the sole value of the variable by default. The above move mostly reverts the pre-2.28 default in repositories that have no relevant configuration. Add a few tests to protect the behaviour with the new configuration variable from future regression. Helped-by: Linus Torvalds <[email protected]> Helped-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2153192 commit 6e6029a

File tree

3 files changed

+66
-4
lines changed

3 files changed

+66
-4
lines changed

Documentation/config/fmt-merge-msg.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,15 @@ merge.log::
88
most the specified number of one-line descriptions from the
99
actual commits that are being merged. Defaults to false, and
1010
true is a synonym for 20.
11+
12+
merge.suppressDest::
13+
By adding a glob that matches the names of integration
14+
branches to this multi-valued configuration variable, the
15+
default merge message computed for merges into these
16+
integration branches will omit " into <branch name>" from
17+
its title.
18+
+
19+
An element with an empty value can be used to clear the list
20+
of globs accumulated from previous configuration entries.
21+
When there is no `merge.suppressDest` variable defined, the
22+
default value of `master` is used for backward compatibility.

fmt-merge-msg.c

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include "commit-reach.h"
1111

1212
static int use_branch_desc;
13+
static int suppress_dest_pattern_seen;
14+
static struct string_list suppress_dest_patterns = STRING_LIST_INIT_DUP;
1315

1416
int fmt_merge_msg_config(const char *key, const char *value, void *cb)
1517
{
@@ -22,6 +24,14 @@ int fmt_merge_msg_config(const char *key, const char *value, void *cb)
2224
merge_log_config = DEFAULT_MERGE_LOG_LEN;
2325
} else if (!strcmp(key, "merge.branchdesc")) {
2426
use_branch_desc = git_config_bool(key, value);
27+
} else if (!strcmp(key, "merge.suppressdest")) {
28+
if (!value)
29+
return config_error_nonbool(key);
30+
if (!*value)
31+
string_list_clear(&suppress_dest_patterns, 0);
32+
else
33+
string_list_append(&suppress_dest_patterns, value);
34+
suppress_dest_pattern_seen = 1;
2535
} else {
2636
return git_default_config(key, value, cb);
2737
}
@@ -403,6 +413,24 @@ static void shortlog(const char *name,
403413
string_list_clear(&subjects, 0);
404414
}
405415

416+
/*
417+
* See if dest_branch matches with any glob pattern on the
418+
* suppress_dest_patterns list.
419+
*
420+
* We may want to also allow negative matches e.g. ":!glob" like we do
421+
* for pathspec, but for now, let's keep it simple and stupid.
422+
*/
423+
static int dest_suppressed(const char *dest_branch)
424+
{
425+
struct string_list_item *item;
426+
427+
for_each_string_list_item(item, &suppress_dest_patterns) {
428+
if (!wildmatch(item->string, dest_branch, WM_PATHNAME))
429+
return 1;
430+
}
431+
return 0;
432+
}
433+
406434
static void fmt_merge_msg_title(struct strbuf *out,
407435
const char *current_branch)
408436
{
@@ -451,10 +479,9 @@ static void fmt_merge_msg_title(struct strbuf *out,
451479
strbuf_addf(out, " of %s", srcs.items[i].string);
452480
}
453481

454-
if (!strcmp("master", current_branch))
455-
strbuf_addch(out, '\n');
456-
else
457-
strbuf_addf(out, " into %s\n", current_branch);
482+
if (!dest_suppressed(current_branch))
483+
strbuf_addf(out, " into %s", current_branch);
484+
strbuf_addch(out, '\n');
458485
}
459486

460487
static void fmt_tag_signature(struct strbuf *tagbuf,
@@ -599,6 +626,9 @@ int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
599626
void *current_branch_to_free;
600627
struct merge_parents merge_parents;
601628

629+
if (!suppress_dest_pattern_seen)
630+
string_list_append(&suppress_dest_patterns, "master");
631+
602632
memset(&merge_parents, 0, sizeof(merge_parents));
603633

604634
/* get current branch */

t/t6200-fmt-merge-msg.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,4 +542,24 @@ test_expect_success 'merge-msg with "merging" an annotated tag' '
542542
test_cmp expected .git/MERGE_MSG
543543
'
544544

545+
test_expect_success 'merge.suppressDest configuration' '
546+
git checkout -B side master &&
547+
git commit --allow-empty -m "One step ahead" &&
548+
git checkout master &&
549+
git fetch . side &&
550+
551+
git -c merge.suppressDest="" fmt-merge-msg <.git/FETCH_HEAD >full.1 &&
552+
head -n1 full.1 >actual &&
553+
grep -e "Merge branch .side. into master" actual &&
554+
555+
git -c merge.suppressDest="mast" fmt-merge-msg <.git/FETCH_HEAD >full.2 &&
556+
head -n1 full.2 >actual &&
557+
grep -e "Merge branch .side. into master$" actual &&
558+
559+
git -c merge.suppressDest="ma??er" fmt-merge-msg <.git/FETCH_HEAD >full.3 &&
560+
head -n1 full.3 >actual &&
561+
grep -e "Merge branch .side." actual &&
562+
! grep -e " into master$" actual
563+
'
564+
545565
test_done

0 commit comments

Comments
 (0)