Skip to content

Commit da15028

Browse files
dschogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f361120 commit da15028

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

fmt-merge-msg.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ static void fmt_merge_msg_title(struct strbuf *out,
407407
const char *current_branch)
408408
{
409409
int i = 0;
410-
char *sep = "";
410+
char *sep = "", *default_branch_name;
411411

412412
strbuf_addstr(out, "Merge ");
413413
for (i = 0; i < srcs.nr; i++) {
@@ -451,10 +451,12 @@ static void fmt_merge_msg_title(struct strbuf *out,
451451
strbuf_addf(out, " of %s", srcs.items[i].string);
452452
}
453453

454-
if (!strcmp("master", current_branch))
454+
default_branch_name = git_default_branch_name(1);
455+
if (!strcmp(default_branch_name, current_branch))
455456
strbuf_addch(out, '\n');
456457
else
457458
strbuf_addf(out, " into %s\n", current_branch);
459+
free(default_branch_name);
458460
}
459461

460462
static void fmt_tag_signature(struct strbuf *tagbuf,

t/t6200-fmt-merge-msg.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,14 @@ test_expect_success 'setup FETCH_HEAD' '
158158
git fetch . left
159159
'
160160

161+
test_expect_success 'with overridden default branch name' '
162+
test_config core.defaultBranchName default &&
163+
test_when_finished "git switch master" &&
164+
git switch -c default &&
165+
git fmt-merge-msg <.git/FETCH_HEAD >actual &&
166+
! grep "into default" actual
167+
'
168+
161169
test_expect_success 'merge.log=3 limits shortlog length' '
162170
cat >expected <<-EOF &&
163171
Merge branch ${apos}left${apos}

0 commit comments

Comments
 (0)