Signed-off-by: Felipe Contreras <felipe.contre...@gmail.com>
---
 builtin/push.c | 35 +++++++++++++++++++----------------
 1 file changed, 19 insertions(+), 16 deletions(-)

diff --git a/builtin/push.c b/builtin/push.c
index 04f0eaf..5dc06a3 100644
--- a/builtin/push.c
+++ b/builtin/push.c
@@ -113,20 +113,11 @@ static NORETURN int die_push_simple(struct branch 
*branch, struct remote *remote
            remote->name, branch->name, advice_maybe);
 }
 
-static const char message_detached_head_die[] =
-       N_("You are not currently on a branch.\n"
-          "To push the history leading to the current (detached HEAD)\n"
-          "state now, use\n"
-          "\n"
-          "    git push %s HEAD:<name-of-remote-branch>\n");
-
 static void setup_push_upstream(struct remote *remote, struct branch *branch,
                                int triangular)
 {
        struct strbuf refspec = STRBUF_INIT;
 
-       if (!branch)
-               die(_(message_detached_head_die), remote->name);
        if (!branch->merge_nr || !branch->merge || !branch->remote_name)
                die(_("The current branch %s has no upstream branch.\n"
                    "To push the current branch and set the remote as upstream, 
use\n"
@@ -156,8 +147,6 @@ 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);
        add_refspec(branch->name);
 }
 
@@ -191,9 +180,23 @@ static int is_workflow_triangular(struct remote *remote)
        return (fetch_remote && fetch_remote != remote);
 }
 
-static void setup_default_push_refspecs(struct remote *remote)
+static const char message_detached_head_die[] =
+       N_("You are not currently on a branch.\n"
+          "To push the history leading to the current (detached HEAD)\n"
+          "state now, use\n"
+          "\n"
+          "    git push %s HEAD:<name-of-remote-branch>\n");
+
+static struct branch *get_current_branch(struct remote *remote)
 {
        struct branch *branch = branch_get(NULL);
+       if (!branch)
+               die(_(message_detached_head_die), remote->name);
+       return branch;
+}
+
+static void setup_default_push_refspecs(struct remote *remote)
+{
        int triangular = is_workflow_triangular(remote);
 
        switch (push_default) {
@@ -208,17 +211,17 @@ static void setup_default_push_refspecs(struct remote 
*remote)
 
        case PUSH_DEFAULT_SIMPLE:
                if (triangular)
-                       setup_push_current(remote, branch);
+                       setup_push_current(remote, get_current_branch(remote));
                else
-                       setup_push_upstream(remote, branch, triangular);
+                       setup_push_upstream(remote, get_current_branch(remote), 
triangular);
                break;
 
        case PUSH_DEFAULT_UPSTREAM:
-               setup_push_upstream(remote, branch, triangular);
+               setup_push_upstream(remote, get_current_branch(remote), 
triangular);
                break;
 
        case PUSH_DEFAULT_CURRENT:
-               setup_push_current(remote, branch);
+               setup_push_current(remote, get_current_branch(remote));
                break;
 
        case PUSH_DEFAULT_NOTHING:
-- 
1.8.4-fc

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to