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

Re: Hardcoded #!/bin/sh in t5532 causes problems on Solaris

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 10, 2016, 19:01 UTC
Message-ID
<xmqq37qtthit.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<xmqqmvp2ti20.fsf@gitster.mtv.corp.google.com>
Junio C Hamano <gitster@pobox.com> writes:
Show 29 quoted lines
> I looked at
>
>     $ git grep -c '#! */bin/sh' t | grep -v ':1$'
>
> and did a few just for fun.  Doing it fully may be a good
> microproject for next year ;-)
>
>  t/t1020-subdirectory.sh       |  6 +++---
>  t/t2050-git-dir-relative.sh   | 11 ++++++-----
>  t/t3404-rebase-interactive.sh |  7 +++----
>  3 files changed, 12 insertions(+), 12 deletions(-)
>
> diff --git a/t/t1020-subdirectory.sh b/t/t1020-subdirectory.sh
> index 8e22b03..6dedb1c 100755
> --- a/t/t1020-subdirectory.sh
> +++ b/t/t1020-subdirectory.sh
> @@ -142,9 +142,9 @@ test_expect_success 'GIT_PREFIX for built-ins' '
>  	# Use GIT_EXTERNAL_DIFF to test that the "diff" built-in
>  	# receives the GIT_PREFIX variable.
>  	printf "dir/" >expect &&
> -	printf "#!/bin/sh\n" >diff &&
> -	printf "printf \"\$GIT_PREFIX\"" >>diff &&
> -	chmod +x diff &&
> +	write_script diff <<-\EOF &&
> +	printf "%s" "$GIT_PREFIX"
> +	EOF
>  	(
>  		cd dir &&
>  		printf "change" >two &&

Regarding this one, I notice that "expect" and "actual" (produced later in this script by executing "diff" script) are eventually compared by test_cmp, which runs "diff" to show the actual differences. If we are doing this modernization to use write_script more, we probably should make "expect" and "actual" text files that end with a complete line.

I.e.
-- >8 --
Subject: t1020: do not overuse printf and use write_script

The test prepares a sample file "dir/two" with a single incomplete line in it with "printf", and also prepares a small helper script "diff" to create a file with a single incomplete line in it, again with "printf". The output from the latter is compared with an expected output, again prepared with "printf" hance lacking the final LF. There is no reason for this test to be using files with an incomplete line at the end, and these look more like a mistake of not using

	printf "%s\n" "string to be written"
and using
	printf "string to be written"

Depending on what would be in $GIT_PREFIX, using the latter form could be a bug waiting to happen. Correct them.

Also, the test uses hardcoded #!/bin/sh to create a small helper script. For a small task like what the generated script does, it does not matter too much in that what appears as /bin/sh would not be _so_ broken, but while we are at it, use write_script instead, which happens to make the result easier to read by reducing need of one level of quoting.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 t/t1020-subdirectory.sh | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/t/t1020-subdirectory.sh b/t/t1020-subdirectory.sh
index 8e22b03..df3183e 100755
--- a/t/t1020-subdirectory.sh
+++ b/t/t1020-subdirectory.sh
@@ -141,13 +141,13 @@ test_expect_success 'GIT_PREFIX for !alias' '
 test_expect_success 'GIT_PREFIX for built-ins' '
 	# Use GIT_EXTERNAL_DIFF to test that the "diff" built-in
 	# receives the GIT_PREFIX variable.
-	printf "dir/" >expect &&
-	printf "#!/bin/sh\n" >diff &&
-	printf "printf \"\$GIT_PREFIX\"" >>diff &&
-	chmod +x diff &&
+	echo "dir/" >expect &&
+	write_script diff <<-\EOF &&
+	printf "%s\n" "$GIT_PREFIX"
+	EOF
 	(
 		cd dir &&
-		printf "change" >two &&
+		echo "change" >two &&
 		GIT_EXTERNAL_DIFF=./diff git diff >../actual
 		git checkout -- two
 	) &&
Previous: Junio C HamanoNext: Eric Sunshine
Message 6 of 14 in “Hardcoded #!/bin/sh in t5532 causes problems on Solaris”
  1. Tom G. ChristensenApr 9, 2016
  2. Jeff KingApr 9, 2016
  3. Tom G. ChristensenApr 9, 2016
  4. Jeff KingApr 9, 2016
  5. Junio C HamanoApr 10, 2016
  6. Junio C HamanoApr 10, 2016
  7. Eric SunshineApr 10, 2016
  8. Junio C HamanoApr 11, 2016
  9. Jeff KingApr 11, 2016
  10. Jeff KingApr 11, 2016
  11. Junio C HamanoApr 12, 2016
  12. Junio C HamanoApr 12, 2016
  13. Jeff KingApr 12, 2016
  14. Jeff KingApr 12, 2016

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.