Skip to content

Commit bd30037

Browse files
committed
Merge branch 'jk/maint-merge-msg-fix' into maint
* jk/maint-merge-msg-fix: merge: indicate remote tracking branches in merge message merge: fix incorrect merge message for ambiguous tag/branch add tests for merge message headings
2 parents 6b37b3d + 69a8b7c commit bd30037

File tree

4 files changed

+75
-11
lines changed

4 files changed

+75
-11
lines changed

builtin-merge.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
358358
struct strbuf buf = STRBUF_INIT;
359359
struct strbuf bname = STRBUF_INIT;
360360
const char *ptr;
361+
char *found_ref;
361362
int len, early;
362363

363364
strbuf_branchname(&bname, remote);
@@ -368,14 +369,17 @@ static void merge_name(const char *remote, struct strbuf *msg)
368369
if (!remote_head)
369370
die("'%s' does not point to a commit", remote);
370371

371-
strbuf_addstr(&buf, "refs/heads/");
372-
strbuf_addstr(&buf, remote);
373-
resolve_ref(buf.buf, branch_head, 0, NULL);
374-
375-
if (!hashcmp(remote_head->sha1, branch_head)) {
376-
strbuf_addf(msg, "%s\t\tbranch '%s' of .\n",
377-
sha1_to_hex(branch_head), remote);
378-
goto cleanup;
372+
if (dwim_ref(remote, strlen(remote), branch_head, &found_ref) > 0) {
373+
if (!prefixcmp(found_ref, "refs/heads/")) {
374+
strbuf_addf(msg, "%s\t\tbranch '%s' of .\n",
375+
sha1_to_hex(branch_head), remote);
376+
goto cleanup;
377+
}
378+
if (!prefixcmp(found_ref, "refs/remotes/")) {
379+
strbuf_addf(msg, "%s\t\tremote branch '%s' of .\n",
380+
sha1_to_hex(branch_head), remote);
381+
goto cleanup;
382+
}
379383
}
380384

381385
/* See if remote matches <name>^^^.. or <name>~<number> */

t/t3409-rebase-preserve-merges.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ test_expect_success 'rebase -p fakes interactive rebase' '
7171
git fetch &&
7272
git rebase -p origin/topic &&
7373
test 1 = $(git rev-list --all --pretty=oneline | grep "Modify A" | wc -l) &&
74-
test 1 = $(git rev-list --all --pretty=oneline | grep "Merge commit" | wc -l)
74+
test 1 = $(git rev-list --all --pretty=oneline | grep "Merge remote branch " | wc -l)
7575
)
7676
'
7777

t/t4202-log.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,11 @@ test_expect_success 'set up more tangled history' '
320320
'
321321

322322
cat > expect <<\EOF
323-
* Merge branch 'reach'
323+
* Merge commit 'reach'
324324
|\
325325
| \
326326
| \
327-
*-. \ Merge branches 'octopus-a' and 'octopus-b'
327+
*-. \ Merge commit 'octopus-a'; commit 'octopus-b'
328328
|\ \ \
329329
* | | | seventh
330330
| | * | octopus-b

t/t7608-merge-messages.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/sh
2+
3+
test_description='test auto-generated merge messages'
4+
. ./test-lib.sh
5+
6+
check_oneline() {
7+
echo "$1" | sed "s/Q/'/g" >expect &&
8+
git log -1 --pretty=tformat:%s >actual &&
9+
test_cmp expect actual
10+
}
11+
12+
test_expect_success 'merge local branch' '
13+
test_commit master-1 &&
14+
git checkout -b local-branch &&
15+
test_commit branch-1 &&
16+
git checkout master &&
17+
test_commit master-2 &&
18+
git merge local-branch &&
19+
check_oneline "Merge branch Qlocal-branchQ"
20+
'
21+
22+
test_expect_success 'merge octopus branches' '
23+
git checkout -b octopus-a master &&
24+
test_commit octopus-1 &&
25+
git checkout -b octopus-b master &&
26+
test_commit octopus-2 &&
27+
git checkout master &&
28+
git merge octopus-a octopus-b &&
29+
check_oneline "Merge branches Qoctopus-aQ and Qoctopus-bQ"
30+
'
31+
32+
test_expect_success 'merge tag' '
33+
git checkout -b tag-branch master &&
34+
test_commit tag-1 &&
35+
git checkout master &&
36+
test_commit master-3 &&
37+
git merge tag-1 &&
38+
check_oneline "Merge commit Qtag-1Q"
39+
'
40+
41+
test_expect_success 'ambiguous tag' '
42+
git checkout -b ambiguous master &&
43+
test_commit ambiguous &&
44+
git checkout master &&
45+
test_commit master-4 &&
46+
git merge ambiguous &&
47+
check_oneline "Merge commit QambiguousQ"
48+
'
49+
50+
test_expect_success 'remote branch' '
51+
git checkout -b remote master &&
52+
test_commit remote-1 &&
53+
git update-ref refs/remotes/origin/master remote &&
54+
git checkout master &&
55+
test_commit master-5 &&
56+
git merge origin/master &&
57+
check_oneline "Merge remote branch Qorigin/masterQ"
58+
'
59+
60+
test_done

0 commit comments

Comments
 (0)