Since it's likely to become the default in 1.8.0, I've played a bit
with "push.default = tracking". I was very happy to see that the flow
git init bla
git clone bla
git commit
git push
was working like a charm (it required a --all or so the first time),
but the "create a new branch and push it" is still a bit hard to get
for newbies.
[PATCH 1/2] should solve it, by providing a cut-and-paste ready
command to do the push.
While I was there, I also improved a bit other messages which gives
[PATCH 2/2]. I've kept the changes in separate patches, but they may
be squashed once reviewed.
Matthieu Moy (2):
push: better error message when push.default = tracking
push: better error messages for detached HEAD and "no destination"
builtin/push.c | 27 ++++++++++++++++++++-------
1 files changed, 20 insertions(+), 7 deletions(-)
--
1.7.4.1.142.g43604.dirty
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.
Signed-off-by: Matthieu Moy <redacted>
---
builtin/push.c | 15 ++++++++++-----
1 files changed, 10 insertions(+), 5 deletions(-)
@@ -64,14 +64,19 @@ static void set_refspecs(const char **refs, int nr)}}-staticvoidsetup_push_upstream(void)+staticvoidsetup_push_upstream(structremote*remote){structstrbufrefspec=STRBUF_INIT;structbranch*branch=branch_get(NULL);if(!branch)die("You are not currently on a branch.");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, "
In both cases, give a hint on what to do next. We mention explicitely
"detached HEAD" since this is the keyword to look for in documentations.
Signed-off-by: Matthieu Moy <redacted>
---
builtin/push.c | 12 ++++++++++--
1 files changed, 10 insertions(+), 2 deletions(-)
@@ -69,7 +69,8 @@ static void setup_push_upstream(struct remote *remote)structstrbufrefspec=STRBUF_INIT;structbranch*branch=branch_get(NULL);if(!branch)-die("You are not currently on a branch.");+die("You are not currently on a branch (detached HEAD).\n"+"Please, checkout the branch you want to push first or specify it on the command line.");if(!branch->merge_nr||!branch->merge)die("The current branch %s has no upstream branch.\n""To push the current branch and set the remote as upstream, use\n"
@@ -152,7 +153,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 destination configured to push to.\n"+"Either specify the URL from the command line or configure a remote repository using\n"+"\n"+" git remote add <name> <url>\n"+"\n"+"and then push using the remote name like\n"+"\n"+" git push <name>\n");}if(remote->mirror)
From: Junio C Hamano <hidden> Date: 2016-06-15 22:50:41
Matthieu Moy [off-list ref] writes:
quoted hunk
In both cases, give a hint on what to do next. We mention explicitely
"detached HEAD" since this is the keyword to look for in documentations.
Signed-off-by: Matthieu Moy <redacted>
---
builtin/push.c | 12 ++++++++++--
1 files changed, 10 insertions(+), 2 deletions(-)
@@ -69,7 +69,8 @@ static void setup_push_upstream(struct remote *remote)structstrbufrefspec=STRBUF_INIT;structbranch*branch=branch_get(NULL);if(!branch)-die("You are not currently on a branch.");+die("You are not currently on a branch (detached HEAD).\n"+"Please, checkout the branch you want to push first or specify it on the command line.");
I agree that it is a good thing to suggest specifying what to push on the
command line, but I don't think this "checkout first" is particularly a
good advice, as it requires two-step operation that is quite a roundabout
way of doing what the user wanted to do: a very specific checkout followed
by re-running of a nonspecific push.
quoted hunk
@@ -152,7 +153,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 destination configured to push to.\n"+ "Either specify the URL from the command line or configure a remote repository using\n"+ "\n"+ " git remote add <name> <url>\n"+ "\n"+ "and then push using the remote name like\n"+ "\n"+ " git push <name>\n"); }
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 <redacted>
---
Compared to v1, the detached HEAD case joined this patch since it
became semantically linked (requires the "remote" extra parameter),
and doesn't mention the possibility to checkout another branch before
pushing it (cf. Junio).
builtin/push.c | 21 +++++++++++++++------
1 files changed, 15 insertions(+), 6 deletions(-)
@@ -64,14 +64,23 @@ static void set_refspecs(const char **refs, int nr)}}-staticvoidsetup_push_upstream(void)+staticvoidsetup_push_upstream(structremote*remote){structstrbufrefspec=STRBUF_INIT;structbranch*branch=branch_get(NULL);if(!branch)-die("You are not currently on a branch.");+die("You are not currently on a branch (detached HEAD).\n"+"To push a specific branch and set the remote as upstream, use\n"+"\n"+" git push --set-upstream %s <branch-name>\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, "
@@ -156,7 +156,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 <name> <url>\n"+"\n"+"and then push using the remote name\n"+"\n"+" git push <name>\n");}if(remote->mirror)