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

Re: [PATCH] worktree: allow "-" short-hand for @{-1} in add command

From
Junio C Hamano <gitster@pobox.com>
Date
May 27, 2016, 17:52 UTC
Message-ID
<xmqqvb1zqtgp.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<vpqvb1zrh8s.fsf@anie.imag.fr>
Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:
Show 23 quoted lines
> Junio C Hamano <gitster@pobox.com> writes:
>
>> Jordan DE GEA <jordan.de-gea@grenoble-inp.org> writes:
>>
>>> +	branch=$(cd short-hand && git rev-parse --symbolic-full-name HEAD) &&
>>> +	test "$branch" = refs/heads/newbranch &&
>>> +	cd ..
>>
>> If any of the command between "cd short-hand" and "cd .." failed,
>> after correcting the broken &&-chain, the next test will end up
>> running in short-hand directory, which it is not expecting.  A
>> canonical way to avoid this problem is to replace the above with:
>>
>> 	...
>>         git worktree add short-hand - &&
>>         (
>> 		cd short-hand &&
>>                 ...
>>                 test "$branch" = refs/heads/newbranch
>> 	)
>
> Actually, $(...) implicitly does a subshell, so the "cd .." was just
> useless.

You trimmed my message a bit too aggressively while composing your response, and I think that is what ended up confusing you.

Here is what I wrote:
| > +	cd short-hand &&
| > +	test $(git rev-parse --symbolic-full-name HEAD) = "refs/heads/newbranch"
| 
| Broken &&-chain.
| 
| > +	branch=$(cd short-hand && git rev-parse --symbolic-full-name HEAD) &&
| > +	test "$branch" = refs/heads/newbranch &&
| > +	cd ..
| 
| If any of the command between "cd short-hand" and "cd .." failed,
| ...

The problematic "cd short-hand" is the one a few lines above where you started quoting, not the one you saw in the $().

Previous: Matthieu MoyNext: Jordan DE GEA
Message 4 of 7 in “worktree: allow "-" short-hand for @{-1} in add command”
  1. worktree: allow "-" short-hand for @{-1} in add commandJordan DE GEA, May 26, 2016
  2. Junio C HamanoMay 26, 2016
  3. Matthieu MoyMay 27, 2016
  4. Junio C HamanoMay 27, 2016
  5. Jordan DE GEAMay 27, 2016
  6. worktree: allow "-" short-hand for @{-1} in add commandJordan DE GEA, May 27, 2016
  7. Junio C HamanoMay 27, 2016

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.