threads / patch / 9557

patcht1301-shared-repo.sh: fix 'stat' portability issue

Subject: [PATCH] t1301-shared-repo.sh: fix 'stat' portability issue

## tl;dr

5 messages between Aug 16, 2007 and Aug 17, 2007. Diffs are folded; open one to read it.

replies: 4people: 3as markdown or json

Arjen Laarhoven· Aug 16, 2007, 15:21 UTC · lore

The t1301-shared-repo.sh testscript uses /usr/bin/stat to get the file mode, which isn't portable. There already is a dependency on Perl, so use a Perl one-liner to do the file mode test, but portable.

Signed-off-by: Arjen Laarhoven <arjen@yaph.org>
---
 t/t1301-shared-repo.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Show changes to t/t1301-shared-repo.sh +1 −1
diff --git a/t/t1301-shared-repo.sh b/t/t1301-shared-repo.sh
index bb5f302..888c5fb 100755
--- a/t/t1301-shared-repo.sh
+++ b/t/t1301-shared-repo.sh
@@ -21,7 +21,7 @@ test_expect_success 'update-server-info honors core.sharedRepository' '
 	git commit -m a1 &&
 	umask 0277 &&
 	git update-server-info &&
-	test 444 = $(stat -c %a .git/info/refs)
+	$(perl -e '\''exit !(((stat ".git/info/refs")[2] & 0777) == 0444)'\'')
 '
 
 test_done
-- 
1.5.3.rc4.67.gf9286
Junio C Hamano· Aug 16, 2007, 19:09 UTC · re: Arjen Laarhoven · lore

Re: [PATCH] t1301-shared-repo.sh: fix 'stat' portability issue

Arjen Laarhoven <arjen@yaph.org> writes:
Show 20 quoted lines
> The t1301-shared-repo.sh testscript uses /usr/bin/stat to get the file
> mode, which isn't portable.  There already is a dependency on Perl, so
> use a Perl one-liner to do the file mode test, but portable.
>
> Signed-off-by: Arjen Laarhoven <arjen@yaph.org>
> ---
>  t/t1301-shared-repo.sh |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/t/t1301-shared-repo.sh b/t/t1301-shared-repo.sh
> index bb5f302..888c5fb 100755
> --- a/t/t1301-shared-repo.sh
> +++ b/t/t1301-shared-repo.sh
> @@ -21,7 +21,7 @@ test_expect_success 'update-server-info honors core.sharedRepository' '
>  	git commit -m a1 &&
>  	umask 0277 &&
>  	git update-server-info &&
> -	test 444 = $(stat -c %a .git/info/refs)
> +	$(perl -e '\''exit !(((stat ".git/info/refs")[2] & 0777) == 0444)'\'')
>  '
Why is this inside a $()?
I am just wondering if this is more portable and readable...
	... &&
	current="$(ls -l .git/info/refs)" &&
	case "$current" in
        -r--r--r--*)
        	: happy
                ;;
	*)
        	echo Oops, .git/info/refs is not 0444
                false
                ;;
	esac
Arjen Laarhoven· Aug 16, 2007, 22:02 UTC · re: Junio C Hamano · lore

Re: [PATCH] t1301-shared-repo.sh: fix 'stat' portability issue

The t1301-shared-repo.sh testscript uses /usr/bin/stat to get the file mode, which isn't portable. Implement the test in shell using 'ls' as shown by Junio.

Signed-off-by: Arjen Laarhoven <arjen@yaph.org>
---
 t/t1301-shared-repo.sh |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)
Show changes to t/t1301-shared-repo.sh +10 −1
diff --git a/t/t1301-shared-repo.sh b/t/t1301-shared-repo.sh
index bb5f302..6bfe19a 100755
--- a/t/t1301-shared-repo.sh
+++ b/t/t1301-shared-repo.sh
@@ -21,7 +21,16 @@ test_expect_success 'update-server-info honors core.sharedRepository' '
 	git commit -m a1 &&
 	umask 0277 &&
 	git update-server-info &&
-	test 444 = $(stat -c %a .git/info/refs)
+	actual="$(ls -l .git/info/refs)" &&
+	case "$actual" in
+	-r--r--r--*)
+		: happy
+		;;
+	*)
+		echo Oops, .git/info/refs is not 0444
+		false
+		;;
+	esac
 '
 
 test_done
-- 
1.5.3.rc4.67.gf9286

> > -	test 444 = $(stat -c %a .git/info/refs)
> > +	$(perl -e '\''exit !(((stat ".git/info/refs")[2] & 0777) == 0444)'\'')
> >  '
> 
> Why is this inside a $()?

Bah.

> I am just wondering if this is more portable and readable...
> 
> 	... &&
> 	current="$(ls -l .git/info/refs)" &&
> 	case "$current" in
>         -r--r--r--*)
>         	: happy
>                 ;;
> 	*)
>         	echo Oops, .git/info/refs is not 0444
>                 false
>                 ;;
> 	esac
Uwe Kleine-König· Aug 17, 2007, 12:48 UTC · re: Arjen Laarhoven · lore

Re: [PATCH] t1301-shared-repo.sh: fix 'stat' portability issue

Hello,
Show 10 quoted lines
> +	actual="$(ls -l .git/info/refs)" &&
> +	case "$actual" in
> +	-r--r--r--*)
> +		: happy
> +		;;
> +	*)
> +		echo Oops, .git/info/refs is not 0444
> +		false
> +		;;
> +	esac

Don't know if this matters here, but a while ago I learnd that if I really need to parse output of ls -l, then I should set LANG=C and LC_ALL=C. I didn't see any breakage when LS_COLORS is set, but maybe you want to reset that, too?

Best regards Uwe

-- 
Uwe Kleine-König

http://www.google.com/search?q=2004+in+roman+numerals
Junio C Hamano· Aug 17, 2007, 23:37 UTC · re: Uwe Kleine-König · lore

Re: [PATCH] t1301-shared-repo.sh: fix 'stat' portability issue

Uwe Kleine-König <ukleinek@informatik.uni-freiburg.de> writes:
> Don't know if this matters here, but a while ago I learnd that if I
> really need to parse output of ls -l, then I should set LANG=C and
> LC_ALL=C.  I didn't see any breakage when LS_COLORS is set, but maybe
> you want to reset that, too?

Yeah, I usually try to be defensive and I know LANG/LC_ALL matters if you want to parse "ls -l" for dates, but it should not matter for perm bits. If LS_COLORS is honoured when it is outputting to non-terminal (as in var=`ls`), it's severely broken, so...

← back to recent threads