From: Jeff King <peff@peff.net>
To: Felipe Contreras <felipe.contreras@gmail.com>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
Brandon Williams <bwilliams.eng@gmail.com>,
Jacob Keller <jacob.keller@gmail.com>
Subject: Re: [PATCH] refspec: make @ a valid refspec
Date: Tue, 24 Nov 2020 02:42:19 -0500 [thread overview]
Message-ID: <X7y5Wxu1eY4k6753@coredump.intra.peff.net> (raw)
In-Reply-To: <20201122164641.2091160-1-felipe.contreras@gmail.com>
On Sun, Nov 22, 2020 at 10:46:41AM -0600, Felipe Contreras wrote:
> Since commit 9ba89f484e git learned how to push to a remote branch using
> the source @, for example:
>
> git push origin @:master
>
> However, if the right-hand side is missing, the push fails:
>
> git push origin @
Yeah, I think this probably makes sense. I find the "@:master" refspec a
bit weird, but it is a natural consequence of parsing "@" on the LHS as
an arbitrary object to lookup (not a ref).
I did find the implementation a little curious:
> - item->src = xstrndup(lhs, llen);
> + if (llen == 1 && *lhs == '@')
> + item->src = xstrdup("HEAD");
> + else
> + item->src = xstrndup(lhs, llen);
We already know we are parsing the LHS, so why must we expand a bare @,
whereas we do not in "@:master". The answer is that the "@" is not
expanded until later, and parse_refspec() gets unhappy that "@" is also
the implicit value for the RHS.
This also means that:
git push origin @:foo
will now work when "foo" doesn't exist on the remote (if we find no
match on the remote, we guess how it should be fully qualified; one of
our heuristics involves seeing that HEAD points to a branch, and
therefore the other side should be a branch, too).
> It is obvious what is the desired behavior, and allowing the push makes
> things more consistent.
This same code is used by fetch, as well. There "git fetch origin
@:master" does not work at all now. This would make that work (to fetch
the remote HEAD into master), along with "git fetch origin @" (into
FETCH_HEAD only). Both seem sensible, and I cannot think of any other
reasonable meaning for them.
> ---
> refspec.c | 5 ++++-
> t/t5511-refspec.sh | 2 ++
> t/t5516-fetch-push.sh | 9 +++++++++
> 3 files changed, 15 insertions(+), 1 deletion(-)
Would we want to cover the extra cases I mentioned above (@:foo, and the
two fetches), as well?
I wondered if there was a good place to mention this in the refspec
documentation, but it may just be an obvious fallout of the "@ is a
shortcut for HEAD" definition in gitrevisions(7). The only change is
that we're resolving the shortcut sooner so that more code can take
advantage of it.
-Peff
next prev parent reply other threads:[~2020-11-24 7:44 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-22 16:46 [PATCH] refspec: make @ a valid refspec Felipe Contreras
2020-11-24 7:42 ` Jeff King [this message]
2020-11-24 20:01 ` Junio C Hamano
2020-11-24 22:01 ` Felipe Contreras
2020-11-24 22:45 ` Junio C Hamano
2020-11-24 22:52 ` Jacob Keller
2020-11-24 23:14 ` Junio C Hamano
2020-11-24 23:47 ` Jacob Keller
2020-11-25 0:28 ` Felipe Contreras
2020-11-25 0:30 ` Junio C Hamano
2020-11-25 0:14 ` Felipe Contreras
2020-11-25 0:09 ` Felipe Contreras
2020-12-04 22:20 ` Felipe Contreras
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=X7y5Wxu1eY4k6753@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=bwilliams.eng@gmail.com \
--cc=felipe.contreras@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jacob.keller@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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).