merge: fix incorrect merge message for ambiguous tag/branch
If we have both a tag and a branch named "foo", then calling "git merge foo" will warn about the ambiguous ref, but merge the tag. When generating the commit message, though, we simply checked whether "refs/heads/foo" existed, and if it did, assumed it was a branch. This led to the statement "Merge branch 'foo'" in the commit message, which is quite wrong. Instead, we should use dwim_ref to find the actual ref used, and describe it appropriately. In addition to the test in t7608, we must also tweak the expected output of t4202, which was accidentally triggering this bug. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Aug 9, 2009 at 06:02 UTC
751c59746c7522982214528eb653dfb61d372257
3 files changed
+10
-11
builtin-merge.c
+7
-8
@@ -358,6 +358,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
358
struct strbuf buf = STRBUF_INIT;
359
struct strbuf bname = STRBUF_INIT;
360
const char *ptr;
361
+ char *found_ref;
362
int len, early;
363
364
strbuf_branchname(&bname, remote);
@@ -368,14 +369,12 @@ static void merge_name(const char *remote, struct strbuf *msg)
369
if (!remote_head)
370
die("'%s' does not point to a commit", remote);
371
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
}
379
380
/* See if remote matches <name>^^^.. or <name>~<number> */
t/t4202-log.sh
+2
-2
@@ -320,11 +320,11 @@ test_expect_success 'set up more tangled history' '
320
'
321
322
cat > expect <<\EOF
323
-* Merge branch 'reach'
323
+* Merge commit 'reach'
324
|\
325
| \
326
| \
327
-*-. \ Merge branches 'octopus-a' and 'octopus-b'
327
+*-. \ Merge commit 'octopus-a'; commit 'octopus-b'
328
|\ \ \
329
* | | | seventh
330
| | * | octopus-b
t/t7608-merge-messages.sh
+1
-1
@@ -38,7 +38,7 @@ test_expect_success 'merge tag' '
38
check_oneline "Merge commit Qtag-1Q"
39
'
40
41
-test_expect_failure 'ambiguous tag' '
41
+test_expect_success 'ambiguous tag' '
42
git checkout -b ambiguous master &&
43
test_commit ambiguous &&
44
git checkout master &&