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

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

From
Arjen Laarhoven <arjen@yaph.org>
Date
Aug 16, 2007, 22:02 UTC
Message-ID
<20070816220217.GH25161@regex.yaph.org>
In-Reply-To
<7v3ayjjnz7.fsf@gitster.siamese.dyndns.org>

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
Previous: Junio C HamanoNext: Uwe Kleine-König
Message 3 of 5 in “t1301-shared-repo.sh: fix 'stat' portability issue”
  1. t1301-shared-repo.sh: fix 'stat' portability issueArjen Laarhoven, Aug 16, 2007
  2. Junio C HamanoAug 16, 2007
  3. Arjen LaarhovenAug 16, 2007
  4. Uwe Kleine-KönigAug 17, 2007
  5. Junio C HamanoAug 17, 2007

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.