summaryrefslogtreecommitdiff
path: root/builtin/push.c
diff options
context:
space:
mode:
authorFelipe Contreras <felipe.contreras@gmail.com>2021-05-31 19:51:15 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-06-02 01:12:01 (GMT)
commitcc16f95d212d8e0bba07ddfb82aaf416dc4df1c2 (patch)
tree757e21e19b135e67f4868bfb842b5cac223c0963 /builtin/push.c
parent04159fba42b61ffa954dfb1fa13df1862c210ad8 (diff)
downloadgit-cc16f95d212d8e0bba07ddfb82aaf416dc4df1c2.zip
git-cc16f95d212d8e0bba07ddfb82aaf416dc4df1c2.tar.gz
git-cc16f95d212d8e0bba07ddfb82aaf416dc4df1c2.tar.bz2
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>
Diffstat (limited to 'builtin/push.c')
-rw-r--r--builtin/push.c10
1 files changed, 3 insertions, 7 deletions
diff --git a/builtin/push.c b/builtin/push.c
index f64b710..8fcbd28 100644
--- a/builtin/push.c
+++ b/builtin/push.c
@@ -206,8 +206,6 @@ static void setup_push_upstream(struct remote *remote, struct branch *branch,
int same_remote)
{
const char *upstream_ref;
- if (!branch)
- die(_(message_detached_head_die), remote->name);
upstream_ref = get_upstream_ref(branch, remote->name);
if (!same_remote)
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)
{
- if (!branch)
- die(_(message_detached_head_die), remote->name);
refspec_appendf(&rs, "%s:%s", branch->refname, branch->refname);
}
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) {
const char *upstream_ref;
@@ -266,6 +259,9 @@ static void setup_default_push_refspecs(struct remote *remote)
break;
}
+ if (!branch)
+ die(_(message_detached_head_die), remote->name);
+
switch (push_default) {
default:
case PUSH_DEFAULT_UNSPECIFIED: