提交 1ed10b88 编写于 作者: J Junio C Hamano

remote.c: "git-push frotz" should update what matches at the source.

Earlier, when the local repository has a branch "frotz" and the
remote repository has a tag "frotz" (but not branch "frotz"),
"git-push frotz" mistakenly updated the tag at the remote side.
This was because the partial refname matching code was applied
independently on both source and destination side.

With this fix, when a colon-less refspec is given to git-push,
we first match it with the refs in the source repository, and
update the matching ref in the destination repository.
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 6125796f
...@@ -455,7 +455,7 @@ static int match_explicit(struct ref *src, struct ref *dst, ...@@ -455,7 +455,7 @@ static int match_explicit(struct ref *src, struct ref *dst,
errs = 1; errs = 1;
if (dst_value == NULL) if (dst_value == NULL)
dst_value = rs->src; dst_value = matched_src->name;
switch (count_refspec_match(dst_value, dst, &matched_dst)) { switch (count_refspec_match(dst_value, dst, &matched_dst)) {
case 1: case 1:
...@@ -463,11 +463,6 @@ static int match_explicit(struct ref *src, struct ref *dst, ...@@ -463,11 +463,6 @@ static int match_explicit(struct ref *src, struct ref *dst,
case 0: case 0:
if (!memcmp(dst_value, "refs/", 5)) if (!memcmp(dst_value, "refs/", 5))
matched_dst = make_dst(dst_value, dst_tail); matched_dst = make_dst(dst_value, dst_tail);
else if (!strcmp(rs->src, dst_value) && matched_src)
/* pushing "master:master" when
* remote does not have master yet.
*/
matched_dst = make_dst(matched_src->name, dst_tail);
else else
error("dst refspec %s does not match any " error("dst refspec %s does not match any "
"existing ref on the remote and does " "existing ref on the remote and does "
......
...@@ -189,6 +189,58 @@ test_expect_success 'push with ambiguity (2)' ' ...@@ -189,6 +189,58 @@ test_expect_success 'push with ambiguity (2)' '
else else
check_push_result $the_first_commit heads/frotz tags/frotz check_push_result $the_first_commit heads/frotz tags/frotz
fi fi
'
test_expect_success 'push with colon-less refspec (1)' '
mk_test heads/frotz tags/frotz &&
git branch -f frotz master &&
git push testrepo frotz &&
check_push_result $the_commit heads/frotz &&
check_push_result $the_first_commit tags/frotz
'
test_expect_success 'push with colon-less refspec (2)' '
mk_test heads/frotz tags/frotz &&
if git show-ref --verify -q refs/heads/frotz
then
git branch -D frotz
fi &&
git tag -f frotz &&
git push testrepo frotz &&
check_push_result $the_commit tags/frotz &&
check_push_result $the_first_commit heads/frotz
'
test_expect_success 'push with colon-less refspec (3)' '
mk_test &&
if git show-ref --verify -q refs/tags/frotz
then
git tag -d frotz
fi &&
git branch -f frotz master &&
git push testrepo frotz &&
check_push_result $the_commit heads/frotz &&
test "$( cd testrepo && git show-ref | wc -l )" = 1
'
test_expect_success 'push with colon-less refspec (4)' '
mk_test &&
if git show-ref --verify -q refs/heads/frotz
then
git branch -D frotz
fi &&
git tag -f frotz &&
git push testrepo frotz &&
check_push_result $the_commit tags/frotz &&
test "$( cd testrepo && git show-ref | wc -l )" = 1
' '
test_done test_done
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册