threads / patch / 49825

patchpush: change needlessly ambiguous example in error

Subject: [PATCH] push: change needlessly ambiguous example in error

## tl;dr

6 messages between Nov 13, 2018 and Nov 14, 2018. Diffs are folded; open one to read it.

replies: 5people: 3as markdown or json

Ævar Arnfjörð Bjarmason· Nov 13, 2018, 20:39 UTC · lore

Change an example push added in b55e677522 ("push: introduce new push.default mode "simple"", 2012-04-24) to always mean the same thing whether the current setting happens to be "simple" or not.

This error is only emitted under "simple", but message is explaining to the user that they can get two sorts of different behaviors by these two invocations.

Let's use "git push <remote> HEAD" which always means push the current branch name to that remote, instead of "git push <remote> <current-branch-name>" which will do that under "simple", but is not guaranteed to do under "upstream".

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 builtin/push.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Show changes to builtin/push.c +2 −2
diff --git a/builtin/push.c b/builtin/push.c
index d09a42062c..8bb8a0849b 100644
--- a/builtin/push.c
+++ b/builtin/push.c
@@ -173,10 +173,10 @@ static NORETURN int die_push_simple(struct branch *branch, struct remote *remote
 	      "\n"
 	      "To push to the branch of the same name on the remote, use\n"
 	      "\n"
-	      "    git push %s %s\n"
+	      "    git push %s HEAD\n"
 	      "%s"),
 	    remote->name, short_upstream,
-	    remote->name, branch->name, advice_maybe);
+	    remote->name, advice_maybe);
 }
 
 static const char message_detached_head_die[] =
-- 
2.19.1.1182.g4ecb1133ce
Matthieu Moy· Nov 13, 2018, 21:37 UTC · re: Ævar Arnfjörð Bjarmason · lore

Re: [PATCH] push: change needlessly ambiguous example in error

Ævar Arnfjörð Bjarmason" <avarab@gmail.com> wrote:
> Let's use "git push <remote> HEAD" which always means push the current
> branch name to that remote, instead of "git push <remote>
> <current-branch-name>" which will do that under "simple", but is not
> guaranteed to do under "upstream".
Probably a good idea indeed.
One potential objection though: I think many people know
  git push origin master

(not that they necessarily understand it, but I've seen many people talking or asking questions about what "origin master" is)

This "git push origin HEAD" is IMHO less common. It may confuse users. Or users may learn it and be happy thanks to your message. I don't know.

-- 
Matthieu Moy
https://matthieu-moy.fr/
Ævar Arnfjörð Bjarmason· Nov 13, 2018, 21:55 UTC · re: Matthieu Moy · lore

Re: [PATCH] push: change needlessly ambiguous example in error

On Tue, Nov 13 2018, Matthieu Moy wrote:
Show 18 quoted lines
> Ævar Arnfjörð Bjarmason" <avarab@gmail.com> wrote:
>
>> Let's use "git push <remote> HEAD" which always means push the current
>> branch name to that remote, instead of "git push <remote>
>> <current-branch-name>" which will do that under "simple", but is not
>> guaranteed to do under "upstream".
>
> Probably a good idea indeed.
>
> One potential objection though: I think many people know
>
>   git push origin master
>
> (not that they necessarily understand it, but I've seen many people talking
> or asking questions about what "origin master" is)
>
> This "git push origin HEAD" is IMHO less common. It may confuse users.
> Or users may learn it and be happy thanks to your message. I don't know.

I was hoping for the latter. I'm slightly embarrassed to say that for the entire time I've been using git I've been doing:

    # on branch 'topic'
    git push origin topic:topic

Where 'topic' is a tracking branch of 'origin/master' (I use push.default=upstream). I only recently discovered that I could push to 'HEAD" to do the same thing. So one ulterior motive is to make that more prominent.

I was going to add a hint on such invocations saying "you can just use HEAD", but have not found the relevant code yet after some brief searching...

Junio C Hamano· Nov 14, 2018, 04:32 UTC · re: Ævar Arnfjörð Bjarmason · lore

Re: [PATCH] push: change needlessly ambiguous example in error

Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
Show 13 quoted lines
>> This "git push origin HEAD" is IMHO less common. It may confuse users.
>> Or users may learn it and be happy thanks to your message. I don't know.
>
> I was hoping for the latter. I'm slightly embarrassed to say that for
> the entire time I've been using git I've been doing:
>
>     # on branch 'topic'
>     git push origin topic:topic
>
> Where 'topic' is a tracking branch of 'origin/master' (I use
> push.default=upstream). I only recently discovered that I could push to
> 'HEAD" to do the same thing. So one ulterior motive is to make that more
> prominent.

Personally I do not think you should feel embarrassed at all. I didn't know it myself, and I do not recall designing such a behaviour, so I would not be surprised if it is merely what the code right now happens to do. FWIW, I would have expected that a "git push origin HEAD" when HEAD is a symref to a branch 'x' would behave as if "git push origin x" were given, going through the usual simple/upstream/matching etc. dance.

Do we consider the current behaviour useful? Is it documented already and widely known? If the answers are yes/no, of course we should document it, but if they are no/no, it may not be a bad idea to deprecate it and replace it with a saner version (i.e. deref HEAD to branch name and behave the same way as pushing that branch) over time.

Matthieu Moy· Nov 14, 2018, 06:36 UTC · re: Junio C Hamano · lore

Re: [PATCH] push: change needlessly ambiguous example in error

"Junio C Hamano" <gitster@pobox.com> wrote:
> > Where 'topic' is a tracking branch of 'origin/master' (I use
> > push.default=upstream). I only recently discovered that I could push to
> > 'HEAD" to do the same thing. So one ulterior motive is to make that more
> > prominent.
[...]
> Do we consider the current behaviour useful? Is it documented
Yes, since 1750783 (Documentation: more git push examples, 2009-01-26).

It may be an accident that the doc says "to the same name on the remote." since it predates the introduction of push.default, but it does say so and it's the actual behavior.

> already and widely known?
https://stackoverflow.com/questions/14031970/git-push-current-branch-shortcut
458 votes for the answer suggesting it.
-- 
Matthieu Moy
https://matthieu-moy.fr/
Junio C Hamano· Nov 14, 2018, 08:16 UTC · re: Matthieu Moy · lore

Re: [PATCH] push: change needlessly ambiguous example in error

Matthieu Moy <git@matthieu-moy.fr> writes:
Show 20 quoted lines
> "Junio C Hamano" <gitster@pobox.com> wrote:
>
>> > Where 'topic' is a tracking branch of 'origin/master' (I use
>> > push.default=upstream). I only recently discovered that I could push to
>> > 'HEAD" to do the same thing. So one ulterior motive is to make that more
>> > prominent.
> [...]
>> Do we consider the current behaviour useful? Is it documented
>
> Yes, since 1750783 (Documentation: more git push examples, 2009-01-26).
>
> It may be an accident that the doc says "to the same name on the
> remote." since it predates the introduction of push.default, but it
> does say so and it's the actual behavior.
>
>> already and widely known?
>
> https://stackoverflow.com/questions/14031970/git-push-current-branch-shortcut
>
> 458 votes for the answer suggesting it.

OK, that probably is good enough reason to keep the current behaviour and convince ourselves that there is nothing that needs to be done further on this topic.

Thanks.

← back to recent threads