fmt-merge-msg: learn about the possibly-configured default branch name

When formatting the commit message for merge commits, Git appends "into
<branch-name>" unless the current branch is the default branch.

Now that we can configure what the default branch name should be, we
will want to respect that setting in that scenario rather than using the
compiled-in default branch name.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Johannes Schindelin
2020-06-10 21:19:28 +00:00
committed by Junio C Hamano
parent f361120fc2
commit da15028a0a
2 changed files with 12 additions and 2 deletions

View File

@ -407,7 +407,7 @@ static void fmt_merge_msg_title(struct strbuf *out,
const char *current_branch)
{
int i = 0;
char *sep = "";
char *sep = "", *default_branch_name;
strbuf_addstr(out, "Merge ");
for (i = 0; i < srcs.nr; i++) {
@ -451,10 +451,12 @@ static void fmt_merge_msg_title(struct strbuf *out,
strbuf_addf(out, " of %s", srcs.items[i].string);
}
if (!strcmp("master", current_branch))
default_branch_name = git_default_branch_name(1);
if (!strcmp(default_branch_name, current_branch))
strbuf_addch(out, '\n');
else
strbuf_addf(out, " into %s\n", current_branch);
free(default_branch_name);
}
static void fmt_tag_signature(struct strbuf *tagbuf,

View File

@ -158,6 +158,14 @@ test_expect_success 'setup FETCH_HEAD' '
git fetch . left
'
test_expect_success 'with overridden default branch name' '
test_config core.defaultBranchName default &&
test_when_finished "git switch master" &&
git switch -c default &&
git fmt-merge-msg <.git/FETCH_HEAD >actual &&
! grep "into default" actual
'
test_expect_success 'merge.log=3 limits shortlog length' '
cat >expected <<-EOF &&
Merge branch ${apos}left${apos}