git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] t1301-shared-repo.sh: fix 'stat' portability issue
@ 2007-08-16 15:21 Arjen Laarhoven
  2007-08-16 19:09 ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Arjen Laarhoven @ 2007-08-16 15:21 UTC (permalink / raw)
  To: Junio C Hamano, Git Mailing List; +Cc: Arjen Laarhoven

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)'\'')
 '
 
 test_done
-- 
1.5.3.rc4.67.gf9286

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] t1301-shared-repo.sh: fix 'stat' portability issue
  2007-08-16 15:21 [PATCH] t1301-shared-repo.sh: fix 'stat' portability issue Arjen Laarhoven
@ 2007-08-16 19:09 ` Junio C Hamano
  2007-08-16 22:02   ` Arjen Laarhoven
  0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2007-08-16 19:09 UTC (permalink / raw)
  To: Arjen Laarhoven; +Cc: Git Mailing List

Arjen Laarhoven <arjen@yaph.org> writes:

> 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] t1301-shared-repo.sh: fix 'stat' portability issue
  2007-08-16 19:09 ` Junio C Hamano
@ 2007-08-16 22:02   ` Arjen Laarhoven
  2007-08-17 12:48     ` Uwe Kleine-König
  0 siblings, 1 reply; 5+ messages in thread
From: Arjen Laarhoven @ 2007-08-16 22:02 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git Mailing List

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(-)

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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] t1301-shared-repo.sh: fix 'stat' portability issue
  2007-08-16 22:02   ` Arjen Laarhoven
@ 2007-08-17 12:48     ` Uwe Kleine-König
  2007-08-17 23:37       ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Uwe Kleine-König @ 2007-08-17 12:48 UTC (permalink / raw)
  To: Arjen Laarhoven; +Cc: Junio C Hamano, Git Mailing List

Hello,

> +	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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] t1301-shared-repo.sh: fix 'stat' portability issue
  2007-08-17 12:48     ` Uwe Kleine-König
@ 2007-08-17 23:37       ` Junio C Hamano
  0 siblings, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2007-08-17 23:37 UTC (permalink / raw)
  To: Uwe Kleine-König; +Cc: Arjen Laarhoven, Git Mailing List

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...

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-08-17 23:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-16 15:21 [PATCH] t1301-shared-repo.sh: fix 'stat' portability issue Arjen Laarhoven
2007-08-16 19:09 ` Junio C Hamano
2007-08-16 22:02   ` Arjen Laarhoven
2007-08-17 12:48     ` Uwe Kleine-König
2007-08-17 23:37       ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).