From ec8460bd91007f0bd7851cd07494d1019a39937f Mon Sep 17 00:00:00 2001 From: Matthieu Moy Date: Wed, 2 Mar 2011 21:12:10 +0100 Subject: push: better error messages when push.default = tracking A common scenario is to create a new branch and push it (checkout -b && push [--set-upstream]). In this case, the user was getting "The current branch %s has no upstream branch.", which doesn't help much. Provide the user a command to push the current branch. To avoid the situation in the future, suggest --set-upstream. While we're there, also improve the error message in the "detached HEAD" case. We mention explicitly "detached HEAD" since this is the keyword to look for in documentations. Signed-off-by: Matthieu Moy Signed-off-by: Junio C Hamano --- builtin/push.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'builtin') diff --git a/builtin/push.c b/builtin/push.c index 31da418cf4..1b493fb5a9 100644 --- a/builtin/push.c +++ b/builtin/push.c @@ -64,14 +64,24 @@ static void set_refspecs(const char **refs, int nr) } } -static void setup_push_upstream(void) +static void setup_push_upstream(struct remote *remote) { struct strbuf refspec = STRBUF_INIT; struct branch *branch = branch_get(NULL); if (!branch) - die("You are not currently on a branch."); + die("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:\n", + remote->name); if (!branch->merge_nr || !branch->merge) - die("The current branch %s has no upstream branch.", + die("The current branch %s has no upstream branch.\n" + "To push the current branch and set the remote as upstream, use\n" + "\n" + " git push --set-upstream %s %s\n", + branch->name, + remote->name, branch->name); if (branch->merge_nr != 1) die("The current branch %s has multiple upstream branches, " @@ -80,7 +90,7 @@ static void setup_push_upstream(void) add_refspec(refspec.buf); } -static void setup_default_push_refspecs(void) +static void setup_default_push_refspecs(struct remote *remote) { switch (push_default) { default: @@ -89,7 +99,7 @@ static void setup_default_push_refspecs(void) break; case PUSH_DEFAULT_UPSTREAM: - setup_push_upstream(); + setup_push_upstream(remote); break; case PUSH_DEFAULT_CURRENT: @@ -175,7 +185,7 @@ static int do_push(const char *repo, int flags) refspec = remote->push_refspec; refspec_nr = remote->push_refspec_nr; } else if (!(flags & TRANSPORT_PUSH_MIRROR)) - setup_default_push_refspecs(); + setup_default_push_refspecs(remote); } errs = 0; if (remote->pushurl_nr) { -- cgit v1.2.3 From a3f5e7a32ec2d885fe6ff7fc14ee91de391f1d72 Mon Sep 17 00:00:00 2001 From: Matthieu Moy Date: Wed, 2 Mar 2011 21:12:11 +0100 Subject: push: better error message when no remote configured Signed-off-by: Matthieu Moy Signed-off-by: Junio C Hamano --- builtin/push.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'builtin') diff --git a/builtin/push.c b/builtin/push.c index 1b493fb5a9..c3c2feb944 100644 --- a/builtin/push.c +++ b/builtin/push.c @@ -157,7 +157,14 @@ static int do_push(const char *repo, int flags) if (!remote) { if (repo) die("bad repository '%s'", repo); - die("No destination configured to push to."); + die("No configured push destination.\n" + "Either specify the URL from the command-line or configure a remote repository using\n" + "\n" + " git remote add \n" + "\n" + "and then push using the remote name\n" + "\n" + " git push \n"); } if (remote->mirror) -- cgit v1.2.3