From: Matthieu Moy <Matthieu.Moy@univ-lyon1.fr>
To: Dannier Castro L <danniercl@gmail.com>
Cc: git <git@vger.kernel.org>, Junio C Hamano <gitster@pobox.com>,
Matthieu Moy <Matthieu.Moy@imag.fr>,
jrnieder@gmail.com, bmwill@google.com
Subject: Re: [PATCH 1/3] checkout.c: add strict usage of -- before file_path
Date: Sun, 13 May 2018 18:52:31 +0200 (CEST) [thread overview]
Message-ID: <191675463.13930902.1526230351223.JavaMail.zimbra@inria.fr> (raw)
In-Reply-To: <9e3a36eea5d34dc2941560b96046dc27@BPMBX2013-01.univ-lyon1.fr>
"Dannier Castro L" <danniercl@gmail.com> wrote:
> Currently, <checkout> is a complex command able to handle both
> branches and files without any distintion other than their names,
> taking into account that depending on the type (branch or file),
> the functionality is completely different, the easier example:
>
> $ git checkout <branch> # Switch from current branch to <branch>.
> $ git checkout <file> # Restore <file> from HEAD, discarding
> # changes if it's necessary.
> $ git checkout -- <file> # The same as the last one, only with an
> # useless '--'.
It's not really "useless".
In the first two commands you give, git guesses whether the first
argument is a branch or a file. In the 3rd, the -- indicates that it
must be a file.
> For GIT new users,
Nit: we write Git (for the system) or git (for the command-line tool),
but usually avoid the all-caps GIT.
> The solution consists in detect '--' into command args, allowing
> the discard of changes and considering the following names as
> file paths, otherwise, they are branch names.
This answers the "what?" question, but does not explain why this is a
good change. A good commit message should focus more on the "why?"
question.
While I agree that "git checkout" is a complex command, and would love
to see a simpler syntax at least for the most common operations, I do
not think that this is a good change for several reasons:
* If one considers that this "--" syntax is an issue, then this patch
is a very partial solution only. Many other commands use the same
convention (for example "git log <commit>" Vs "git log -- <file>"),
so changing only one makes git less consistent. Also, note that this
"--" convention is not git-specific. Try "touch --help" and "touch
-- --help" for example.
* This breaks backward compatibility. People used to "git checkout
<file>" won't be able to use it anymore. Scripts using it will
break. Git avoids breaking backward compatibility, and when there's
a good reason to do so we need a good transition plan. In this case,
one possible plan would be to 1) issue a warning whenever "git
checkout <file>" is used for a while, and then 2) actually forbid
it. But following this path, I don't think step 2) would actually be
useful.
> @@ -928,6 +931,7 @@ static int parse_branchname_arg(int argc, const char **argv,
> dash_dash_pos = -1;
> for (i = 0; i < argc; i++) {
> if (!strcmp(argv[i], "--")) {
> + opts->discard_changes = 1;
> dash_dash_pos = i;
Wouldn't "dash_dash_pos != -1" be enough to know whether there's a --?
--
Matthieu Moy
https://matthieu-moy.fr/
next parent reply other threads:[~2018-05-13 16:52 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <9e3a36eea5d34dc2941560b96046dc27@BPMBX2013-01.univ-lyon1.fr>
2018-05-13 16:52 ` Matthieu Moy [this message]
2018-05-13 2:23 [PATCH 1/3] checkout.c: add strict usage of -- before file_path Dannier Castro L
2018-05-13 6:03 ` Duy Nguyen
2018-05-14 1:51 ` Junio C Hamano
2018-05-13 21:02 ` Kevin Daudt
2018-05-14 14:52 ` Duy Nguyen
2018-05-14 15:43 ` Duy Nguyen
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=191675463.13930902.1526230351223.JavaMail.zimbra@inria.fr \
--to=matthieu.moy@univ-lyon1.fr \
--cc=Matthieu.Moy@imag.fr \
--cc=bmwill@google.com \
--cc=danniercl@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jrnieder@gmail.com \
/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).