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

Re: test z$foo = zbar (and Re: [PATCH 1/3] bisect: relax requirement for a working tree.)

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Aug 7, 2011, 14:10 UTC
Message-ID
<20110807141035.GC10748@elie.gateway.2wire.net>
In-Reply-To
<201108071505.00762.stefano.lattarini@gmail.com>
Stefano Lattarini wrote:
>   $ /usr/xpg4/bin/sh -c 'test -z ")"'; echo $?
>   0

Yikes, thanks for pointing it out. I wonder if we should introduce a sane_test function, like this.

 empty_string () {
	case $* in
	?*)
		return 1 ;;
	*)
		return 0 ;;
	esac
 }
 # This is like "test", but:
 #  - it only implements a minimal subset of the functionality
 #  - it works around shells that cannot cope with parentheses as
 #    parameters to some operators, like ksh before 2008:
 #
 #	$ /usr/xpg4/bin/sh -c 'test -z ")"'; echo $?
 #	0
 sane_test () {
	# implied -n
	test "$#" = 0 && set -- -n ""
	test "$#" = 1 && set -- -n "$1"
	test "$#" = 2 && test "z$1" = z! && set -- -z "$2"
	test "$#" -le 4 || 
	case $# in
	2)
		case $1 in
		-z)
			empty_string "$2" ;;
		-n)
			! empty_string "$2" ;;
		-*)
			test "$@" ;;
		*)
			die "sane_test: unrecognized unary operator $1" ;;
		esac
		;;
	3)
		case $2 in
		= | !=)
			test "z$1" "$2" "z$3" ;;
		-eq | -lt | -gt | -le | -ge)
			test "$@" ;;
		*)
			die "sane_test: unrecognized binary operator $2" ;;
		esac
		;;
	4)
		test "z$1" = z! ||
		die "sane_test: unrecognized 4-argument test (not a negation)"
		shift
		! sane_test "$@"
		;;
	*)
		die 'sane_test: too many arguments'
		;;
	esac
 }
Previous: Stefano LattariniNext: Jon Seymour
Message 6 of 12 in “bisect: add support for bisecting bare repositories”
  1. 0/3 bisect: add support for bisecting bare repositoriesJon Seymour, Aug 7, 2011
  2. 1/3 bisect: relax requirement for a working tree.Jon Seymour, Aug 7, 2011
  3. test z$foo = zbar (and Re: [PATCH 1/3] bisect: relax requirement for a working tree.)Jonathan Nieder, Aug 7, 2011
  4. Jon SeymourAug 7, 2011
  5. Stefano LattariniAug 7, 2011
  6. Jonathan NiederAug 7, 2011
  7. Jon SeymourAug 7, 2011
  8. 2/3 bisect: add tests for bisection on bare repositoriesJon Seymour, Aug 7, 2011
  9. Jonathan NiederAug 7, 2011
  10. Jon SeymourAug 7, 2011
  11. 3/3 bisect: document that --no-checkout is the default for bare repositoriesJon Seymour, Aug 7, 2011
  12. Jonathan NiederAug 7, 2011

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.