summaryrefslogtreecommitdiff
path: root/remote.c
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2017-01-06 20:12:15 -0500
committerJunio C Hamano <gitster@pobox.com>2017-01-07 19:20:07 -0800
commitb10731f43dc21fa47c275052e7c074c686335cd3 (patch)
treea8dec989c054725eb2f0605aef101aca5c17d403 /remote.c
parent0b65a8dbdb38962e700ee16776a3042beb489060 (diff)
downloadgit-b10731f43dc21fa47c275052e7c074c686335cd3.tar.gz
branch_get_push: do not segfault when HEAD is detachedkm/branch-get-push-while-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: Kyle Meyer <kyle@kyleam.com> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'remote.c')
-rw-r--r--remote.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/remote.c b/remote.c
index a326e4e251..d1a7a4032b 100644
--- a/remote.c
+++ b/remote.c
@@ -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;