{"thread":{"id":"26624","subject":"[PATCH 1/2] push: better error message when push.default = tracking","startedAt":"2011-02-28T21:14:03Z","lastAt":"2011-03-03T01:43:24Z","messageCount":12,"participants":["Matthieu Moy","Jay Soffian","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"162478","messageId":"1298927645-2716-1-git-send-email-Matthieu.Moy@imag.fr","threadId":"26624","inReplyTo":null,"subject":"[PATCH 0/2] push: better error messages","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@imag.fr","sentAt":"2011-02-28T21:14:03Z","receivedAt":"2011-02-28T21:14:03Z","isPatch":true,"sender":{"key":"git@matthieu-moy.fr","avatar":"https://avatars.githubusercontent.com/u/14709?v=4"},"body":"Since it's likely to become the default in 1.8.0, I've played a bit\nwith \"push.default = tracking\". I was very happy to see that the flow\n\ngit init bla\ngit clone bla\ngit commit\ngit push\n\nwas working like a charm (it required a --all or so the first time),\nbut the \"create a new branch and push it\" is still a bit hard to get\nfor newbies.\n\n[PATCH 1/2] should solve it, by providing a cut-and-paste ready\ncommand to do the push.\n\nWhile I was there, I also improved a bit other messages which gives\n[PATCH 2/2]. I've kept the changes in separate patches, but they may\nbe squashed once reviewed.\n\nMatthieu Moy (2):\n  push: better error message when push.default = tracking\n  push: better error messages for detached HEAD and \"no destination\"\n\n builtin/push.c |   27 ++++++++++++++++++++-------\n 1 files changed, 20 insertions(+), 7 deletions(-)\n\n-- \n1.7.4.1.142.g43604.dirty\n"},{"id":"162476","messageId":"1298927645-2716-2-git-send-email-Matthieu.Moy@imag.fr","threadId":"26624","inReplyTo":"1298927645-2716-1-git-send-email-Matthieu.Moy@imag.fr","subject":"[PATCH 1/2] push: better error message when push.default = tracking","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@imag.fr","sentAt":"2011-02-28T21:14:04Z","receivedAt":"2011-02-28T21:14:04Z","isPatch":true,"sender":{"key":"git@matthieu-moy.fr","avatar":"https://avatars.githubusercontent.com/u/14709?v=4"},"body":"A common scenario is to create a new branch and push it (checkout -b &&\npush [--set-upstream]). In this case, the user was getting \"The current\nbranch %s has no upstream branch.\", which doesn't help much.\n\nProvide the user a command to push the current branch. To avoid the\nsituation in the future, suggest --set-upstream.\n\nSigned-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>\n---\n builtin/push.c |   15 ++++++++++-----\n 1 files changed, 10 insertions(+), 5 deletions(-)\n\ndiff --git a/builtin/push.c b/builtin/push.c\nindex 31da418..210eb36 100644\n--- a/builtin/push.c\n+++ b/builtin/push.c\n@@ -64,14 +64,19 @@ static void set_refspecs(const char **refs, int nr)\n \t}\n }\n \n-static void setup_push_upstream(void)\n+static void setup_push_upstream(struct remote *remote)\n {\n \tstruct strbuf refspec = STRBUF_INIT;\n \tstruct branch *branch = branch_get(NULL);\n \tif (!branch)\n \t\tdie(\"You are not currently on a branch.\");\n \tif (!branch->merge_nr || !branch->merge)\n-\t\tdie(\"The current branch %s has no upstream branch.\",\n+\t\tdie(\"The current branch %s has no upstream branch.\\n\"\n+\t\t    \"To push the current branch and set the remote as upstream, use\\n\"\n+\t\t    \"\\n\"\n+\t\t    \"    git push --set-upstream %s %s\\n\",\n+\t\t    branch->name,\n+\t\t    remote->name,\n \t\t    branch->name);\n \tif (branch->merge_nr != 1)\n \t\tdie(\"The current branch %s has multiple upstream branches, \"\n@@ -80,7 +85,7 @@ static void setup_push_upstream(void)\n \tadd_refspec(refspec.buf);\n }\n \n-static void setup_default_push_refspecs(void)\n+static void setup_default_push_refspecs(struct remote *remote)\n {\n \tswitch (push_default) {\n \tdefault:\n@@ -89,7 +94,7 @@ static void setup_default_push_refspecs(void)\n \t\tbreak;\n \n \tcase PUSH_DEFAULT_UPSTREAM:\n-\t\tsetup_push_upstream();\n+\t\tsetup_push_upstream(remote);\n \t\tbreak;\n \n \tcase PUSH_DEFAULT_CURRENT:\n@@ -175,7 +180,7 @@ static int do_push(const char *repo, int flags)\n \t\t\trefspec = remote->push_refspec;\n \t\t\trefspec_nr = remote->push_refspec_nr;\n \t\t} else if (!(flags & TRANSPORT_PUSH_MIRROR))\n-\t\t\tsetup_default_push_refspecs();\n+\t\t\tsetup_default_push_refspecs(remote);\n \t}\n \terrs = 0;\n \tif (remote->pushurl_nr) {\n-- \n1.7.4.1.142.g43604.dirty\n"},{"id":"162481","messageId":"1298927645-2716-3-git-send-email-Matthieu.Moy@imag.fr","threadId":"26624","inReplyTo":"1298927645-2716-1-git-send-email-Matthieu.Moy@imag.fr","subject":"[PATCH 2/2] push: better error messages for detached HEAD and \"no destination\"","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@imag.fr","sentAt":"2011-02-28T21:14:05Z","receivedAt":"2011-02-28T21:14:05Z","isPatch":true,"sender":{"key":"git@matthieu-moy.fr","avatar":"https://avatars.githubusercontent.com/u/14709?v=4"},"body":"In both cases, give a hint on what to do next. We mention explicitely\n\"detached HEAD\" since this is the keyword to look for in documentations.\n\nSigned-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>\n---\n builtin/push.c |   12 ++++++++++--\n 1 files changed, 10 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/push.c b/builtin/push.c\nindex 210eb36..48fb050 100644\n--- a/builtin/push.c\n+++ b/builtin/push.c\n@@ -69,7 +69,8 @@ static void setup_push_upstream(struct remote *remote)\n \tstruct strbuf refspec = STRBUF_INIT;\n \tstruct branch *branch = branch_get(NULL);\n \tif (!branch)\n-\t\tdie(\"You are not currently on a branch.\");\n+\t\tdie(\"You are not currently on a branch (detached HEAD).\\n\"\n+\t\t    \"Please, checkout the branch you want to push first or specify it on the command line.\");\n \tif (!branch->merge_nr || !branch->merge)\n \t\tdie(\"The current branch %s has no upstream branch.\\n\"\n \t\t    \"To push the current branch and set the remote as upstream, use\\n\"\n@@ -152,7 +153,14 @@ static int do_push(const char *repo, int flags)\n \tif (!remote) {\n \t\tif (repo)\n \t\t\tdie(\"bad repository '%s'\", repo);\n-\t\tdie(\"No destination configured to push to.\");\n+\t\tdie(\"No destination configured to push to.\\n\"\n+\t\t    \"Either specify the URL from the command line or configure a remote repository using\\n\"\n+\t\t    \"\\n\"\n+\t\t    \"    git remote add <name> <url>\\n\"\n+\t\t    \"\\n\"\n+\t\t    \"and then push using the remote name like\\n\"\n+\t\t    \"\\n\"\n+\t\t    \"    git push <name>\\n\");\n \t}\n \n \tif (remote->mirror)\n-- \n1.7.4.1.142.g43604.dirty\n"},{"id":"162487","messageId":"AANLkTim7O4O2UUWzZOrZOWN1zp2iruLYf3+3WMFTi8_5@mail.gmail.com","threadId":"26624","inReplyTo":"1298927645-2716-3-git-send-email-Matthieu.Moy@imag.fr","subject":"Re: [PATCH 2/2] push: better error messages for detached HEAD and \"no destination\"","fromName":"Jay Soffian","fromEmail":"jaysoffian@gmail.com","sentAt":"2011-02-28T22:48:04Z","receivedAt":"2011-02-28T22:48:04Z","isPatch":true,"sender":{"key":"jaysoffian@gmail.com","avatar":"https://avatars.githubusercontent.com/u/155970?v=4"},"body":"On Mon, Feb 28, 2011 at 4:14 PM, Matthieu Moy <Matthieu.Moy@imag.fr> wrote:\n\n> ---\n>  builtin/push.c |   12 ++++++++++--\n>  1 files changed, 10 insertions(+), 2 deletions(-)\n>\n> @@ -152,7 +153,14 @@ static int do_push(const char *repo, int flags)\n>        if (!remote) {\n>                if (repo)\n>                        die(\"bad repository '%s'\", repo);\n> -               die(\"No destination configured to push to.\");\n> +               die(\"No destination configured to push to.\\n\"\n\nThe dangling preposition is awkward. How about:\n\n  No configured push destination.\n\nOr\n\n  Push destination not configured.\n\n> +                   \"Either specify the URL from the command line or configure a remote repository using\\n\"\n\nMaybe \"Either specify the URL explicitly or configure...\"\n\n> +                   \"\\n\"\n> +                   \"    git remote add <name> <url>\\n\"\n> +                   \"\\n\"\n> +                   \"and then push using the remote name like\\n\"\n\ns/like//\n\n> +                   \"\\n\"\n> +                   \"    git push <name>\\n\");\n\nWell, I just bikeshedded that 3 different colors, didn't I? You're welcome. :-)\n\nj.\n"},{"id":"162488","messageId":"vpqwrkjepdo.fsf@bauges.imag.fr","threadId":"26624","inReplyTo":"AANLkTim7O4O2UUWzZOrZOWN1zp2iruLYf3+3WMFTi8_5@mail.gmail.com","subject":"Re: [PATCH 2/2] push: better error messages for detached HEAD and \"no destination\"","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2011-02-28T23:00:19Z","receivedAt":"2011-02-28T23:00:19Z","isPatch":true,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Jay Soffian <jaysoffian@gmail.com> writes:\n\n>> +                   \"Either specify the URL from the command line or configure a remote repository using\\n\"\n>\n> Maybe \"Either specify the URL explicitly or configure...\"\n\nI prefer \"from the command-line\" to \"explicitely\", because \"explicitely\"\ncould mean \"in a configuration file\", or so.\n\n> Well, I just bikeshedded that 3 different colors, didn't I? You're welcome. :-)\n\nThanks, I took the 2 other colors.\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"162493","messageId":"7v8vwzhh5g.fsf@alter.siamese.dyndns.org","threadId":"26624","inReplyTo":"1298927645-2716-3-git-send-email-Matthieu.Moy@imag.fr","subject":"Re: [PATCH 2/2] push: better error messages for detached HEAD and \"no destination\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-02-28T23:29:47Z","receivedAt":"2011-02-28T23:29:47Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Matthieu Moy <Matthieu.Moy@imag.fr> writes:\n\n> In both cases, give a hint on what to do next. We mention explicitely\n> \"detached HEAD\" since this is the keyword to look for in documentations.\n>\n> Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>\n> ---\n>  builtin/push.c |   12 ++++++++++--\n>  1 files changed, 10 insertions(+), 2 deletions(-)\n>\n> diff --git a/builtin/push.c b/builtin/push.c\n> index 210eb36..48fb050 100644\n> --- a/builtin/push.c\n> +++ b/builtin/push.c\n> @@ -69,7 +69,8 @@ static void setup_push_upstream(struct remote *remote)\n>  \tstruct strbuf refspec = STRBUF_INIT;\n>  \tstruct branch *branch = branch_get(NULL);\n>  \tif (!branch)\n> -\t\tdie(\"You are not currently on a branch.\");\n> +\t\tdie(\"You are not currently on a branch (detached HEAD).\\n\"\n> +\t\t    \"Please, checkout the branch you want to push first or specify it on the command line.\");\n\nI agree that it is a good thing to suggest specifying what to push on the\ncommand line, but I don't think this \"checkout first\" is particularly a\ngood advice, as it requires two-step operation that is quite a roundabout\nway of doing what the user wanted to do: a very specific checkout followed\nby re-running of a nonspecific push.\n\n> @@ -152,7 +153,14 @@ static int do_push(const char *repo, int flags)\n>  \tif (!remote) {\n>  \t\tif (repo)\n>  \t\t\tdie(\"bad repository '%s'\", repo);\n> -\t\tdie(\"No destination configured to push to.\");\n> +\t\tdie(\"No destination configured to push to.\\n\"\n> +\t\t    \"Either specify the URL from the command line or configure a remote repository using\\n\"\n> +\t\t    \"\\n\"\n> +\t\t    \"    git remote add <name> <url>\\n\"\n> +\t\t    \"\\n\"\n> +\t\t    \"and then push using the remote name like\\n\"\n> +\t\t    \"\\n\"\n> +\t\t    \"    git push <name>\\n\");\n>  \t}\n\nThis one would be helpful.\n"},{"id":"162523","messageId":"1298970662-25828-1-git-send-email-Matthieu.Moy@imag.fr","threadId":"26624","inReplyTo":"1298927645-2716-1-git-send-email-Matthieu.Moy@imag.fr","subject":"[PATCH 1/2 v2] push: better error messages when push.default = tracking","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@imag.fr","sentAt":"2011-03-01T09:11:01Z","receivedAt":"2011-03-01T09:11:01Z","isPatch":true,"sender":{"key":"git@matthieu-moy.fr","avatar":"https://avatars.githubusercontent.com/u/14709?v=4"},"body":"A common scenario is to create a new branch and push it (checkout -b &&\npush [--set-upstream]). In this case, the user was getting \"The current\nbranch %s has no upstream branch.\", which doesn't help much.\n\nProvide the user a command to push the current branch. To avoid the\nsituation in the future, suggest --set-upstream.\n\nWhile we're there, also improve the error message in the \"detached HEAD\"\ncase. We mention explicitly \"detached HEAD\" since this is the keyword to\nlook for in documentations.\n\nSigned-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>\n---\nCompared to v1, the detached HEAD case joined this patch since it\nbecame semantically linked (requires the \"remote\" extra parameter),\nand doesn't mention the possibility to checkout another branch before\npushing it (cf. Junio).\n\n builtin/push.c |   21 +++++++++++++++------\n 1 files changed, 15 insertions(+), 6 deletions(-)\n\ndiff --git a/builtin/push.c b/builtin/push.c\nindex 31da418..c949187 100644\n--- a/builtin/push.c\n+++ b/builtin/push.c\n@@ -64,14 +64,23 @@ static void set_refspecs(const char **refs, int nr)\n \t}\n }\n \n-static void setup_push_upstream(void)\n+static void setup_push_upstream(struct remote *remote)\n {\n \tstruct strbuf refspec = STRBUF_INIT;\n \tstruct branch *branch = branch_get(NULL);\n \tif (!branch)\n-\t\tdie(\"You are not currently on a branch.\");\n+\t\tdie(\"You are not currently on a branch (detached HEAD).\\n\"\n+\t\t    \"To push a specific branch and set the remote as upstream, use\\n\"\n+\t\t    \"\\n\"\n+\t\t    \"    git push --set-upstream %s <branch-name>\\n\",\n+\t\t    remote->name);\n \tif (!branch->merge_nr || !branch->merge)\n-\t\tdie(\"The current branch %s has no upstream branch.\",\n+\t\tdie(\"The current branch %s has no upstream branch.\\n\"\n+\t\t    \"To push the current branch and set the remote as upstream, use\\n\"\n+\t\t    \"\\n\"\n+\t\t    \"    git push --set-upstream %s %s\\n\",\n+\t\t    branch->name,\n+\t\t    remote->name,\n \t\t    branch->name);\n \tif (branch->merge_nr != 1)\n \t\tdie(\"The current branch %s has multiple upstream branches, \"\n@@ -80,7 +89,7 @@ static void setup_push_upstream(void)\n \tadd_refspec(refspec.buf);\n }\n \n-static void setup_default_push_refspecs(void)\n+static void setup_default_push_refspecs(struct remote *remote)\n {\n \tswitch (push_default) {\n \tdefault:\n@@ -89,7 +98,7 @@ static void setup_default_push_refspecs(void)\n \t\tbreak;\n \n \tcase PUSH_DEFAULT_UPSTREAM:\n-\t\tsetup_push_upstream();\n+\t\tsetup_push_upstream(remote);\n \t\tbreak;\n \n \tcase PUSH_DEFAULT_CURRENT:\n@@ -175,7 +184,7 @@ static int do_push(const char *repo, int flags)\n \t\t\trefspec = remote->push_refspec;\n \t\t\trefspec_nr = remote->push_refspec_nr;\n \t\t} else if (!(flags & TRANSPORT_PUSH_MIRROR))\n-\t\t\tsetup_default_push_refspecs();\n+\t\t\tsetup_default_push_refspecs(remote);\n \t}\n \terrs = 0;\n \tif (remote->pushurl_nr) {\n-- \n1.7.4.1.142.ge03e1\n"},{"id":"162525","messageId":"1298970662-25828-2-git-send-email-Matthieu.Moy@imag.fr","threadId":"26624","inReplyTo":"1298970662-25828-1-git-send-email-Matthieu.Moy@imag.fr","subject":"[PATCH 2/2 v2] push: better error message when no remote configured","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@imag.fr","sentAt":"2011-03-01T09:11:02Z","receivedAt":"2011-03-01T09:11:02Z","isPatch":true,"sender":{"key":"git@matthieu-moy.fr","avatar":"https://avatars.githubusercontent.com/u/14709?v=4"},"body":"\nSigned-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>\n---\n\"No configured push destination.\" (Jay Soffian) and reword.\n\n builtin/push.c |    9 ++++++++-\n 1 files changed, 8 insertions(+), 1 deletions(-)\n\ndiff --git a/builtin/push.c b/builtin/push.c\nindex c949187..b4fba7a 100644\n--- a/builtin/push.c\n+++ b/builtin/push.c\n@@ -156,7 +156,14 @@ static int do_push(const char *repo, int flags)\n \tif (!remote) {\n \t\tif (repo)\n \t\t\tdie(\"bad repository '%s'\", repo);\n-\t\tdie(\"No destination configured to push to.\");\n+\t\tdie(\"No configured push destination.\\n\"\n+\t\t    \"Either specify the URL from the command-line or configure a remote repository using\\n\"\n+\t\t    \"\\n\"\n+\t\t    \"    git remote add <name> <url>\\n\"\n+\t\t    \"\\n\"\n+\t\t    \"and then push using the remote name\\n\"\n+\t\t    \"\\n\"\n+\t\t    \"    git push <name>\\n\");\n \t}\n \n \tif (remote->mirror)\n-- \n1.7.4.1.142.ge03e1\n"},{"id":"162564","messageId":"7vhbbmellx.fsf@alter.siamese.dyndns.org","threadId":"26624","inReplyTo":"1298970662-25828-1-git-send-email-Matthieu.Moy@imag.fr","subject":"Re: [PATCH 1/2 v2] push: better error messages when push.default = tracking","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-03-01T18:34:02Z","receivedAt":"2011-03-01T18:34:02Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Matthieu Moy <Matthieu.Moy@imag.fr> writes:\n\n> diff --git a/builtin/push.c b/builtin/push.c\n> index 31da418..c949187 100644\n> --- a/builtin/push.c\n> +++ b/builtin/push.c\n> @@ -64,14 +64,23 @@ static void set_refspecs(const char **refs, int nr)\n>  \t}\n>  }\n>  \n> -static void setup_push_upstream(void)\n> +static void setup_push_upstream(struct remote *remote)\n>  {\n>  \tstruct strbuf refspec = STRBUF_INIT;\n>  \tstruct branch *branch = branch_get(NULL);\n>  \tif (!branch)\n> -\t\tdie(\"You are not currently on a branch.\");\n> +\t\tdie(\"You are not currently on a branch (detached HEAD).\\n\"\n> +\t\t    \"To push a specific branch and set the remote as upstream, use\\n\"\n> +\t\t    \"\\n\"\n> +\t\t    \"    git push --set-upstream %s <branch-name>\\n\",\n> +\t\t    remote->name);\n\nFor all the other cases covered in this patch, the sequence that lead to\nthis situation would be like this:\n\n\tgit checkout somebranch\n        hack hack hack including commits\n        git push\n\nand it is very clear that the user wants to push the current branch to the\ncorresponding place but the user is getting an error because there is no\n\"corresponding place\" mapping established yet.\n\nI agree \"push --set-upstream\" is a very good advice to give under that\nscenario---it would push the history s/he wanted to push right now, while\nestablishing the mapping for later use, both at the same time with a\nsingle command.\n\nHowever, I don't think that applies to this case with detached HEAD; it is\nmore likely that the user came here this way:\n\n\tgit checkout somebranch~4 ;# the tip 3 are not quite ready\n        hack hack quickfix to do only the sure part of the tip 3 did\n        commit and test\n        git push\n\nMaybe the user needed to quickly push out a minimum fix out of the more\nelaborate work, in which case, what would follow in the workflow is first\nto:\n\n\tgit push origin HEAD:somebranch\n\nin order to unblock others.  This will then be followed by a more\nleisurely:\n\n\tgit rebase HEAD somebranch\n\nto get back to the more elaborate work that is not yet presentable.\n\nIt is not likely that the end user wanted to:\n\n\tgit checkout $not_a_branch_tip ;# detached\n        hack hack hack including commits\n        git push origin an_unrelated_branch\n\nand wanted to omit \"where and what\" part.  We are talking about \"push the\ncurrent branch only to corresponding destination\" people, so if that\nunrelated branch were already ready for external consumption, they would\nhave already pushed it out at the end of the session when they were on\nthat branch (and seen the other advice you are adding in this patch).\n\nThat is why I suggested to advice an explicit push, without checkout nor\nset upstream, in my original review message.  IOW, I think the message\nshould instead suggest:\n\n\tIf you want to push the history leading to the current (detached)\n\tstate now, use\n\n\t    git push $remote HEAD:the-branch-you-want-to-push-to\n"},{"id":"162664","messageId":"1299096731-14194-1-git-send-email-Matthieu.Moy@imag.fr","threadId":"26624","inReplyTo":"7vhbbmellx.fsf@alter.siamese.dyndns.org","subject":"[PATCH 1/2 v3] push: better error messages when push.default = tracking","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@imag.fr","sentAt":"2011-03-02T20:12:10Z","receivedAt":"2011-03-02T20:12:10Z","isPatch":true,"sender":{"key":"git@matthieu-moy.fr","avatar":"https://avatars.githubusercontent.com/u/14709?v=4"},"body":"A common scenario is to create a new branch and push it (checkout -b &&\npush [--set-upstream]). In this case, the user was getting \"The current\nbranch %s has no upstream branch.\", which doesn't help much.\n\nProvide the user a command to push the current branch. To avoid the\nsituation in the future, suggest --set-upstream.\n\nWhile we're there, also improve the error message in the \"detached HEAD\"\ncase. We mention explicitly \"detached HEAD\" since this is the keyword to\nlook for in documentations.\n\nSigned-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>\n---\n\nI applied Junio's suggestion to suggest pushing HEAD in detached HEAD\nstate. I don't care very much either way indeed (and I didn't want to\nmake the message too heavy, just give the user a way to do something).\n\nhope that's OK for inclusion.\n\n builtin/push.c |   22 ++++++++++++++++------\n 1 files changed, 16 insertions(+), 6 deletions(-)\n\ndiff --git a/builtin/push.c b/builtin/push.c\nindex 31da418..1b493fb 100644\n--- a/builtin/push.c\n+++ b/builtin/push.c\n@@ -64,14 +64,24 @@ static void set_refspecs(const char **refs, int nr)\n \t}\n }\n \n-static void setup_push_upstream(void)\n+static void setup_push_upstream(struct remote *remote)\n {\n \tstruct strbuf refspec = STRBUF_INIT;\n \tstruct branch *branch = branch_get(NULL);\n \tif (!branch)\n-\t\tdie(\"You are not currently on a branch.\");\n+\t\tdie(\"You are not currently on a branch.\\n\"\n+\t\t    \"To push the history leading to the current (detached HEAD)\\n\"\n+\t\t    \"state now, use\\n\"\n+\t\t    \"\\n\"\n+\t\t    \"    git push %s HEAD:<name-of-remote-branch>\\n\",\n+\t\t    remote->name);\n \tif (!branch->merge_nr || !branch->merge)\n-\t\tdie(\"The current branch %s has no upstream branch.\",\n+\t\tdie(\"The current branch %s has no upstream branch.\\n\"\n+\t\t    \"To push the current branch and set the remote as upstream, use\\n\"\n+\t\t    \"\\n\"\n+\t\t    \"    git push --set-upstream %s %s\\n\",\n+\t\t    branch->name,\n+\t\t    remote->name,\n \t\t    branch->name);\n \tif (branch->merge_nr != 1)\n \t\tdie(\"The current branch %s has multiple upstream branches, \"\n@@ -80,7 +90,7 @@ static void setup_push_upstream(void)\n \tadd_refspec(refspec.buf);\n }\n \n-static void setup_default_push_refspecs(void)\n+static void setup_default_push_refspecs(struct remote *remote)\n {\n \tswitch (push_default) {\n \tdefault:\n@@ -89,7 +99,7 @@ static void setup_default_push_refspecs(void)\n \t\tbreak;\n \n \tcase PUSH_DEFAULT_UPSTREAM:\n-\t\tsetup_push_upstream();\n+\t\tsetup_push_upstream(remote);\n \t\tbreak;\n \n \tcase PUSH_DEFAULT_CURRENT:\n@@ -175,7 +185,7 @@ static int do_push(const char *repo, int flags)\n \t\t\trefspec = remote->push_refspec;\n \t\t\trefspec_nr = remote->push_refspec_nr;\n \t\t} else if (!(flags & TRANSPORT_PUSH_MIRROR))\n-\t\t\tsetup_default_push_refspecs();\n+\t\t\tsetup_default_push_refspecs(remote);\n \t}\n \terrs = 0;\n \tif (remote->pushurl_nr) {\n-- \n1.7.4.1.176.g6b069.dirty\n"},{"id":"162665","messageId":"1299096731-14194-2-git-send-email-Matthieu.Moy@imag.fr","threadId":"26624","inReplyTo":"1299096731-14194-1-git-send-email-Matthieu.Moy@imag.fr","subject":"[PATCH 2/2 v3] push: better error message when no remote configured","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@imag.fr","sentAt":"2011-03-02T20:12:11Z","receivedAt":"2011-03-02T20:12:11Z","isPatch":true,"sender":{"key":"git@matthieu-moy.fr","avatar":"https://avatars.githubusercontent.com/u/14709?v=4"},"body":"\nSigned-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>\n---\nNo change since v2\n\n builtin/push.c |    9 ++++++++-\n 1 files changed, 8 insertions(+), 1 deletions(-)\n\ndiff --git a/builtin/push.c b/builtin/push.c\nindex 1b493fb..c3c2feb 100644\n--- a/builtin/push.c\n+++ b/builtin/push.c\n@@ -157,7 +157,14 @@ static int do_push(const char *repo, int flags)\n \tif (!remote) {\n \t\tif (repo)\n \t\t\tdie(\"bad repository '%s'\", repo);\n-\t\tdie(\"No destination configured to push to.\");\n+\t\tdie(\"No configured push destination.\\n\"\n+\t\t    \"Either specify the URL from the command-line or configure a remote repository using\\n\"\n+\t\t    \"\\n\"\n+\t\t    \"    git remote add <name> <url>\\n\"\n+\t\t    \"\\n\"\n+\t\t    \"and then push using the remote name\\n\"\n+\t\t    \"\\n\"\n+\t\t    \"    git push <name>\\n\");\n \t}\n \n \tif (remote->mirror)\n-- \n1.7.4.1.176.g6b069.dirty\n"},{"id":"162693","messageId":"7vbp1t9dxf.fsf@alter.siamese.dyndns.org","threadId":"26624","inReplyTo":"1299096731-14194-1-git-send-email-Matthieu.Moy@imag.fr","subject":"Re: [PATCH 1/2 v3] push: better error messages when push.default = tracking","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-03-03T01:43:24Z","receivedAt":"2011-03-03T01:43:24Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Matthieu Moy <Matthieu.Moy@imag.fr> writes:\n\n> I applied Junio's suggestion to suggest pushing HEAD in detached HEAD\n> state. I don't care very much either way indeed (and I didn't want to\n> make the message too heavy, just give the user a way to do something).\n\nIf I were asked my honest opinion, I would have to say that I do not care\ntoo deeply about it either, in the sense that I won't claim that the\nworkflow I thought was most likely to get a new user into the situation to\nget the message on the detached HEAD would be really the most likely one,\nbut I wouldn't spend too much time on coming up with other scenarios\nmyself even though I admit that there may be some other cases that the\nupdated message is not optimal.\n\nBut one thing that I would value (and I would like to see others on the\nlist to also value) is that every change we make is backed by solid\nthinking---at least I would like to see us being able to explain _why_ we\nthought that the message after applying this is better than the old one\ntoday.  Others who will wonder why the message advises the action it\nadvises three months down the road should be able to find out the thinking\nbehind the change, and decide to agree or disagree with it.  Without such\na trace of clear and solid thinking, i.e. \"even though we admit we may not\nhave fully thought things through, at least we considered this and that\nwhen we came up with this solution\", we would end up going circles,\nwasting everybody's time.\n\nIn any case, I've applied them and pushed the results out.  Thanks.\n"}]}