Skip to content

Commit

Permalink
Merge branch 'jc/merge-tag-object'
Browse files Browse the repository at this point in the history
"git merge $(git rev-parse v1.8.2)" behaved quite differently from
"git merge v1.8.2" as if v1.8.2 were written as v1.8.2^0 and did
not pay much attention to the annotated tag payload.

This makes the code notice the type of the tag object, in addition
to the dwim_ref() based classification the current code uses
(i.e. the name appears in refs/tags/) to decide when to special
case merging of tags.

* jc/merge-tag-object:
  t6200: test message for merging of an annotated tag
  t6200: use test_config/test_unconfig
  merge: a random object may not necssarily be a commit
  • Loading branch information
Junio C Hamano committed Apr 5, 2013
2 parents bfd70c5 + a38d3d7 commit e636241
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 32 deletions.
13 changes: 13 additions & 0 deletions builtin/merge.c
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,19 @@ static void merge_name(const char *remote, struct strbuf *msg)
strbuf_release(&line);
goto cleanup;
}

if (remote_head->util) {
struct merge_remote_desc *desc;
desc = merge_remote_util(remote_head);
if (desc && desc->obj && desc->obj->type == OBJ_TAG) {
strbuf_addf(msg, "%s\t\t%s '%s'\n",
sha1_to_hex(desc->obj->sha1),
typename(desc->obj->type),
remote);
goto cleanup;
}
}

strbuf_addf(msg, "%s\t\tcommit '%s'\n",
sha1_to_hex(remote_head->object.sha1), remote);
cleanup:
Expand Down
100 changes: 68 additions & 32 deletions t/t6200-fmt-merge-msg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,17 @@ test_expect_success '[merge] summary/log configuration' '
Common #1
EOF
git config merge.log true &&
test_might_fail git config --unset-all merge.summary &&
test_config merge.log true &&
test_unconfig merge.summary &&
git checkout master &&
test_tick &&
git fetch . left &&
git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
test_might_fail git config --unset-all merge.log &&
git config merge.summary true &&
test_unconfig merge.log &&
test_config merge.summary true &&
git checkout master &&
test_tick &&
Expand All @@ -134,11 +134,6 @@ test_expect_success '[merge] summary/log configuration' '
test_cmp expected actual2
'

test_expect_success 'setup: clear [merge] configuration' '
test_might_fail git config --unset-all merge.log &&
test_might_fail git config --unset-all merge.summary
'

test_expect_success 'setup FETCH_HEAD' '
git checkout master &&
test_tick &&
Expand Down Expand Up @@ -248,14 +243,14 @@ test_expect_success 'fmt-merge-msg -m' '
Common #1
EOF
test_might_fail git config --unset merge.log &&
test_might_fail git config --unset merge.summary &&
test_unconfig merge.log &&
test_unconfig merge.summary &&
git checkout master &&
git fetch "$(pwd)" left &&
git fmt-merge-msg -m "Sync with left" <.git/FETCH_HEAD >actual &&
git fmt-merge-msg --log -m "Sync with left" \
<.git/FETCH_HEAD >actual.log &&
git config merge.log true &&
test_config merge.log true &&
git fmt-merge-msg -m "Sync with left" \
<.git/FETCH_HEAD >actual.log-config &&
git fmt-merge-msg --no-log -m "Sync with left" \
Expand Down Expand Up @@ -290,29 +285,29 @@ test_expect_success 'setup: expected shortlog for two branches' '
'

test_expect_success 'shortlog for two branches' '
git config merge.log true &&
test_might_fail git config --unset-all merge.summary &&
test_config merge.log true &&
test_unconfig merge.summary &&
git checkout master &&
test_tick &&
git fetch . left right &&
git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
test_might_fail git config --unset-all merge.log &&
git config merge.summary true &&
test_unconfig merge.log &&
test_config merge.summary true &&
git checkout master &&
test_tick &&
git fetch . left right &&
git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
git config merge.log yes &&
test_might_fail git config --unset-all merge.summary &&
test_config merge.log yes &&
test_unconfig merge.summary &&
git checkout master &&
test_tick &&
git fetch . left right &&
git fmt-merge-msg <.git/FETCH_HEAD >actual3 &&
test_might_fail git config --unset-all merge.log &&
git config merge.summary yes &&
test_unconfig merge.log &&
test_config merge.summary yes &&
git checkout master &&
test_tick &&
git fetch . left right &&
Expand All @@ -325,8 +320,8 @@ test_expect_success 'shortlog for two branches' '
'

test_expect_success 'merge-msg -F' '
test_might_fail git config --unset-all merge.log &&
git config merge.summary yes &&
test_unconfig merge.log &&
test_config merge.summary yes &&
git checkout master &&
test_tick &&
git fetch . left right &&
Expand All @@ -335,8 +330,8 @@ test_expect_success 'merge-msg -F' '
'

test_expect_success 'merge-msg -F in subdirectory' '
test_might_fail git config --unset-all merge.log &&
git config merge.summary yes &&
test_unconfig merge.log &&
test_config merge.summary yes &&
git checkout master &&
test_tick &&
git fetch . left right &&
Expand All @@ -350,8 +345,8 @@ test_expect_success 'merge-msg -F in subdirectory' '
'

test_expect_success 'merge-msg with nothing to merge' '
test_might_fail git config --unset-all merge.log &&
git config merge.summary yes &&
test_unconfig merge.log &&
test_config merge.summary yes &&
>empty &&
Expand All @@ -376,8 +371,8 @@ test_expect_success 'merge-msg tag' '
Common #1
EOF
test_might_fail git config --unset-all merge.log &&
git config merge.summary yes &&
test_unconfig merge.log &&
test_config merge.summary yes &&
git checkout master &&
test_tick &&
Expand Down Expand Up @@ -406,8 +401,8 @@ test_expect_success 'merge-msg two tags' '
Common #1
EOF
test_might_fail git config --unset-all merge.log &&
git config merge.summary yes &&
test_unconfig merge.log &&
test_config merge.summary yes &&
git checkout master &&
test_tick &&
Expand Down Expand Up @@ -436,8 +431,8 @@ test_expect_success 'merge-msg tag and branch' '
Common #1
EOF
test_might_fail git config --unset-all merge.log &&
git config merge.summary yes &&
test_unconfig merge.log &&
test_config merge.summary yes &&
git checkout master &&
test_tick &&
Expand All @@ -464,6 +459,8 @@ test_expect_success 'merge-msg lots of commits' '
echo " ..."
} >expected &&
test_config merge.summary yes &&
git checkout master &&
test_tick &&
git fetch . long &&
Expand All @@ -472,4 +469,43 @@ test_expect_success 'merge-msg lots of commits' '
test_cmp expected actual
'

test_expect_success 'merge-msg with "merging" an annotated tag' '
test_config merge.log true &&
git checkout master^0 &&
git commit --allow-empty -m "One step ahead" &&
git tag -a -m "An annotated one" annote HEAD &&
git checkout master &&
git fetch . annote &&
git fmt-merge-msg <.git/FETCH_HEAD >actual &&
{
cat <<-\EOF
Merge tag '\''annote'\''
An annotated one
* tag '\''annote'\'':
One step ahead
EOF
} >expected &&
test_cmp expected actual &&
test_when_finished "git reset --hard" &&
annote=$(git rev-parse annote) &&
git merge --no-commit $annote &&
{
cat <<-EOF
Merge tag '\''$annote'\''
An annotated one
* tag '\''$annote'\'':
One step ahead
EOF
} >expected &&
test_cmp expected .git/MERGE_MSG
'

test_done

0 comments on commit e636241

Please sign in to comment.