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

Re: [PATCH] t0300-credentials: Word around a solaris /bin/sh bug

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Feb 2, 2012, 21:11 UTC
Message-ID
<20120202211146.GC19520@burratino>
In-Reply-To
<vpq62fp3r15.fsf@bauges.imag.fr>
Matthieu Moy wrote:
> Jonathan Nieder <jrnieder@gmail.com> writes:
Show 7 quoted lines
>> 	(
>> 		IFS==
>> 		while read key value
>> 		do
>> 			...
>> 		done
>> 	)
[...]
> I don't think so since the "..." contains
>
>     eval "$key=$value"
Oh, whoops.  Thanks for noticing.

Here's an updated patch, for amusement value. No functional change intended. I don't think it's actually worth applying unless people actively working on this file find the result easier to work with.

-- >8 --
Subject: t0300 (credentials): shell scripting style cleanups

As Ben noticed, the helper used by this test script assigns a temporary value to IFS while calling the "read" builtin, which in ancient shells causes the value to leak into the environment and affect later code in the same script. Explicitly save and restore IFS to avoid rekindling old memories.

While at it, put the "do" associated to a "while" statement on its own line to match the house style and define helper scripts in the test data section above all test assertions so the "setup" test itself is less cluttered and we can worry a little less about quoting issues.

Inspired-by: Ben Walton <bwalton@artsci.utoronto.ca>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 t/t0300-credentials.sh |   36 ++++++++++++++++++++----------------
 1 files changed, 20 insertions(+), 16 deletions(-)
diff --git a/t/t0300-credentials.sh b/t/t0300-credentials.sh
index edf65478..780d5dcb 100755
--- a/t/t0300-credentials.sh
+++ b/t/t0300-credentials.sh
@@ -4,33 +4,37 @@ test_description='basic credential helper tests'
 . ./test-lib.sh
 . "$TEST_DIRECTORY"/lib-credential.sh
 
-test_expect_success 'setup helper scripts' '
-	cat >dump <<-\EOF &&
+cat >dump <<-\EOF
 	whoami=`echo $0 | sed s/.*git-credential-//`
 	echo >&2 "$whoami: $*"
-	while IFS== read key value; do
+	save_IFS=$IFS
+	IFS==
+	while read key value
+	do
 		echo >&2 "$whoami: $key=$value"
 		eval "$key=$value"
 	done
-	EOF
+	IFS=$save_IFS
+EOF
 
-	cat >git-credential-useless <<-EOF &&
+cat >git-credential-useless <<-EOF
 	#!$SHELL_PATH
 	. ./dump
 	exit 0
-	EOF
+EOF
+
+cat >git-credential-verbatim <<-EOF
+	#!$SHELL_PATH
+	user=\$1; shift
+	pass=\$1; shift
+	. ./dump
+	test -z "\$user" || echo username=\$user
+	test -z "\$pass" || echo password=\$pass
+EOF
+
+test_expect_success setup '
 	chmod +x git-credential-useless &&
-
-	echo "#!$SHELL_PATH" >git-credential-verbatim &&
-	cat >>git-credential-verbatim <<-\EOF &&
-	user=$1; shift
-	pass=$1; shift
-	. ./dump
-	test -z "$user" || echo username=$user
-	test -z "$pass" || echo password=$pass
-	EOF
 	chmod +x git-credential-verbatim &&
-
 	PATH="$PWD:$PATH"
 '
 
-- 
1.7.9
Previous: Matthieu Moy
Message 22 of 22 in “t0300-credentials: Word around a solaris /bin/sh bug”
  1. t0300-credentials: Word around a solaris /bin/sh bugBen Walton, Feb 2, 2012
  2. Frans KlaverFeb 2, 2012
  3. Ben WaltonFeb 2, 2012
  4. Jeff KingFeb 2, 2012
  5. Junio C HamanoFeb 3, 2012
  6. Jeff KingFeb 3, 2012
  7. Ben WaltonFeb 3, 2012
  8. Junio C HamanoFeb 3, 2012
  9. Jeff KingFeb 3, 2012
  10. Junio C HamanoFeb 3, 2012
  11. Jeff KingFeb 3, 2012
  12. Ben WaltonFeb 3, 2012
  13. Junio C HamanoFeb 3, 2012
  14. Jeff KingFeb 3, 2012
  15. Jeff KingFeb 4, 2012
  16. 1/2 tests: add write_script helper functionJeff King, Feb 4, 2012
  17. 2/2 t0300: use write_script helperJeff King, Feb 4, 2012
  18. Junio C HamanoFeb 4, 2012
  19. Jeff KingFeb 4, 2012
  20. Jonathan NiederFeb 2, 2012
  21. Matthieu MoyFeb 2, 2012
  22. Jonathan NiederFeb 2, 2012

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.