Thread (1 message) 1 message, 1 author, 2026-02-19

Re: [PATCH] t: use test_seq -f and pipes in a few more places

From: Junio C Hamano <hidden>
Date: 2026-02-19 17:09:59

Aaron Plattner [off-list ref] writes:
Several tests use a pattern that writes to a temporary file like this:

  printf "do something with %d\n" $(test_seq <count>) >tmpfile &&
  git do-something --stdin <tmpfile

Other tests use test_seq's -f parameter, but still write to a temporary file:

  test_seq -f "do something with %d" <count> >input &&
  git do-something --stdin <input

Simplify both of these patterns to

  test_seq -f "do something with %d" <count> |
  git do-something --stdin

Signed-off-by: Aaron Plattner <redacted>
---
Suggested by Peff and Junio in [ref]
and <xmqqcy3cf5xa.fsf@gitster.g> respectively.
This side topic completely slipped my mind.  Thanks for following it
up.
quoted hunk
diff --git a/t/pack-refs-tests.sh b/t/pack-refs-tests.sh
@@ -401,18 +401,14 @@ do
 
 			# Create 99 packed refs. This should cause the heuristic
 			# to require more than the minimum amount of loose refs.
-			test_seq 99 |
-			while read i
-			do
-				printf "create refs/heads/packed-%d HEAD\n" $i || return 1
-			done >stdin &&
-			git update-ref --stdin <stdin &&
+			test_seq -f "create refs/heads/packed-%d HEAD" 99 |
+			git update-ref --stdin &&
Nice.

The original was doubly bad in that it did not even take advantage
of the fact that printf will iterate over its parameters, but now it
is nicely packaged up in a single "test_seq -f" invocation.
quoted hunk
diff --git a/t/t0613-reftable-write-options.sh b/t/t0613-reftable-write-options.sh
index e334751759..26b716c75f 100755
-		test_seq -f "update refs/heads/branch-%d HEAD" 10 >input &&
-		git update-ref --stdin <input &&
+		test_seq -f "update refs/heads/branch-%d HEAD" 10 |
+		git update-ref --stdin &&
Everything after this patch gets applied follows this pattern, and
once the patch is written, this is not important enough to go back
and fix it, but I do not think it a bad idea to use a temporary file
in something like this.  If you were hacking on the "update-ref"
command and find this test breaking, the first thing you may want to
do is to rerun the test with "-i -v -d" options, chdir to the
$TRASH_DIRECTORY left by the failed test, inspect the "input" file
and then run "../../git-update-ref" under the debugger.  Not having
to type the input again while you are doing so would make your life
a bit easier.

Thanks.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help