提交 b10731f4 编写于 作者: K Kyle Meyer 提交者: Junio C Hamano

branch_get_push: do not segfault when HEAD is detached

Move the detached HEAD check from branch_get_push_1() to
branch_get_push() to avoid setting branch->push_tracking_ref when
branch is NULL.
Signed-off-by: NKyle Meyer <kyle@kyleam.com>
Reviewed-by: NJeff King <peff@peff.net>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 0b65a8db
......@@ -1717,9 +1717,6 @@ static const char *branch_get_push_1(struct branch *branch, struct strbuf *err)
{
struct remote *remote;
if (!branch)
return error_buf(err, _("HEAD does not point to a branch"));
remote = remote_get(pushremote_for_branch(branch, NULL));
if (!remote)
return error_buf(err,
......@@ -1779,6 +1776,9 @@ static const char *branch_get_push_1(struct branch *branch, struct strbuf *err)
const char *branch_get_push(struct branch *branch, struct strbuf *err)
{
if (!branch)
return error_buf(err, _("HEAD does not point to a branch"));
if (!branch->push_tracking_ref)
branch->push_tracking_ref = branch_get_push_1(branch, err);
return branch->push_tracking_ref;
......
......@@ -60,4 +60,10 @@ test_expect_success '@{push} with push refspecs' '
resolve topic@{push} refs/remotes/origin/magic/topic
'
test_expect_success 'resolving @{push} fails with a detached HEAD' '
git checkout HEAD^0 &&
test_when_finished "git checkout -" &&
test_must_fail git rev-parse @{push}
'
test_done
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册