git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Carlos Martín Nieto" <cmn@elego.de>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] branch: make --set-upstream saner without an explicit starting point
Date: Thu, 05 Jul 2012 10:03:09 -0700	[thread overview]
Message-ID: <7vd34arvhu.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <1341480589-1890-1-git-send-email-cmn@elego.de> ("Carlos Martín Nieto"'s message of "Thu, 5 Jul 2012 11:29:49 +0200")

Carlos Martín Nieto <cmn@elego.de> writes:

> The branch command assumes HEAD as the starting point if none is
> specified. This causes --set-upstream to behave unexpectedly if the
> user types
>
>     git branch --set-upstream origin/master
>
> git-branch will assume a second argument of HEAD and create config
> entries for a local branch origin/master to track the current
> branch. This is rarely, if ever, what the user wants to do.
>
> Catch invocations with --set-upstream and only one branch so the
> command above sets up the current branch to track origin's master
> branch.

If you look at the set of management operations "git branch"
(i.e. other than "listing" [*1*]) allows you to do, the first name
on the command line always is the branch that is manipulated for
everything other than the "set upstream" operation.  In that sense,
the current implementation consistently handles command line
arguments with other options, and your patch breaks the consistency
in the UI.

I think it was a mistake that nobody noticed that it is likely that
the operation most often will be done for the current branch and the
usual "give me one branch name to operate on, or I'll operate on the
current branch" command line convention of "git branch" commannd is
not a good fit for it, when "set upstream" feature was added, and
suggested an alternative syntax that avoids the mistake you quoted
above, perhaps something like:

	git branch --set-upstream-to=origin/master [HEAD]

which would have been very clear whose upstream is set to what (with
or without the name of the other branch).  In other words, make the
name "origin/master" *NOT* the first branch name on the command line
in the usual sense, but a parameter to the --set-upstream option, so
that "give me one branch name to operate on, or I'll operate on the
current branch" convention is still kept.

You also broke people who corrected another kind of mistake in this
workflow:

    git checkout frotz
    hack hack
    # ok, shared infrastructure between two branches are
    # sound, and I can build the other topic on top of this
    # state
    git branch nitfol
    # oops, forgot to mark that nitfol is derived on frotz with --track
    git branch --set-upstream nitfol

where the last one meant "git branch --set-upstream nitfol frotz",
to retroactively mark the upstream of the named branch, no?

Even though my instinct tends to agree with your "is rarely, if
ever", I do not think it is sane to change the behaviour of a
command that produced one result without failing to produce
something entirely different like your patch does (it would have
been a different story if an operation that everybody got failure
and did not produce a useful result were updated to produce a useful
result).

Coming from the above observation, while I am sympathetic to your
cause and agree that we would want to do something about it, I am
having a hard time to convince myself that your patch is the best
way to go.

I am not entirely happy with the hypothetical "set-upstream-to"
myself, either.


[Footnote]

*1* The point of "listing" is you do not know the names and asking
the command to produce them, so it is OK to be different.  The "set
upstream" operation in question does not share the excuse to be
different.

  parent reply	other threads:[~2012-07-05 17:03 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-05  9:29 [PATCH] branch: make --set-upstream saner without an explicit starting point Carlos Martín Nieto
2012-07-05  9:42 ` Jeff King
2012-07-05 16:34   ` Carlos Martín Nieto
2012-07-05 17:03 ` Junio C Hamano [this message]
2012-07-05 17:44   ` Junio C Hamano
2012-07-06  7:18     ` Carlos Martín Nieto
2012-07-06  7:29       ` Junio C Hamano
2012-07-06  8:03         ` Carlos Martín Nieto
2012-07-18  5:56           ` Junio C Hamano
2012-07-18 15:33             ` Carlos Martín Nieto
2012-08-16 21:58               ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7vd34arvhu.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=cmn@elego.de \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).