Skip to content

Commit cc16f95

Browse files
felipecgitster
authored andcommitted
push: factor out null branch check
No need to do it in every single function. Signed-off-by: Felipe Contreras <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 04159fb commit cc16f95

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

builtin/push.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,6 @@ static void setup_push_upstream(struct remote *remote, struct branch *branch,
206206
int same_remote)
207207
{
208208
const char *upstream_ref;
209-
if (!branch)
210-
die(_(message_detached_head_die), remote->name);
211209
upstream_ref = get_upstream_ref(branch, remote->name);
212210
if (!same_remote)
213211
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,
220218

221219
static void setup_push_current(struct remote *remote, struct branch *branch)
222220
{
223-
if (!branch)
224-
die(_(message_detached_head_die), remote->name);
225221
refspec_appendf(&rs, "%s:%s", branch->refname, branch->refname);
226222
}
227223

228224
static void setup_push_simple(struct remote *remote, struct branch *branch, int same_remote)
229225
{
230-
if (!branch)
231-
die(_(message_detached_head_die), remote->name);
232-
233226
if (same_remote) {
234227
const char *upstream_ref;
235228

@@ -266,6 +259,9 @@ static void setup_default_push_refspecs(struct remote *remote)
266259
break;
267260
}
268261

262+
if (!branch)
263+
die(_(message_detached_head_die), remote->name);
264+
269265
switch (push_default) {
270266
default:
271267
case PUSH_DEFAULT_UNSPECIFIED:

0 commit comments

Comments
 (0)