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

Re: [PATCH 10/10] git-submodule.sh: don't use the -a or -b option with the test command

From
Junio C Hamano <gitster@pobox.com>
Date
May 16, 2014, 19:09 UTC
Message-ID
<xmqq7g5la6c6.fsf@gitster.dls.corp.google.com>
In-Reply-To
<20140515155821.GA27279@google.com>
Jonathan Nieder <jrnieder@gmail.com> writes:
Show 12 quoted lines
> Perhaps something like the following would work?
>
> 	tree-wide: convert test -a/-o to && and ||
>
> 	The interaction with unary operators and operator precedence
> 	for && and || are better known than -a and -o, and for that
> 	reason we prefer them.  Replace all existing instances in git
> 	of -a and -o to save readers from the burden of thinking
> 	about such things.
>
> 	Add a check-non-portable-shell.pl to avoid more instances of
> 	test -a and -o arising in the future.

Yeah, the title is certainly better than "-a or -b option" I see above ;-) and a single tree-wide fix may be OK while the tree is quiescent.

I however do think "better known" is much less of an issue than that "-a/-o" is more error prone e.g. 'test -n "$x" -a a = b' is buggy because it does not consider that $x could be "=".

Show 12 quoted lines
> [...]
>> -			test $status = D -o $status = T && echo "$sm_path" && continue
>> +			 ( test $status = D || test $status = T ) && echo "$sm_path" && continue
>
> There's no need for a subshell for this.  Better to use a block:
>
> 			{
> 				test "$status" = D ||
> 				test "$status" = T
> 			} &&
> 			echo "$sm_path" &&
> 			continue
Yes.
Previous: Jonathan Nieder
Message 14 of 14 in “check_bindir: don't use the -a or -b option with the test command”
  1. 01/10 check_bindir: don't use the -a or -b option with the test commandElia Pinto, May 15, 2014
  2. 02/10 contrib/examples/git-clone.sh: don't use the -a or -b option with the test commandElia Pinto, May 15, 2014
  3. 03/10 contrib/examples/git-commit.sh: don't use the -a or -b option with the test commandElia Pinto, May 15, 2014
  4. 04/10 contrib/examples/git-merge.sh: don't use the -a or -b option with the test commandElia Pinto, May 15, 2014
  5. 05/10 contrib/examples/git-repack.sh: don't use the -a or -b option with the test commandElia Pinto, May 15, 2014
  6. 06/10 contrib/examples/git-resolve.sh: don't use the -a or -b option with the test commandElia Pinto, May 15, 2014
  7. 07/10 git-bisect.sh: don't use the -a or -b option with the test commandElia Pinto, May 15, 2014
  8. 08/10 git-mergetool.sh: don't use the -a or -b option with the test commandElia Pinto, May 15, 2014
  9. David AguilarMay 16, 2014
  10. 09/10 git-rebase--interactive.sh: don't use the -a or -b option with the test commandElia Pinto, May 15, 2014
  11. 10/10 git-submodule.sh: don't use the -a or -b option with the test commandElia Pinto, May 15, 2014
  12. Elia PintoMay 15, 2014
  13. Jonathan NiederMay 15, 2014
  14. Junio C HamanoMay 16, 2014

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.