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>

Felipe Contreras committed May 31, 2021 at 14:51 UTC cc16f95d212d8e0bba07ddfb82aaf416dc4df1c2
1 file changed +3 -7
builtin/push.c
+3 -7
@@ -206,8 +206,6 @@ static void setup_push_upstream(struct remote *remote, struct branch *branch,
206 int same_remote)
207 {
208 const char *upstream_ref;
209 - if (!branch)
210 - die(_(message_detached_head_die), remote->name);
209 upstream_ref = get_upstream_ref(branch, remote->name);
210 if (!same_remote)
211 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,
218
219 static void setup_push_current(struct remote *remote, struct branch *branch)
220 {
223 - if (!branch)
224 - die(_(message_detached_head_die), remote->name);
221 refspec_appendf(&rs, "%s:%s", branch->refname, branch->refname);
222 }
223
224 static void setup_push_simple(struct remote *remote, struct branch *branch, int same_remote)
225 {
230 - if (!branch)
231 - die(_(message_detached_head_die), remote->name);
232 -
226 if (same_remote) {
227 const char *upstream_ref;
228
@@ -266,6 +259,9 @@ static void setup_default_push_refspecs(struct remote *remote)
259 break;
260 }
261
262 + if (!branch)
263 + die(_(message_detached_head_die), remote->name);
264 +
265 switch (push_default) {
266 default:
267 case PUSH_DEFAULT_UNSPECIFIED: