push: factor out null branch check

No need to do it in every single function.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Felipe Contreras
2021-05-31 14:51:15 -05:00
committed by Junio C Hamano
parent 04159fba42
commit cc16f95d21

View File

@ -206,8 +206,6 @@ static void setup_push_upstream(struct remote *remote, struct branch *branch,
int same_remote) int same_remote)
{ {
const char *upstream_ref; const char *upstream_ref;
if (!branch)
die(_(message_detached_head_die), remote->name);
upstream_ref = get_upstream_ref(branch, remote->name); upstream_ref = get_upstream_ref(branch, remote->name);
if (!same_remote) if (!same_remote)
die(_("You are pushing to remote '%s', which is not the upstream of\n" die(_("You are pushing to remote '%s', which is not the upstream of\n"
@ -220,16 +218,11 @@ static void setup_push_upstream(struct remote *remote, struct branch *branch,
static void setup_push_current(struct remote *remote, struct branch *branch) static void setup_push_current(struct remote *remote, struct branch *branch)
{ {
if (!branch)
die(_(message_detached_head_die), remote->name);
refspec_appendf(&rs, "%s:%s", branch->refname, branch->refname); refspec_appendf(&rs, "%s:%s", branch->refname, branch->refname);
} }
static void setup_push_simple(struct remote *remote, struct branch *branch, int same_remote) static void setup_push_simple(struct remote *remote, struct branch *branch, int same_remote)
{ {
if (!branch)
die(_(message_detached_head_die), remote->name);
if (same_remote) { if (same_remote) {
const char *upstream_ref; const char *upstream_ref;
@ -266,6 +259,9 @@ static void setup_default_push_refspecs(struct remote *remote)
break; break;
} }
if (!branch)
die(_(message_detached_head_die), remote->name);
switch (push_default) { switch (push_default) {
default: default:
case PUSH_DEFAULT_UNSPECIFIED: case PUSH_DEFAULT_UNSPECIFIED: