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

Re: [PATCH v3 3/3] refspec: make @ a synonym of HEAD

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 25, 2020, 23:53 UTC
Message-ID
<xmqqpn41at89.fsf@gitster.c.googlers.com>
In-Reply-To
<20201125233443.63130-4-felipe.contreras@gmail.com>
Felipe Contreras <felipe.contreras@gmail.com> writes:
Show 20 quoted lines
> 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 @
>
> It is obvious what is the desired behavior, and allowing the push makes
> things more consistent.
>
> Additionally, @:master now has the same semantics as HEAD:master.
>
> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
> ---
>  refspec.c             |   5 +-
>  t/t5511-refspec.sh    |   2 +
>  t/t5516-fetch-push.sh | 106 ++++++++++++++++++++++--------------------
>  3 files changed, 61 insertions(+), 52 deletions(-)

Sorry, but I cannot queue this version in today's pushout due to time constraints.

> -test_expect_success 'push with HEAD' '
> +for head in HEAD @; do
Style: replace "; " with a LF.
> +	test_expect_success "push with $head" "

Don't open the test body with double-quote; keep using the original single-quote and the reference to $head is resolved while running the test, not when the test body is formulated before eval'ed.

Two benefits are
 - (obvious) you do not need extra quoting, e.g. \$the_commit etc.
 - in this case it does not matter, but it works intuitively when
   the variable has $IFS whitespace in it.  If you write in the test
   body that is enclosed in a single-quote pair,
		git push testrepo "$head"
   would correctly give the contents of variable head as a single
   element in argv[] of "git push".
For the latter reason, it is encouraged to make it a habit to do so.
Thanks.
Previous: Felipe ContrerasNext: Junio C Hamano
Message 5 of 7 in “refspec: make @ a synonym of HEAD”
  1. 0/3 refspec: make @ a synonym of HEADFelipe Contreras, Nov 25, 2020
  2. 1/3 tests: push: improve cleanup of HEAD testsFelipe Contreras, Nov 25, 2020
  3. 2/3 tests: push: trivial cleanupFelipe Contreras, Nov 25, 2020
  4. 3/3 refspec: make @ a synonym of HEADFelipe Contreras, Nov 25, 2020
  5. Junio C HamanoNov 25, 2020
  6. Junio C HamanoNov 25, 2020
  7. Johannes SchindelinNov 27, 2020

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.