merge: do not mistake (ancestor of) tag for branch
If no branch 'foo' exists but a tag 'foo' does, then git merge foo^ results in Merge branch 'foo' (early part) as a commit message, because the relevant code path checks that refs/heads/foo is a valid refname for writing rather than for reading. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jonathan Nieder committed
Aug 17, 2010 at 01:52 UTC
b81f925f709a10b37fb4fcd03629b55bc890a478
2 files changed
+13
-5
builtin/merge.c
+1
-1
@@ -437,7 +437,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
437
strbuf_addstr(&truname, "refs/heads/");
438
strbuf_addstr(&truname, remote);
439
strbuf_setlen(&truname, truname.len - len);
440
- if (resolve_ref(truname.buf, buf_sha, 0, NULL)) {
440
+ if (resolve_ref(truname.buf, buf_sha, 1, NULL)) {
441
strbuf_addf(msg,
442
"%s\t\tbranch '%s'%s of .\n",
443
sha1_to_hex(remote_head->sha1),
t/t7600-merge.sh
+12
-4
@@ -558,8 +558,11 @@ test_expect_success 'refresh the index before merging' '
558
git merge c3
559
'
560
561
-cat >expected <<EOF
562
-Merge branch 'c5' (early part)
561
+cat >expected.branch <<\EOF
562
+Merge branch 'c5-branch' (early part)
563
+EOF
564
+cat >expected.tag <<\EOF
565
+Merge commit 'c5~1'
566
EOF
567
568
test_expect_success 'merge early part of c2' '
@@ -577,9 +580,14 @@ test_expect_success 'merge early part of c2' '
580
git add c6.c &&
581
git commit -m c6 &&
582
git tag c6 &&
583
+ git branch -f c5-branch c5 &&
584
+ git merge c5-branch~1 &&
585
+ git show -s --pretty=format:%s HEAD >actual.branch &&
586
+ git reset --keep HEAD^ &&
587
git merge c5~1 &&
581
- git show -s --pretty=format:%s HEAD > actual &&
582
- test_cmp actual expected
588
+ git show -s --pretty=format:%s HEAD >actual.tag &&
589
+ test_cmp expected.branch actual.branch &&
590
+ test_cmp expected.tag actual.tag
591
'
592
593
test_debug 'gitk --all'