git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/2 v2] push: better error messages when push.default = tracking

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 1, 2011, 18:34 UTC
Message-ID
<7vhbbmellx.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1298970662-25828-1-git-send-email-Matthieu.Moy@imag.fr>
Matthieu Moy <Matthieu.Moy@imag.fr> writes:
Show 20 quoted lines
> diff --git a/builtin/push.c b/builtin/push.c
> index 31da418..c949187 100644
> --- a/builtin/push.c
> +++ b/builtin/push.c
> @@ -64,14 +64,23 @@ 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 (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);

For all the other cases covered in this patch, the sequence that lead to this situation would be like this:

	git checkout somebranch
        hack hack hack including commits
        git push

and it is very clear that the user wants to push the current branch to the corresponding place but the user is getting an error because there is no "corresponding place" mapping established yet.

I agree "push --set-upstream" is a very good advice to give under that scenario---it would push the history s/he wanted to push right now, while establishing the mapping for later use, both at the same time with a single command.

However, I don't think that applies to this case with detached HEAD; it is more likely that the user came here this way:

	git checkout somebranch~4 ;# the tip 3 are not quite ready
        hack hack quickfix to do only the sure part of the tip 3 did
        commit and test
        git push

Maybe the user needed to quickly push out a minimum fix out of the more elaborate work, in which case, what would follow in the workflow is first to:

	git push origin HEAD:somebranch

in order to unblock others. This will then be followed by a more leisurely:

	git rebase HEAD somebranch
to get back to the more elaborate work that is not yet presentable.
It is not likely that the end user wanted to:
	git checkout $not_a_branch_tip ;# detached
        hack hack hack including commits
        git push origin an_unrelated_branch

and wanted to omit "where and what" part. We are talking about "push the current branch only to corresponding destination" people, so if that unrelated branch were already ready for external consumption, they would have already pushed it out at the end of the session when they were on that branch (and seen the other advice you are adding in this patch).

That is why I suggested to advice an explicit push, without checkout nor set upstream, in my original review message. IOW, I think the message should instead suggest:

	If you want to push the history leading to the current (detached)
	state now, use
	    git push $remote HEAD:the-branch-you-want-to-push-to
Previous: Matthieu MoyNext: Matthieu Moy
Message 9 of 12 in “push: better error messages”
  1. 0/2 push: better error messagesMatthieu Moy, Feb 28, 2011
  2. 1/2 push: better error message when push.default = trackingMatthieu Moy, Feb 28, 2011
  3. 2/2 push: better error messages for detached HEAD and "no destination"Matthieu Moy, Feb 28, 2011
  4. Jay SoffianFeb 28, 2011
  5. Matthieu MoyFeb 28, 2011
  6. Junio C HamanoFeb 28, 2011
  7. 1/2 push: better error messages when push.default = trackingMatthieu Moy, Mar 1, 2011
  8. 2/2 push: better error message when no remote configuredMatthieu Moy, Mar 1, 2011
  9. Junio C HamanoMar 1, 2011
  10. 1/2 push: better error messages when push.default = trackingMatthieu Moy, Mar 2, 2011
  11. 2/2 push: better error message when no remote configuredMatthieu Moy, Mar 2, 2011
  12. Junio C HamanoMar 3, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.