refspec: make @ a synonym of HEAD
Since commit 9ba89f484e
git learned how to push to a remote branch using
the source @, for example:
git push origin @:master
However, if the right-hand side is missing, the push fails:
git push origin @
It is obvious what is the desired behavior, and allowing the push makes
things more consistent.
Additionally, @:master now has the same semantics as HEAD:master.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
e7f80eafd1
commit
374fbaef3d
@ -71,7 +71,10 @@ static int parse_refspec(struct refspec_item *item, const char *refspec, int fet
|
|||||||
}
|
}
|
||||||
|
|
||||||
item->pattern = is_glob;
|
item->pattern = is_glob;
|
||||||
item->src = xstrndup(lhs, llen);
|
if (llen == 1 && *lhs == '@')
|
||||||
|
item->src = xstrdup("HEAD");
|
||||||
|
else
|
||||||
|
item->src = xstrndup(lhs, llen);
|
||||||
flags = REFNAME_ALLOW_ONELEVEL | (is_glob ? REFNAME_REFSPEC_PATTERN : 0);
|
flags = REFNAME_ALLOW_ONELEVEL | (is_glob ? REFNAME_REFSPEC_PATTERN : 0);
|
||||||
|
|
||||||
if (item->negative) {
|
if (item->negative) {
|
||||||
|
@ -58,6 +58,8 @@ test_refspec fetch 'HEAD~4:refs/remotes/frotz/new' invalid
|
|||||||
|
|
||||||
test_refspec push 'HEAD'
|
test_refspec push 'HEAD'
|
||||||
test_refspec fetch 'HEAD'
|
test_refspec fetch 'HEAD'
|
||||||
|
test_refspec push '@'
|
||||||
|
test_refspec fetch '@'
|
||||||
test_refspec push 'refs/heads/ nitfol' invalid
|
test_refspec push 'refs/heads/ nitfol' invalid
|
||||||
test_refspec fetch 'refs/heads/ nitfol' invalid
|
test_refspec fetch 'refs/heads/ nitfol' invalid
|
||||||
|
|
||||||
|
@ -436,71 +436,76 @@ test_expect_success 'push ref expression with non-existent, incomplete dest' '
|
|||||||
|
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'push with HEAD' '
|
for head in HEAD @
|
||||||
|
do
|
||||||
|
|
||||||
mk_test testrepo heads/master &&
|
test_expect_success "push with $head" '
|
||||||
git checkout master &&
|
|
||||||
git push testrepo HEAD &&
|
|
||||||
check_push_result testrepo $the_commit heads/master
|
|
||||||
|
|
||||||
'
|
mk_test testrepo heads/master &&
|
||||||
|
git checkout master &&
|
||||||
|
git push testrepo $head &&
|
||||||
|
check_push_result testrepo $the_commit heads/master
|
||||||
|
|
||||||
test_expect_success 'push with HEAD nonexisting at remote' '
|
'
|
||||||
|
|
||||||
mk_test testrepo heads/master &&
|
test_expect_success "push with $head nonexisting at remote" '
|
||||||
git checkout -b local master &&
|
|
||||||
test_when_finished "git checkout master; git branch -D local" &&
|
|
||||||
git push testrepo HEAD &&
|
|
||||||
check_push_result testrepo $the_commit heads/local
|
|
||||||
'
|
|
||||||
|
|
||||||
test_expect_success 'push with +HEAD' '
|
mk_test testrepo heads/master &&
|
||||||
|
git checkout -b local master &&
|
||||||
|
test_when_finished "git checkout master; git branch -D local" &&
|
||||||
|
git push testrepo $head &&
|
||||||
|
check_push_result testrepo $the_commit heads/local
|
||||||
|
'
|
||||||
|
|
||||||
mk_test testrepo heads/master &&
|
test_expect_success "push with +$head" '
|
||||||
git checkout -b local master &&
|
|
||||||
test_when_finished "git checkout master; git branch -D local" &&
|
|
||||||
git push testrepo master local &&
|
|
||||||
check_push_result testrepo $the_commit heads/master &&
|
|
||||||
check_push_result testrepo $the_commit heads/local &&
|
|
||||||
|
|
||||||
# Without force rewinding should fail
|
mk_test testrepo heads/master &&
|
||||||
git reset --hard HEAD^ &&
|
git checkout -b local master &&
|
||||||
test_must_fail git push testrepo HEAD &&
|
test_when_finished "git checkout master; git branch -D local" &&
|
||||||
check_push_result testrepo $the_commit heads/local &&
|
git push testrepo master local &&
|
||||||
|
check_push_result testrepo $the_commit heads/master &&
|
||||||
|
check_push_result testrepo $the_commit heads/local &&
|
||||||
|
|
||||||
# With force rewinding should succeed
|
# Without force rewinding should fail
|
||||||
git push testrepo +HEAD &&
|
git reset --hard $head^ &&
|
||||||
check_push_result testrepo $the_first_commit heads/local
|
test_must_fail git push testrepo $head &&
|
||||||
|
check_push_result testrepo $the_commit heads/local &&
|
||||||
|
|
||||||
'
|
# With force rewinding should succeed
|
||||||
|
git push testrepo +$head &&
|
||||||
|
check_push_result testrepo $the_first_commit heads/local
|
||||||
|
|
||||||
test_expect_success 'push HEAD with non-existent, incomplete dest' '
|
'
|
||||||
|
|
||||||
mk_test testrepo &&
|
test_expect_success "push $head with non-existent, incomplete dest" '
|
||||||
git checkout master &&
|
|
||||||
git push testrepo HEAD:branch &&
|
|
||||||
check_push_result testrepo $the_commit heads/branch
|
|
||||||
|
|
||||||
'
|
mk_test testrepo &&
|
||||||
|
git checkout master &&
|
||||||
|
git push testrepo $head:branch &&
|
||||||
|
check_push_result testrepo $the_commit heads/branch
|
||||||
|
|
||||||
test_expect_success 'push with config remote.*.push = HEAD' '
|
'
|
||||||
|
|
||||||
mk_test testrepo heads/local &&
|
test_expect_success "push with config remote.*.push = $head" '
|
||||||
git checkout master &&
|
|
||||||
git branch -f local $the_commit &&
|
mk_test testrepo heads/local &&
|
||||||
test_when_finished "git branch -D local" &&
|
git checkout master &&
|
||||||
(
|
git branch -f local $the_commit &&
|
||||||
cd testrepo &&
|
test_when_finished "git branch -D local" &&
|
||||||
git checkout local &&
|
(
|
||||||
git reset --hard $the_first_commit
|
cd testrepo &&
|
||||||
) &&
|
git checkout local &&
|
||||||
test_config remote.there.url testrepo &&
|
git reset --hard $the_first_commit
|
||||||
test_config remote.there.push HEAD &&
|
) &&
|
||||||
test_config branch.master.remote there &&
|
test_config remote.there.url testrepo &&
|
||||||
git push &&
|
test_config remote.there.push $head &&
|
||||||
check_push_result testrepo $the_commit heads/master &&
|
test_config branch.master.remote there &&
|
||||||
check_push_result testrepo $the_first_commit heads/local
|
git push &&
|
||||||
'
|
check_push_result testrepo $the_commit heads/master &&
|
||||||
|
check_push_result testrepo $the_first_commit heads/local
|
||||||
|
'
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
test_expect_success 'push with remote.pushdefault' '
|
test_expect_success 'push with remote.pushdefault' '
|
||||||
mk_test up_repo heads/master &&
|
mk_test up_repo heads/master &&
|
||||||
|
Loading…
Reference in New Issue
Block a user