t1301-shared-repo.sh: fix 'stat' portability issue
PATCH 1/1 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. There already is a dependency on Perl, so use a Perl one-liner to do the file mode test, but portable.
--- t/t1301-shared-repo.sh | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
t/t1301-shared-repo.sh +1 -1
@@ -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
Signature · 1 line
1.5.3.rc4.67.gf9286
Quoted 14 lines · Arjen Laarhoven
The
t1301-shared-repo.shtestscript uses/usr/bin/statto 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 <[email protected]>--- t/t1301-shared-repo.sh | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)t/t1301-shared-repo.sh +0
-0
t/t1301-shared-repo.sh test_expect_success 'update-server-info honors core.sharedRepository' ' · line 25
Quoted 6 lines
t/t1301-shared-repo.sh +1
-1@@ -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
;;
esacThe 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.
--- t/t1301-shared-repo.sh | 11 ++++++++++- 1 files changed, 10 insertions(+), 1 deletions(-)
t/t1301-shared-repo.sh +10 -1
@@ -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
Signature · 1 line
1.5.3.rc4.67.gf9286
Quoted 5 lines
Review
Quoted 3 lines
(quoted diff) +1
-1- test 444 = $(stat -c %a .git/info/refs) + $(perl -e '\''exit !(((stat ".git/info/refs")[2] & 0777) == 0444)'\'') 'Why is this inside a $()?
Bah.
Quoted 13 lines
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
Hello,
t/t1301-shared-repo.sh test_expect_success 'update-server-info honors core.sharedRepository' ' · line 33
Quoted 10 lines
t/t1301-shared-repo.sh +10
-0+ 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
Signature · 3 lines
Uwe Kleine-König http://www.google.com/search?q=2004+in+roman+numerals
Quoted 4 lines · Uwe Kleine-König
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_COLORSis 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...