Git Mailing List Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 00/27] t: general test cleanup + `set -o pipefail`
@ 2019-11-15  1:00 Denton Liu
  2019-11-15  1:00 ` [PATCH 01/27] lib-bash.sh: move `then` onto its own line Denton Liu
                   ` (28 more replies)
  0 siblings, 29 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-15  1:00 UTC (permalink / raw)
  To: Git Mailing List

Patches 1-20 perform some general test cleanup to modernise the style.
They should be relatively uncontroversial and can be merged earlier (or
as a separate series) if desired. The reason these tests were identified
for cleanup was because they failed under `set -o pipefail`.

Patches 21-27 should be considered RFC. In an attempt to catch git
commands failing in the upstream of a pipe, we enable `set -o pipefail`
on Bash. This may result in some funny-looking shell script constructs
(e.g. needing to wrap `grep` since it may "fail") but overall, I think it
is an improvement since we catch failure in more cases.

This change should be backwards compatible with shells that don't
support pipefail since tests that pass under pipefail should be a subset
of tests that can pass without pipefail.

I've tested these patches on Linux, MacOS and Travis[1], although I skipped
CVS, SVN, Apache2 tests (and maybe others?). I'd appreciate help testing
these patches on that regard.

[1]: https://travis-ci.org/Denton-L/git/builds/612133448

Denton Liu (27):
  lib-bash.sh: move `then` onto its own line
  t0014: remove git command upstream of pipe
  t0090: stop losing return codes of git commands
  t3301: stop losing return codes of git commands
  t3600: use test_line_count() where possible
  t3600: stop losing return codes of git commands
  t3600: comment on inducing SIGPIPE in `git rm`
  t4015: stop losing return codes of git commands
  t4015: use test_write_lines()
  t4138: stop losing return codes of git commands
  t5317: stop losing return codes of git commands
  t5317: use ! grep to check for no matching lines
  t5703: stop losing return codes of git commands
  t7501: remove spaces after redirect operators
  t7501: stop losing return codes of git commands
  t7700: drop redirections to /dev/null
  t7700: remove spaces after redirect operators
  t7700: move keywords onto their own line
  t7700: s/test -f/test_path_is_file/
  t7700: stop losing return codes of git commands
  t: define test_grep_return_success()
  t0090: mask failing grep status
  t3600: mark git command as failing
  t5004: ignore SIGPIPE in zipinfo
  t5703: mask failing grep status
  t9902: disable pipefail
  t: run tests with `set -o pipefail` on Bash

 t/README                               |   4 +
 t/lib-bash.sh                          |   3 +-
 t/t0014-alias.sh                       |   4 +-
 t/t0090-cache-tree.sh                  |   5 +-
 t/t3301-notes.sh                       | 230 ++++++++++++++++++-------
 t/t3600-rm.sh                          |  16 +-
 t/t4015-diff-whitespace.sh             | 123 +++++++------
 t/t4138-apply-ws-expansion.sh          |  16 +-
 t/t5004-archive-corner-cases.sh        |   4 +-
 t/t5317-pack-objects-filter-objects.sh |  34 ++--
 t/t5703-upload-pack-ref-in-want.sh     |  52 ++++--
 t/t7501-commit-basic-functionality.sh  |  83 +++++----
 t/t7700-repack.sh                      | 125 ++++++++------
 t/t9902-completion.sh                  |   6 +
 t/test-lib-functions.sh                |   5 +
 t/test-lib.sh                          |  12 ++
 16 files changed, 458 insertions(+), 264 deletions(-)

-- 
2.24.0.399.gf8350c9437


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH 01/27] lib-bash.sh: move `then` onto its own line
  2019-11-15  1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu
@ 2019-11-15  1:00 ` Denton Liu
  2019-11-15 18:22   ` Eric Sunshine
  2019-11-15  1:00 ` [PATCH 02/27] t0014: remove git command upstream of pipe Denton Liu
                   ` (27 subsequent siblings)
  28 siblings, 1 reply; 169+ messages in thread
From: Denton Liu @ 2019-11-15  1:00 UTC (permalink / raw)
  To: Git Mailing List

The code style for tests is to have statements on their own line if
possible. Move the `then` onto its own line so that it conforms with the
test style.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/lib-bash.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/t/lib-bash.sh b/t/lib-bash.sh
index 2be955fafb..6a2c21cd24 100644
--- a/t/lib-bash.sh
+++ b/t/lib-bash.sh
@@ -2,7 +2,8 @@
 # to run under Bash; primarily intended for tests of the completion
 # script.
 
-if test -n "$BASH" && test -z "$POSIXLY_CORRECT"; then
+if test -n "$BASH" && test -z "$POSIXLY_CORRECT"
+then
 	# we are in full-on bash mode
 	true
 elif type bash >/dev/null 2>&1; then
-- 
2.24.0.399.gf8350c9437


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH 02/27] t0014: remove git command upstream of pipe
  2019-11-15  1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu
  2019-11-15  1:00 ` [PATCH 01/27] lib-bash.sh: move `then` onto its own line Denton Liu
@ 2019-11-15  1:00 ` Denton Liu
  2019-11-15  1:00 ` [PATCH 03/27] t0090: stop losing return codes of git commands Denton Liu
                   ` (26 subsequent siblings)
  28 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-15  1:00 UTC (permalink / raw)
  To: Git Mailing List

Before, the `git frotz` command would fail but its return code was
hidden since it was in the upstream of a pipe. Break the pipeline into
two commands so that the return code is no longer lost. Also, mark
`git frotz` with test_must_fail since it's supposed to fail.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t0014-alias.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/t/t0014-alias.sh b/t/t0014-alias.sh
index 2694c81afd..8d3d9144c0 100755
--- a/t/t0014-alias.sh
+++ b/t/t0014-alias.sh
@@ -38,8 +38,8 @@ test_expect_success 'looping aliases - internal execution' '
 #'
 
 test_expect_success 'run-command formats empty args properly' '
-    GIT_TRACE=1 git frotz a "" b " " c 2>&1 |
-    sed -ne "/run_command:/s/.*trace: run_command: //p" >actual &&
+    test_must_fail env GIT_TRACE=1 git frotz a "" b " " c 2>actual.raw &&
+    sed -ne "/run_command:/s/.*trace: run_command: //p" actual.raw >actual &&
     echo "git-frotz a '\'''\'' b '\'' '\'' c" >expect &&
     test_cmp expect actual
 '
-- 
2.24.0.399.gf8350c9437


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH 03/27] t0090: stop losing return codes of git commands
  2019-11-15  1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu
  2019-11-15  1:00 ` [PATCH 01/27] lib-bash.sh: move `then` onto its own line Denton Liu
  2019-11-15  1:00 ` [PATCH 02/27] t0014: remove git command upstream of pipe Denton Liu
@ 2019-11-15  1:00 ` Denton Liu
  2019-11-15  1:00 ` [PATCH 04/27] t3301: " Denton Liu
                   ` (25 subsequent siblings)
  28 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-15  1:00 UTC (permalink / raw)
  To: Git Mailing List

In generate_expected_cache_tree_rec(), there are currently two instances
of `git ls-files` in the upstream of a pipe. In the case where the
upstream git command fails, its return code will be lost. Extract the
`git ls-files` into its own call so that if it ever fails, its return
code is not lost.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t0090-cache-tree.sh | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh
index ce9a4a5f32..5a633690bf 100755
--- a/t/t0090-cache-tree.sh
+++ b/t/t0090-cache-tree.sh
@@ -21,9 +21,10 @@ generate_expected_cache_tree_rec () {
 	parent="$2" &&
 	# ls-files might have foo/bar, foo/bar/baz, and foo/bar/quux
 	# We want to count only foo because it's the only direct child
-	subtrees=$(git ls-files|grep /|cut -d / -f 1|uniq) &&
+	git ls-files >files &&
+	subtrees=$(grep / files|cut -d / -f 1|uniq) &&
 	subtree_count=$(echo "$subtrees"|awk -v c=0 '$1 != "" {++c} END {print c}') &&
-	entries=$(git ls-files|wc -l) &&
+	entries=$(wc -l <files) &&
 	printf "SHA $dir (%d entries, %d subtrees)\n" "$entries" "$subtree_count" &&
 	for subtree in $subtrees
 	do
-- 
2.24.0.399.gf8350c9437


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH 04/27] t3301: stop losing return codes of git commands
  2019-11-15  1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu
                   ` (2 preceding siblings ...)
  2019-11-15  1:00 ` [PATCH 03/27] t0090: stop losing return codes of git commands Denton Liu
@ 2019-11-15  1:00 ` " Denton Liu
  2019-11-15  1:00 ` [PATCH 05/27] t3600: use test_line_count() where possible Denton Liu
                   ` (24 subsequent siblings)
  28 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-15  1:00 UTC (permalink / raw)
  To: Git Mailing List

Currently, there are two ways where the return codes of git commands are
lost. The first way is when a command is in the upstream of a pipe. In a
pipe, only the return code of the last command is used. Thus, all other
commands will have their return codes masked. Rewrite pipes so that
there are no git commands upstream.

The other way is when a command is in a non-assignment command
substitution. The return code will be lost in favour of the surrounding
command's. Rewrite instances of this so that git commands are either run
on their own or in an assignment-only command substitution.

This patch fixes a real buggy test: in 'copy note with "git notes
copy"', `git notes` was mistyped as `git note`.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t3301-notes.sh | 230 +++++++++++++++++++++++++++++++++--------------
 1 file changed, 163 insertions(+), 67 deletions(-)

diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh
index d66a5f6faa..8f43303007 100755
--- a/t/t3301-notes.sh
+++ b/t/t3301-notes.sh
@@ -54,7 +54,9 @@ test_expect_success 'create notes' '
 	test_path_is_missing .git/NOTES_EDITMSG &&
 	git ls-tree -r refs/notes/commits >actual &&
 	test_line_count = 1 actual &&
-	test "b4" = "$(git notes show)" &&
+	echo b4 >expect &&
+	git notes show >actual &&
+	test_cmp expect actual &&
 	git show HEAD^ &&
 	test_must_fail git notes show HEAD^
 '
@@ -79,14 +81,21 @@ test_expect_success 'edit existing notes' '
 	test_path_is_missing .git/NOTES_EDITMSG &&
 	git ls-tree -r refs/notes/commits >actual &&
 	test_line_count = 1 actual &&
-	test "b3" = "$(git notes show)" &&
+	echo b3 >expect &&
+	git notes show >actual &&
+	test_cmp expect actual &&
 	git show HEAD^ &&
 	test_must_fail git notes show HEAD^
 '
 
 test_expect_success 'show notes from treeish' '
-	test "b3" = "$(git notes --ref commits^{tree} show)" &&
-	test "b4" = "$(git notes --ref commits@{1} show)"
+	echo b3 >expect &&
+	git notes --ref commits^{tree} show >actual &&
+	test_cmp expect actual &&
+
+	echo b4 >expect &&
+	git notes --ref commits@{1} show >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'cannot edit notes from non-ref' '
@@ -99,7 +108,9 @@ test_expect_success 'cannot "git notes add -m" where notes already exists' '
 	test_path_is_missing .git/NOTES_EDITMSG &&
 	git ls-tree -r refs/notes/commits >actual &&
 	test_line_count = 1 actual &&
-	test "b3" = "$(git notes show)" &&
+	echo b3 >expect &&
+	git notes show >actual &&
+	test_cmp expect actual &&
 	git show HEAD^ &&
 	test_must_fail git notes show HEAD^
 '
@@ -109,7 +120,9 @@ test_expect_success 'can overwrite existing note with "git notes add -f -m"' '
 	test_path_is_missing .git/NOTES_EDITMSG &&
 	git ls-tree -r refs/notes/commits >actual &&
 	test_line_count = 1 actual &&
-	test "b1" = "$(git notes show)" &&
+	echo b1 >expect &&
+	git notes show >actual &&
+	test_cmp expect actual &&
 	git show HEAD^ &&
 	test_must_fail git notes show HEAD^
 '
@@ -119,7 +132,9 @@ test_expect_success 'add w/no options on existing note morphs into edit' '
 	test_path_is_missing .git/NOTES_EDITMSG &&
 	git ls-tree -r refs/notes/commits >actual &&
 	test_line_count = 1 actual &&
-	test "b2" = "$(git notes show)" &&
+	echo b2 >expect &&
+	git notes show >actual &&
+	test_cmp expect actual &&
 	git show HEAD^ &&
 	test_must_fail git notes show HEAD^
 '
@@ -129,7 +144,9 @@ test_expect_success 'can overwrite existing note with "git notes add -f"' '
 	test_path_is_missing .git/NOTES_EDITMSG &&
 	git ls-tree -r refs/notes/commits >actual &&
 	test_line_count = 1 actual &&
-	test "b1" = "$(git notes show)" &&
+	echo b1 >expect &&
+	git notes show >actual &&
+	test_cmp expect actual &&
 	git show HEAD^ &&
 	test_must_fail git notes show HEAD^
 '
@@ -146,7 +163,8 @@ test_expect_success 'show notes' '
 		Notes:
 		${indent}b1
 	EOF
-	! (git cat-file commit HEAD | grep b1) &&
+	git cat-file commit HEAD >commits &&
+	! grep b1 commits &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -472,9 +490,11 @@ test_expect_success 'removing with --stdin --ignore-missing' '
 test_expect_success 'list notes with "git notes list"' '
 	commit_2=$(git rev-parse 2nd) &&
 	commit_3=$(git rev-parse 3rd) &&
+	note_2=$(git rev-parse refs/notes/commits:$commit_2) &&
+	note_3=$(git rev-parse refs/notes/commits:$commit_3) &&
 	sort -t" " -k2 >expect <<-EOF &&
-		$(git rev-parse refs/notes/commits:$commit_2) $commit_2
-		$(git rev-parse refs/notes/commits:$commit_3) $commit_3
+		$note_2 $commit_2
+		$note_3 $commit_3
 	EOF
 	git notes list >actual &&
 	test_cmp expect actual
@@ -486,9 +506,7 @@ test_expect_success 'list notes with "git notes"' '
 '
 
 test_expect_success 'list specific note with "git notes list <object>"' '
-	cat >expect <<-EOF &&
-		$(git rev-parse refs/notes/commits:$commit_3)
-	EOF
+	git rev-parse refs/notes/commits:$commit_3 >expect &&
 	git notes list HEAD^^ >actual &&
 	test_cmp expect actual
 '
@@ -512,10 +530,11 @@ test_expect_success 'append to existing note with "git notes append"' '
 
 test_expect_success '"git notes list" does not expand to "git notes list HEAD"' '
 	commit_5=$(git rev-parse 5th) &&
+	note_5=$(git rev-parse refs/notes/commits:$commit_5) &&
 	sort -t" " -k2 >expect_list <<-EOF &&
-		$(git rev-parse refs/notes/commits:$commit_2) $commit_2
-		$(git rev-parse refs/notes/commits:$commit_3) $commit_3
-		$(git rev-parse refs/notes/commits:$commit_5) $commit_5
+		$note_2 $commit_2
+		$note_3 $commit_3
+		$note_5 $commit_5
 	EOF
 	git notes list >actual &&
 	test_cmp expect_list actual
@@ -721,7 +740,8 @@ test_expect_success 'Allow notes on non-commits (trees, blobs, tags)' '
 	git notes show HEAD: >actual &&
 	test_cmp expect actual &&
 	echo "Note on a blob" >expect &&
-	filename=$(git ls-tree --name-only HEAD | head -n1) &&
+	git ls-tree --name-only HEAD >files &&
+	filename=$(head -n1 files) &&
 	git notes add -m "Note on a blob" HEAD:$filename &&
 	git notes show HEAD:$filename >actual &&
 	test_cmp expect actual &&
@@ -745,10 +765,13 @@ test_expect_success 'create note from other note with "git notes add -C"' '
 		Notes:
 		${indent}order test
 	EOF
-	git notes add -C $(git notes list HEAD^) &&
+	note=$(git notes list HEAD^) &&
+	git notes add -C $note &&
 	git log -1 >actual &&
 	test_cmp expect actual &&
-	test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
+	git notes list HEAD^ >expect &&
+	git notes list HEAD >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'create note from non-existing note with "git notes add -C" fails' '
@@ -777,11 +800,12 @@ test_expect_success 'create note from blob with "git notes add -C" reuses blob i
 		Notes:
 		${indent}This is a blob object
 	EOF
-	blob=$(echo "This is a blob object" | git hash-object -w --stdin) &&
-	git notes add -C $blob &&
+	echo "This is a blob object" | git hash-object -w --stdin >blob &&
+	git notes add -C $(cat blob) &&
 	git log -1 >actual &&
 	test_cmp expect actual &&
-	test "$(git notes list HEAD)" = "$blob"
+	git notes list HEAD >actual &&
+	test_cmp blob actual
 '
 
 test_expect_success 'create note from other note with "git notes add -c"' '
@@ -797,7 +821,8 @@ test_expect_success 'create note from other note with "git notes add -c"' '
 		Notes:
 		${indent}yet another note
 	EOF
-	MSG="yet another note" git notes add -c $(git notes list HEAD^^) &&
+	note=$(git notes list HEAD^^) &&
+	MSG="yet another note" git notes add -c $note &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -822,7 +847,8 @@ test_expect_success 'append to note from other note with "git notes append -C"'
 		${indent}
 		${indent}yet another note
 	EOF
-	git notes append -C $(git notes list HEAD^) HEAD^ &&
+	note=$(git notes list HEAD^) &&
+	git notes append -C $note HEAD^ &&
 	git log -1 HEAD^ >actual &&
 	test_cmp expect actual
 '
@@ -839,7 +865,8 @@ test_expect_success 'create note from other note with "git notes append -c"' '
 		Notes:
 		${indent}other note
 	EOF
-	MSG="other note" git notes append -c $(git notes list HEAD^) &&
+	note=$(git notes list HEAD^) &&
+	MSG="other note" git notes append -c $note &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -858,7 +885,8 @@ test_expect_success 'append to note from other note with "git notes append -c"'
 		${indent}
 		${indent}yet another note
 	EOF
-	MSG="yet another note" git notes append -c $(git notes list HEAD) &&
+	note=$(git notes list HEAD) &&
+	MSG="yet another note" git notes append -c $note &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -878,7 +906,9 @@ test_expect_success 'copy note with "git notes copy"' '
 	git notes copy 8th 4th &&
 	git log 3rd..4th >actual &&
 	test_cmp expect actual &&
-	test "$(git note list 4th)" = "$(git note list 8th)"
+	git notes list 4th >expect &&
+	git notes list 8th >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'copy note with "git notes copy" with default' '
@@ -899,14 +929,30 @@ test_expect_success 'copy note with "git notes copy" with default' '
 	git notes copy HEAD^ &&
 	git log -1 >actual &&
 	test_cmp expect actual &&
-	test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
+	git notes list HEAD^ >expect &&
+	git notes list HEAD >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'prevent overwrite with "git notes copy"' '
 	test_must_fail git notes copy HEAD~2 HEAD &&
+	cat >expect <<-EOF &&
+		commit $commit
+		Author: A U Thor <author@example.com>
+		Date:   Thu Apr 7 15:23:13 2005 -0700
+
+		${indent}11th
+
+		Notes:
+		${indent}other note
+		${indent}
+		${indent}yet another note
+	EOF
 	git log -1 >actual &&
 	test_cmp expect actual &&
-	test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
+	git notes list HEAD^ >expect &&
+	git notes list HEAD >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'allow overwrite with "git notes copy -f"' '
@@ -924,7 +970,9 @@ test_expect_success 'allow overwrite with "git notes copy -f"' '
 	git notes copy -f HEAD~3 HEAD &&
 	git log -1 >actual &&
 	test_cmp expect actual &&
-	test "$(git notes list HEAD)" = "$(git notes list HEAD~3)"
+	git notes list HEAD~3 >expect &&
+	git notes list HEAD >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'allow overwrite with "git notes copy -f" with default' '
@@ -944,7 +992,9 @@ test_expect_success 'allow overwrite with "git notes copy -f" with default' '
 	git notes copy -f HEAD~2 &&
 	git log -1 >actual &&
 	test_cmp expect actual &&
-	test "$(git notes list HEAD)" = "$(git notes list HEAD~2)"
+	git notes list HEAD~2 >expect &&
+	git notes list HEAD >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'cannot copy note from object without notes' '
@@ -979,13 +1029,21 @@ test_expect_success 'git notes copy --stdin' '
 		${indent}
 		${indent}yet another note
 	EOF
-	(echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^) &&
-	echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
-	git notes copy --stdin &&
+	from=$(git rev-parse HEAD~3) &&
+	to=$(git rev-parse HEAD^) &&
+	echo "$from" "$to" >copy &&
+	from=$(git rev-parse HEAD~2) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >>copy &&
+	git notes copy --stdin <copy &&
 	git log -2 >actual &&
 	test_cmp expect actual &&
-	test "$(git notes list HEAD)" = "$(git notes list HEAD~2)" &&
-	test "$(git notes list HEAD^)" = "$(git notes list HEAD~3)"
+	git notes list HEAD~2 >expect &&
+	git notes list HEAD >actual &&
+	test_cmp expect actual &&
+	git notes list HEAD~3 >expect &&
+	git notes list HEAD^ >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'git notes copy --for-rewrite (unconfigured)' '
@@ -1006,9 +1064,13 @@ test_expect_success 'git notes copy --for-rewrite (unconfigured)' '
 
 		${indent}14th
 	EOF
-	(echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^) &&
-	echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
-	git notes copy --for-rewrite=foo &&
+	from=$(git rev-parse HEAD~3) &&
+	to=$(git rev-parse HEAD^) &&
+	echo "$from" "$to" >copy &&
+	from=$(git rev-parse HEAD~2) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >>copy &&
+	git notes copy --for-rewrite=foo <copy &&
 	git log -2 >actual &&
 	test_cmp expect actual
 '
@@ -1041,17 +1103,23 @@ test_expect_success 'git notes copy --for-rewrite (enabled)' '
 	EOF
 	test_config notes.rewriteMode overwrite &&
 	test_config notes.rewriteRef "refs/notes/*" &&
-	(echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^) &&
-	echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
-	git notes copy --for-rewrite=foo &&
+	from=$(git rev-parse HEAD~3) &&
+	to=$(git rev-parse HEAD^) &&
+	echo "$from" "$to" >copy &&
+	from=$(git rev-parse HEAD~2) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >>copy &&
+	git notes copy --for-rewrite=foo <copy &&
 	git log -2 >actual &&
 	test_cmp expect actual
 '
 
 test_expect_success 'git notes copy --for-rewrite (disabled)' '
 	test_config notes.rewrite.bar false &&
-	echo $(git rev-parse HEAD~3) $(git rev-parse HEAD) |
-	git notes copy --for-rewrite=bar &&
+	from=$(git rev-parse HEAD~3) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
+	git notes copy --for-rewrite=bar <copy &&
 	git log -2 >actual &&
 	test_cmp expect actual
 '
@@ -1071,8 +1139,10 @@ test_expect_success 'git notes copy --for-rewrite (overwrite)' '
 	git notes add -f -m"a fresh note" HEAD^ &&
 	test_config notes.rewriteMode overwrite &&
 	test_config notes.rewriteRef "refs/notes/*" &&
-	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
-	git notes copy --for-rewrite=foo &&
+	from=$(git rev-parse HEAD^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
+	git notes copy --for-rewrite=foo <copy &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -1080,8 +1150,10 @@ test_expect_success 'git notes copy --for-rewrite (overwrite)' '
 test_expect_success 'git notes copy --for-rewrite (ignore)' '
 	test_config notes.rewriteMode ignore &&
 	test_config notes.rewriteRef "refs/notes/*" &&
-	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
-	git notes copy --for-rewrite=foo &&
+	from=$(git rev-parse HEAD^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
+	git notes copy --for-rewrite=foo <copy &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -1103,8 +1175,10 @@ test_expect_success 'git notes copy --for-rewrite (append)' '
 	git notes add -f -m"another fresh note" HEAD^ &&
 	test_config notes.rewriteMode concatenate &&
 	test_config notes.rewriteRef "refs/notes/*" &&
-	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
-	git notes copy --for-rewrite=foo &&
+	from=$(git rev-parse HEAD^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
+	git notes copy --for-rewrite=foo <copy &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -1131,9 +1205,13 @@ test_expect_success 'git notes copy --for-rewrite (append two to one)' '
 	git notes add -f -m"append 2" HEAD^^ &&
 	test_config notes.rewriteMode concatenate &&
 	test_config notes.rewriteRef "refs/notes/*" &&
-	(echo $(git rev-parse HEAD^) $(git rev-parse HEAD) &&
-	echo $(git rev-parse HEAD^^) $(git rev-parse HEAD)) |
-	git notes copy --for-rewrite=foo &&
+	from=$(git rev-parse HEAD^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
+	from=$(git rev-parse HEAD^^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >>copy &&
+	git notes copy --for-rewrite=foo <copy &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -1142,8 +1220,10 @@ test_expect_success 'git notes copy --for-rewrite (append empty)' '
 	git notes remove HEAD^ &&
 	test_config notes.rewriteMode concatenate &&
 	test_config notes.rewriteRef "refs/notes/*" &&
-	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
-	git notes copy --for-rewrite=foo &&
+	from=$(git rev-parse HEAD^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
+	git notes copy --for-rewrite=foo <copy &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -1163,8 +1243,10 @@ test_expect_success 'GIT_NOTES_REWRITE_MODE works' '
 	test_config notes.rewriteMode concatenate &&
 	test_config notes.rewriteRef "refs/notes/*" &&
 	git notes add -f -m"replacement note 1" HEAD^ &&
-	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
-	GIT_NOTES_REWRITE_MODE=overwrite git notes copy --for-rewrite=foo &&
+	from=$(git rev-parse HEAD^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
+	GIT_NOTES_REWRITE_MODE=overwrite git notes copy --for-rewrite=foo <copy &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -1184,9 +1266,11 @@ test_expect_success 'GIT_NOTES_REWRITE_REF works' '
 	git notes add -f -m"replacement note 2" HEAD^ &&
 	test_config notes.rewriteMode overwrite &&
 	test_unconfig notes.rewriteRef &&
-	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
+	from=$(git rev-parse HEAD^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
 	GIT_NOTES_REWRITE_REF=refs/notes/commits:refs/notes/other \
-		git notes copy --for-rewrite=foo &&
+		git notes copy --for-rewrite=foo <copy &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -1195,9 +1279,11 @@ test_expect_success 'GIT_NOTES_REWRITE_REF overrides config' '
 	git notes add -f -m"replacement note 3" HEAD^ &&
 	test_config notes.rewriteMode overwrite &&
 	test_config notes.rewriteRef refs/notes/other &&
-	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
+	from=$(git rev-parse HEAD^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
 	GIT_NOTES_REWRITE_REF=refs/notes/commits \
-		git notes copy --for-rewrite=foo &&
+		git notes copy --for-rewrite=foo <copy &&
 	git log -1 >actual &&
 	grep "replacement note 3" actual
 '
@@ -1212,26 +1298,36 @@ test_expect_success 'git notes copy diagnoses too many or too few parameters' '
 test_expect_success 'git notes get-ref expands refs/heads/master to refs/notes/refs/heads/master' '
 	test_unconfig core.notesRef &&
 	sane_unset GIT_NOTES_REF &&
-	test "$(git notes --ref=refs/heads/master get-ref)" = "refs/notes/refs/heads/master"
+	echo refs/notes/refs/heads/master >expect &&
+	git notes --ref=refs/heads/master get-ref >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'git notes get-ref (no overrides)' '
 	test_unconfig core.notesRef &&
 	sane_unset GIT_NOTES_REF &&
-	test "$(git notes get-ref)" = "refs/notes/commits"
+	echo refs/notes/commits >expect &&
+	git notes get-ref >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'git notes get-ref (core.notesRef)' '
 	test_config core.notesRef refs/notes/foo &&
-	test "$(git notes get-ref)" = "refs/notes/foo"
+	echo refs/notes/foo >expect &&
+	git notes get-ref >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'git notes get-ref (GIT_NOTES_REF)' '
-	test "$(GIT_NOTES_REF=refs/notes/bar git notes get-ref)" = "refs/notes/bar"
+	echo refs/notes/bar >expect &&
+	GIT_NOTES_REF=refs/notes/bar git notes get-ref >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'git notes get-ref (--ref)' '
-	test "$(GIT_NOTES_REF=refs/notes/bar git notes --ref=baz get-ref)" = "refs/notes/baz"
+	echo refs/notes/baz >expect &&
+	GIT_NOTES_REF=refs/notes/bar git notes --ref=baz get-ref >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'setup testing of empty notes' '
-- 
2.24.0.399.gf8350c9437


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH 05/27] t3600: use test_line_count() where possible
  2019-11-15  1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu
                   ` (3 preceding siblings ...)
  2019-11-15  1:00 ` [PATCH 04/27] t3301: " Denton Liu
@ 2019-11-15  1:00 ` Denton Liu
  2019-11-15  1:00 ` [PATCH 06/27] t3600: stop losing return codes of git commands Denton Liu
                   ` (23 subsequent siblings)
  28 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-15  1:00 UTC (permalink / raw)
  To: Git Mailing List

Since we have a helper function that can test the number of lines in a
file that gives better debugging information on failure, use
test_line_count() to test the number of lines.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t3600-rm.sh | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh
index 8c8cca5bfb..f6e659b7e9 100755
--- a/t/t3600-rm.sh
+++ b/t/t3600-rm.sh
@@ -113,9 +113,10 @@ test_expect_success '"rm" command printed' '
 	echo frotz >test-file &&
 	git add test-file &&
 	git commit -m "add file for rm test" &&
-	git rm test-file >rm-output &&
-	test $(grep "^rm " rm-output | wc -l) = 1 &&
-	rm -f test-file rm-output &&
+	git rm test-file >rm-output.raw &&
+	grep "^rm " rm-output.raw >rm-output &&
+	test_line_count = 1 rm-output &&
+	rm -f test-file rm-output.raw rm-output &&
 	git commit -m "remove file from rm test"
 '
 
-- 
2.24.0.399.gf8350c9437


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH 06/27] t3600: stop losing return codes of git commands
  2019-11-15  1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu
                   ` (4 preceding siblings ...)
  2019-11-15  1:00 ` [PATCH 05/27] t3600: use test_line_count() where possible Denton Liu
@ 2019-11-15  1:00 ` Denton Liu
  2019-11-15  1:00 ` [PATCH 07/27] t3600: comment on inducing SIGPIPE in `git rm` Denton Liu
                   ` (22 subsequent siblings)
  28 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-15  1:00 UTC (permalink / raw)
  To: Git Mailing List

When a command is in a non-assignment command substitution, the return
code will be lost in favour of the surrounding command's. As a result,
if a git command fails, we won't know about it. Rewrite instances of
this so that git commands are either run in an assignment-only command
substitution so that their return codes aren't lost.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t3600-rm.sh | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh
index f6e659b7e9..0c3bf10edd 100755
--- a/t/t3600-rm.sh
+++ b/t/t3600-rm.sh
@@ -304,7 +304,8 @@ EOF
 
 test_expect_success 'rm removes empty submodules from work tree' '
 	mkdir submod &&
-	git update-index --add --cacheinfo 160000 $(git rev-parse HEAD) submod &&
+	hash=$(git rev-parse HEAD) &&
+	git update-index --add --cacheinfo 160000 "$hash" submod &&
 	git config -f .gitmodules submodule.sub.url ./. &&
 	git config -f .gitmodules submodule.sub.path submod &&
 	git submodule init &&
@@ -623,7 +624,8 @@ test_expect_success 'setup subsubmodule' '
 	git submodule update &&
 	(
 		cd submod &&
-		git update-index --add --cacheinfo 160000 $(git rev-parse HEAD) subsubmod &&
+		hash=$(git rev-parse HEAD) &&
+		git update-index --add --cacheinfo 160000 "$hash" subsubmod &&
 		git config -f .gitmodules submodule.sub.url ../. &&
 		git config -f .gitmodules submodule.sub.path subsubmod &&
 		git submodule init &&
-- 
2.24.0.399.gf8350c9437


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH 07/27] t3600: comment on inducing SIGPIPE in `git rm`
  2019-11-15  1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu
                   ` (5 preceding siblings ...)
  2019-11-15  1:00 ` [PATCH 06/27] t3600: stop losing return codes of git commands Denton Liu
@ 2019-11-15  1:00 ` Denton Liu
  2019-11-15  1:00 ` [PATCH 08/27] t4015: stop losing return codes of git commands Denton Liu
                   ` (21 subsequent siblings)
  28 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-15  1:00 UTC (permalink / raw)
  To: Git Mailing List

Add a comment about intentionally inducing SIGPIPE since this is unusual
and future developers should be aware. Also, even though we are trying
to refactor git commands out of the upstream of pipes, we cannot do it
here since we rely on it being upstream to induce SIGPIPE. Comment on
that as well so that future developers do not try to change it.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t3600-rm.sh | 1 +
 1 file changed, 1 insertion(+)

diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh
index 0c3bf10edd..0ea858d652 100755
--- a/t/t3600-rm.sh
+++ b/t/t3600-rm.sh
@@ -251,6 +251,7 @@ test_expect_success 'choking "git rm" should not let it die with cruft' '
 		echo "100644 $hash 0	some-file-$i"
 		i=$(( $i + 1 ))
 	done | git update-index --index-info &&
+	# git command is intentionally placed upstream of pipe to induce SIGPIPE
 	git rm -n "some-file-*" | : &&
 	test_path_is_missing .git/index.lock
 '
-- 
2.24.0.399.gf8350c9437


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH 08/27] t4015: stop losing return codes of git commands
  2019-11-15  1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu
                   ` (6 preceding siblings ...)
  2019-11-15  1:00 ` [PATCH 07/27] t3600: comment on inducing SIGPIPE in `git rm` Denton Liu
@ 2019-11-15  1:00 ` Denton Liu
  2019-11-15  1:00 ` [PATCH 09/27] t4015: use test_write_lines() Denton Liu
                   ` (20 subsequent siblings)
  28 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-15  1:00 UTC (permalink / raw)
  To: Git Mailing List

Currently, there are two ways where the return codes of git commands are
lost. The first way is when a command is in the upstream of a pipe. In a
pipe, only the return code of the last command is used. Thus, all other
commands will have their return codes masked. Rewrite pipes so that
there are no git commands upstream.

The other way is when a command is in a non-assignment command
substitution. The return code will be lost in favour of the surrounding
command's. Rewrite instances of this so that git commands are either run
on their own or in an assignment-only command substitution.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t4015-diff-whitespace.sh | 119 ++++++++++++++++++++++---------------
 1 file changed, 72 insertions(+), 47 deletions(-)

diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh
index eadaf57262..7fb83c8eff 100755
--- a/t/t4015-diff-whitespace.sh
+++ b/t/t4015-diff-whitespace.sh
@@ -16,7 +16,8 @@ test_expect_success "Ray Lehtiniemi's example" '
 	} while (0);
 	EOF
 	git update-index --add x &&
-	before=$(git rev-parse --short $(git hash-object x)) &&
+	old_hash_x=$(git hash-object x) &&
+	before=$(git rev-parse --short "$old_hash_x") &&
 
 	cat <<-\EOF >x &&
 	do
@@ -25,7 +26,8 @@ test_expect_success "Ray Lehtiniemi's example" '
 	}
 	while (0);
 	EOF
-	after=$(git rev-parse --short $(git hash-object x)) &&
+	new_hash_x=$(git hash-object x) &&
+	after=$(git rev-parse --short "$new_hash_x") &&
 
 	cat <<-EOF >expect &&
 	diff --git a/x b/x
@@ -63,7 +65,8 @@ test_expect_success 'another test, without options' '
 	EOF
 
 	git update-index x &&
-	before=$(git rev-parse --short $(git hash-object x)) &&
+	old_hash_x=$(git hash-object x) &&
+	before=$(git rev-parse --short "$old_hash_x") &&
 
 	tr "_" " " <<-\EOF >x &&
 	_	whitespace at beginning
@@ -73,7 +76,8 @@ test_expect_success 'another test, without options' '
 	unchanged line
 	CR at end
 	EOF
-	after=$(git rev-parse --short $(git hash-object x)) &&
+	new_hash_x=$(git hash-object x) &&
+	after=$(git rev-parse --short "$new_hash_x") &&
 
 	tr "Q_" "\015 " <<-EOF >expect &&
 	diff --git a/x b/x
@@ -526,13 +530,15 @@ test_expect_success 'ignore-blank-lines: mix changes and blank lines' '
 test_expect_success 'check mixed spaces and tabs in indent' '
 	# This is indented with SP HT SP.
 	echo " 	 foo();" >x &&
-	git diff --check | grep "space before tab in indent"
+	test_must_fail git diff --check >check &&
+	grep "space before tab in indent" check
 '
 
 test_expect_success 'check mixed tabs and spaces in indent' '
 	# This is indented with HT SP HT.
 	echo "	 	foo();" >x &&
-	git diff --check | grep "space before tab in indent"
+	test_must_fail git diff --check >check &&
+	grep "space before tab in indent" check
 '
 
 test_expect_success 'check with no whitespace errors' '
@@ -753,20 +759,23 @@ test_expect_success 'check tab-in-indent excluded from wildcard whitespace attri
 test_expect_success 'line numbers in --check output are correct' '
 	echo "" >x &&
 	echo "foo(); " >>x &&
-	git diff --check | grep "x:2:"
+	test_must_fail git diff --check >check &&
+	grep "x:2:" check
 '
 
 test_expect_success 'checkdiff detects new trailing blank lines (1)' '
 	echo "foo();" >x &&
 	echo "" >>x &&
-	git diff --check | grep "new blank line"
+	test_must_fail git diff --check >check &&
+	grep "new blank line" check
 '
 
 test_expect_success 'checkdiff detects new trailing blank lines (2)' '
 	{ echo a; echo b; echo; echo; } >x &&
 	git add x &&
 	{ echo a; echo; echo; echo; echo; } >x &&
-	git diff --check | grep "new blank line"
+	test_must_fail git diff --check >check &&
+	grep "new blank line" check
 '
 
 test_expect_success 'checkdiff allows new blank lines' '
@@ -794,14 +803,16 @@ test_expect_success 'whitespace-only changes reported across renames' '
 	git reset --hard &&
 	for i in 1 2 3 4 5 6 7 8 9; do echo "$i$i$i$i$i$i"; done >x &&
 	git add x &&
-	before=$(git rev-parse --short $(git hash-object x)) &&
+	hash_x=$(git hash-object x) &&
+	before=$(git rev-parse --short "$hash_x") &&
 	git commit -m "base" &&
 	sed -e "5s/^/ /" x >z &&
 	git rm x &&
 	git add z &&
-	after=$(git rev-parse --short $(git hash-object z)) &&
-	git diff -w -M --cached |
-	sed -e "/^similarity index /s/[0-9][0-9]*/NUM/" >actual &&
+	hash_z=$(git hash-object z) &&
+	after=$(git rev-parse --short "$hash_z") &&
+	git diff -w -M --cached >actual.raw &&
+	sed -e "/^similarity index /s/[0-9][0-9]*/NUM/" actual.raw >actual &&
 	cat <<-EOF >expect &&
 	diff --git a/x b/z
 	similarity index NUM%
@@ -840,7 +851,8 @@ test_expect_success 'combined diff with autocrlf conversion' '
 	git config core.autocrlf true &&
 	test_must_fail git merge master &&
 
-	git diff | sed -e "1,/^@@@/d" >actual &&
+	git diff >actual.raw &&
+	sed -e "1,/^@@@/d" actual.raw >actual &&
 	! grep "^-" actual
 
 '
@@ -864,11 +876,14 @@ test_expect_success 'diff that introduces a line with only tabs' '
 	git config core.whitespace blank-at-eol &&
 	git reset --hard &&
 	echo "test" >x &&
-	before=$(git rev-parse --short $(git hash-object x)) &&
+	old_hash_x=$(git hash-object x) &&
+	before=$(git rev-parse --short "$old_hash_x") &&
 	git commit -m "initial" x &&
 	echo "{NTN}" | tr "NT" "\n\t" >>x &&
-	after=$(git rev-parse --short $(git hash-object x)) &&
-	git diff --color | test_decode_color >current &&
+	new_hash_x=$(git hash-object x) &&
+	after=$(git rev-parse --short "$new_hash_x") &&
+	git diff --color >current.raw &&
+	test_decode_color <current.raw >current &&
 
 	cat >expected <<-EOF &&
 	<BOLD>diff --git a/x b/x<RESET>
@@ -891,17 +906,19 @@ test_expect_success 'diff that introduces and removes ws breakages' '
 		echo "0. blank-at-eol " &&
 		echo "1. blank-at-eol "
 	} >x &&
-	before=$(git rev-parse --short $(git hash-object x)) &&
+	old_hash_x=$(git hash-object x) &&
+	before=$(git rev-parse --short "$old_hash_x") &&
 	git commit -a --allow-empty -m preimage &&
 	{
 		echo "0. blank-at-eol " &&
 		echo "1. still-blank-at-eol " &&
 		echo "2. and a new line "
 	} >x &&
-	after=$(git rev-parse --short $(git hash-object x)) &&
+	new_hash_x=$(git hash-object x) &&
+	after=$(git rev-parse --short "$new_hash_x") &&
 
-	git diff --color |
-	test_decode_color >current &&
+	git diff --color >current.raw &&
+	test_decode_color <current.raw >current &&
 
 	cat >expected <<-EOF &&
 	<BOLD>diff --git a/x b/x<RESET>
@@ -925,14 +942,16 @@ test_expect_success 'ws-error-highlight test setup' '
 		echo "0. blank-at-eol " &&
 		echo "1. blank-at-eol "
 	} >x &&
-	before=$(git rev-parse --short $(git hash-object x)) &&
+	old_hash_x=$(git hash-object x) &&
+	before=$(git rev-parse --short "$old_hash_x") &&
 	git commit -a --allow-empty -m preimage &&
 	{
 		echo "0. blank-at-eol " &&
 		echo "1. still-blank-at-eol " &&
 		echo "2. and a new line "
 	} >x &&
-	after=$(git rev-parse --short $(git hash-object x)) &&
+	new_hash_x=$(git hash-object x) &&
+	after=$(git rev-parse --short "$new_hash_x") &&
 
 	cat >expect.default-old <<-EOF &&
 	<BOLD>diff --git a/x b/x<RESET>
@@ -974,32 +993,32 @@ test_expect_success 'ws-error-highlight test setup' '
 
 test_expect_success 'test --ws-error-highlight option' '
 
-	git diff --color --ws-error-highlight=default,old |
-	test_decode_color >current &&
+	git diff --color --ws-error-highlight=default,old >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.default-old current &&
 
-	git diff --color --ws-error-highlight=all |
-	test_decode_color >current &&
+	git diff --color --ws-error-highlight=all >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.all current &&
 
-	git diff --color --ws-error-highlight=none |
-	test_decode_color >current &&
+	git diff --color --ws-error-highlight=none >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.none current
 
 '
 
 test_expect_success 'test diff.wsErrorHighlight config' '
 
-	git -c diff.wsErrorHighlight=default,old diff --color |
-	test_decode_color >current &&
+	git -c diff.wsErrorHighlight=default,old diff --color >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.default-old current &&
 
-	git -c diff.wsErrorHighlight=all diff --color |
-	test_decode_color >current &&
+	git -c diff.wsErrorHighlight=all diff --color >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.all current &&
 
-	git -c diff.wsErrorHighlight=none diff --color |
-	test_decode_color >current &&
+	git -c diff.wsErrorHighlight=none diff --color >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.none current
 
 '
@@ -1007,18 +1026,18 @@ test_expect_success 'test diff.wsErrorHighlight config' '
 test_expect_success 'option overrides diff.wsErrorHighlight' '
 
 	git -c diff.wsErrorHighlight=none \
-		diff --color --ws-error-highlight=default,old |
-	test_decode_color >current &&
+		diff --color --ws-error-highlight=default,old >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.default-old current &&
 
 	git -c diff.wsErrorHighlight=default \
-		diff --color --ws-error-highlight=all |
-	test_decode_color >current &&
+		diff --color --ws-error-highlight=all >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.all current &&
 
 	git -c diff.wsErrorHighlight=all \
-		diff --color --ws-error-highlight=none |
-	test_decode_color >current &&
+		diff --color --ws-error-highlight=none >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.none current
 
 '
@@ -1038,7 +1057,8 @@ test_expect_success 'detect moved code, complete file' '
 	git mv test.c main.c &&
 	test_config color.diff.oldMoved "normal red" &&
 	test_config color.diff.newMoved "normal green" &&
-	git diff HEAD --color-moved=zebra --color --no-renames | test_decode_color >actual &&
+	git diff HEAD --color-moved=zebra --color --no-renames >actual.raw &&
+	test_decode_color <actual.raw >actual &&
 	cat >expected <<-EOF &&
 	<BOLD>diff --git a/main.c b/main.c<RESET>
 	<BOLD>new file mode 100644<RESET>
@@ -1141,9 +1161,12 @@ test_expect_success 'detect malicious moved code, inside file' '
 			bar();
 		}
 	EOF
-	after_main=$(git rev-parse --short $(git hash-object main.c)) &&
-	after_test=$(git rev-parse --short $(git hash-object test.c)) &&
-	git diff HEAD --no-renames --color-moved=zebra --color | test_decode_color >actual &&
+	hash_main=$(git hash-object main.c) &&
+	after_main=$(git rev-parse --short "$hash_main") &&
+	hash_test=$(git hash-object test.c) &&
+	after_test=$(git rev-parse --short "$hash_test") &&
+	git diff HEAD --no-renames --color-moved=zebra --color >actual.raw &&
+	test_decode_color <actual.raw >actual &&
 	cat <<-EOF >expected &&
 	<BOLD>diff --git a/main.c b/main.c<RESET>
 	<BOLD>index $before_main..$after_main 100644<RESET>
@@ -1192,7 +1215,8 @@ test_expect_success 'plain moved code, inside file' '
 	test_config color.diff.oldMovedAlternative "blue" &&
 	test_config color.diff.newMovedAlternative "yellow" &&
 	# needs previous test as setup
-	git diff HEAD --no-renames --color-moved=plain --color | test_decode_color >actual &&
+	git diff HEAD --no-renames --color-moved=plain --color >actual.raw &&
+	test_decode_color <actual.raw >actual &&
 	cat <<-EOF >expected &&
 	<BOLD>diff --git a/main.c b/main.c<RESET>
 	<BOLD>index $before_main..$after_main 100644<RESET>
@@ -1771,7 +1795,8 @@ test_expect_success 'move detection with submodules' '
 	! grep BRED decoded_actual &&
 
 	# nor did we mess with it another way
-	git diff --submodule=diff --color | test_decode_color >expect &&
+	git diff --submodule=diff --color >expect.raw &&
+	test_decode_color <expect.raw >expect &&
 	test_cmp expect decoded_actual &&
 	rm -rf bananas &&
 	git submodule deinit bananas
-- 
2.24.0.399.gf8350c9437


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH 09/27] t4015: use test_write_lines()
  2019-11-15  1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu
                   ` (7 preceding siblings ...)
  2019-11-15  1:00 ` [PATCH 08/27] t4015: stop losing return codes of git commands Denton Liu
@ 2019-11-15  1:00 ` Denton Liu
  2019-11-15  1:00 ` [PATCH 10/27] t4138: stop losing return codes of git commands Denton Liu
                   ` (19 subsequent siblings)
  28 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-15  1:00 UTC (permalink / raw)
  To: Git Mailing List

Instead of rolling our own method to write out some lines into a file,
use the existing test_write_lines().

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t4015-diff-whitespace.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh
index 7fb83c8eff..4c540b1d70 100755
--- a/t/t4015-diff-whitespace.sh
+++ b/t/t4015-diff-whitespace.sh
@@ -771,9 +771,9 @@ test_expect_success 'checkdiff detects new trailing blank lines (1)' '
 '
 
 test_expect_success 'checkdiff detects new trailing blank lines (2)' '
-	{ echo a; echo b; echo; echo; } >x &&
+	test_write_lines a b "" "" >x &&
 	git add x &&
-	{ echo a; echo; echo; echo; echo; } >x &&
+	test_write_lines a "" "" "" "" >x &&
 	test_must_fail git diff --check >check &&
 	grep "new blank line" check
 '
-- 
2.24.0.399.gf8350c9437


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH 10/27] t4138: stop losing return codes of git commands
  2019-11-15  1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu
                   ` (8 preceding siblings ...)
  2019-11-15  1:00 ` [PATCH 09/27] t4015: use test_write_lines() Denton Liu
@ 2019-11-15  1:00 ` Denton Liu
  2019-11-16  9:00   ` Eric Sunshine
  2019-11-15  1:00 ` [PATCH 11/27] t5317: " Denton Liu
                   ` (18 subsequent siblings)
  28 siblings, 1 reply; 169+ messages in thread
From: Denton Liu @ 2019-11-15  1:00 UTC (permalink / raw)
  To: Git Mailing List

In a pipe, only the return code of the last command is used. Thus, all
other commands will have their return codes masked. Rewrite pipes so
that there are no git commands upstream so that we will know if a
command fails.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t4138-apply-ws-expansion.sh | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/t/t4138-apply-ws-expansion.sh b/t/t4138-apply-ws-expansion.sh
index 3b636a63a3..60435d6d41 100755
--- a/t/t4138-apply-ws-expansion.sh
+++ b/t/t4138-apply-ws-expansion.sh
@@ -17,8 +17,8 @@ test_expect_success setup '
 	printf "\t%s\n" 1 2 3 >after &&
 	printf "%64s\n" a b c >>after &&
 	printf "\t%s\n" 4 5 6 >>after &&
-	git diff --no-index before after |
-		sed -e "s/before/test-1/" -e "s/after/test-1/" >patch1.patch &&
+	test_must_fail git diff --no-index before after >patch1.patch.raw &&
+	sed -e "s/before/test-1/" -e "s/after/test-1/" patch1.patch.raw >patch1.patch &&
 	printf "%64s\n" 1 2 3 4 5 6 >test-1 &&
 	printf "%64s\n" 1 2 3 a b c 4 5 6 >expect-1 &&
 
@@ -33,8 +33,8 @@ test_expect_success setup '
 		x=$(( $x + 1 ))
 	done &&
 	printf "\t%s\n" d e f >>after &&
-	git diff --no-index before after |
-		sed -e "s/before/test-2/" -e "s/after/test-2/" >patch2.patch &&
+	test_must_fail git diff --no-index before after >patch2.patch.raw &&
+	sed -e "s/before/test-2/" -e "s/after/test-2/" patch2.patch.raw >patch2.patch &&
 	printf "%64s\n" a b c d e f >test-2 &&
 	printf "%64s\n" a b c >expect-2 &&
 	x=1 &&
@@ -56,8 +56,8 @@ test_expect_success setup '
 		x=$(( $x + 1 ))
 	done &&
 	printf "\t%s\n" d e f >>after &&
-	git diff --no-index before after |
-	sed -e "s/before/test-3/" -e "s/after/test-3/" >patch3.patch &&
+	test_must_fail git diff --no-index before after >patch3.patch.raw &&
+	sed -e "s/before/test-3/" -e "s/after/test-3/" patch3.patch.raw >patch3.patch &&
 	printf "%64s\n" a b c d e f >test-3 &&
 	printf "%64s\n" a b c >expect-3 &&
 	x=0 &&
@@ -84,8 +84,8 @@ test_expect_success setup '
 		printf "\t%02d\n" $x >>after
 		x=$(( $x + 1 ))
 	done &&
-	git diff --no-index before after |
-	sed -e "s/before/test-4/" -e "s/after/test-4/" >patch4.patch &&
+	test_must_fail git diff --no-index before after >patch4.patch.raw &&
+	sed -e "s/before/test-4/" -e "s/after/test-4/" patch4.patch.raw >patch4.patch &&
 	>test-4 &&
 	x=0 &&
 	while test $x -lt 50
-- 
2.24.0.399.gf8350c9437


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH 11/27] t5317: stop losing return codes of git commands
  2019-11-15  1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu
                   ` (9 preceding siblings ...)
  2019-11-15  1:00 ` [PATCH 10/27] t4138: stop losing return codes of git commands Denton Liu
@ 2019-11-15  1:00 ` " Denton Liu
  2019-11-15  1:00 ` [PATCH 12/27] t5317: use ! grep to check for no matching lines Denton Liu
                   ` (17 subsequent siblings)
  28 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-15  1:00 UTC (permalink / raw)
  To: Git Mailing List

Currently, there are two ways where the return codes of git commands are
lost. The first way is when a command is in the upstream of a pipe. In a
pipe, only the return code of the last command is used. Thus, all other
commands will have their return codes masked. Rewrite pipes so that
there are no git commands upstream.

The other way is when a command is in a non-assignment command
substitution. The return code will be lost in favour of the surrounding
command's. Rewrite instances of this such that git commands output to a
file and surrounding commands only call command substitutions with
non-git commands.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5317-pack-objects-filter-objects.sh | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/t/t5317-pack-objects-filter-objects.sh b/t/t5317-pack-objects-filter-objects.sh
index 2d2f5d0229..a8bbad74e2 100755
--- a/t/t5317-pack-objects-filter-objects.sh
+++ b/t/t5317-pack-objects-filter-objects.sh
@@ -72,7 +72,8 @@ test_expect_success 'get an error for missing tree object' '
 	echo foo >r5/foo &&
 	git -C r5 add foo &&
 	git -C r5 commit -m "foo" &&
-	del=$(git -C r5 rev-parse HEAD^{tree} | sed "s|..|&/|") &&
+	git -C r5 rev-parse HEAD^{tree} >tree &&
+	del=$(sed "s|..|&/|" tree) &&
 	rm r5/.git/objects/$del &&
 	test_must_fail git -C r5 pack-objects --revs --stdout 2>bad_tree <<-EOF &&
 	HEAD
@@ -230,10 +231,9 @@ test_expect_success 'verify explicitly specifying oversized blob in input' '
 	awk -f print_2.awk ls_files_result |
 	sort >expected &&
 
-	git -C r2 pack-objects --revs --stdout --filter=blob:limit=1k >filter.pack <<-EOF &&
-	HEAD
-	$(git -C r2 rev-parse HEAD:large.10000)
-	EOF
+	echo HEAD >objects &&
+	git -C r2 rev-parse HEAD:large.10000 >>objects &&
+	git -C r2 pack-objects --revs --stdout --filter=blob:limit=1k <objects >filter.pack &&
 	git -C r2 index-pack ../filter.pack &&
 
 	git -C r2 verify-pack -v ../filter.pack >verify_result &&
@@ -377,7 +377,8 @@ test_expect_success 'verify sparse:oid=OID' '
 	awk -f print_2.awk ls_files_result |
 	sort >expected &&
 
-	oid=$(git -C r4 ls-files -s pattern | awk -f print_2.awk) &&
+	git -C r4 ls-files -s pattern >staged &&
+	oid=$(awk -f print_2.awk staged) &&
 	git -C r4 pack-objects --revs --stdout --filter=sparse:oid=$oid >filter.pack <<-EOF &&
 	HEAD
 	EOF
-- 
2.24.0.399.gf8350c9437


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH 12/27] t5317: use ! grep to check for no matching lines
  2019-11-15  1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu
                   ` (10 preceding siblings ...)
  2019-11-15  1:00 ` [PATCH 11/27] t5317: " Denton Liu
@ 2019-11-15  1:00 ` Denton Liu
  2019-11-16  9:27   ` Eric Sunshine
  2019-11-15  1:01 ` [PATCH 13/27] t5703: stop losing return codes of git commands Denton Liu
                   ` (16 subsequent siblings)
  28 siblings, 1 reply; 169+ messages in thread
From: Denton Liu @ 2019-11-15  1:00 UTC (permalink / raw)
  To: Git Mailing List

Several times in t5317, we would use `wc -l` to ensure that a grep
result is empty. However, grep already has a way to do that... Its
return code! Use ! grep in the cases where we are ensuring that there
are no matching lines.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5317-pack-objects-filter-objects.sh | 21 +++------------------
 1 file changed, 3 insertions(+), 18 deletions(-)

diff --git a/t/t5317-pack-objects-filter-objects.sh b/t/t5317-pack-objects-filter-objects.sh
index a8bbad74e2..dc0446574b 100755
--- a/t/t5317-pack-objects-filter-objects.sh
+++ b/t/t5317-pack-objects-filter-objects.sh
@@ -45,12 +45,7 @@ test_expect_success 'verify blob:none packfile has no blobs' '
 	git -C r1 index-pack ../filter.pack &&
 
 	git -C r1 verify-pack -v ../filter.pack >verify_result &&
-	grep blob verify_result |
-	awk -f print_1.awk |
-	sort >observed &&
-
-	nr=$(wc -l <observed) &&
-	test 0 -eq $nr
+	! grep blob verify_result
 '
 
 test_expect_success 'verify normal and blob:none packfiles have same commits/trees' '
@@ -149,12 +144,7 @@ test_expect_success 'verify blob:limit=500 omits all blobs' '
 	git -C r2 index-pack ../filter.pack &&
 
 	git -C r2 verify-pack -v ../filter.pack >verify_result &&
-	grep blob verify_result |
-	awk -f print_1.awk |
-	sort >observed &&
-
-	nr=$(wc -l <observed) &&
-	test 0 -eq $nr
+	! grep blob verify_result
 '
 
 test_expect_success 'verify blob:limit=1000' '
@@ -164,12 +154,7 @@ test_expect_success 'verify blob:limit=1000' '
 	git -C r2 index-pack ../filter.pack &&
 
 	git -C r2 verify-pack -v ../filter.pack >verify_result &&
-	grep blob verify_result |
-	awk -f print_1.awk |
-	sort >observed &&
-
-	nr=$(wc -l <observed) &&
-	test 0 -eq $nr
+	! grep blob verify_result
 '
 
 test_expect_success 'verify blob:limit=1001' '
-- 
2.24.0.399.gf8350c9437


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH 13/27] t5703: stop losing return codes of git commands
  2019-11-15  1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu
                   ` (11 preceding siblings ...)
  2019-11-15  1:00 ` [PATCH 12/27] t5317: use ! grep to check for no matching lines Denton Liu
@ 2019-11-15  1:01 ` Denton Liu
  2019-11-16 10:11   ` Eric Sunshine
  2019-11-15  1:01 ` [PATCH 14/27] t7501: remove spaces after redirect operators Denton Liu
                   ` (15 subsequent siblings)
  28 siblings, 1 reply; 169+ messages in thread
From: Denton Liu @ 2019-11-15  1:01 UTC (permalink / raw)
  To: Git Mailing List

Currently, there are two ways where the return codes of git commands are
lost. The first way is when a command is in the upstream of a pipe. In a
pipe, only the return code of the last command is used. Thus, all other
commands will have their return codes masked. Rewrite pipes so that
there are no git commands upstream.

The other way is when a command is in a non-assignment command
substitution. The return code will be lost in favour of the surrounding
command's. Rewrite instances of this such that git commands are in an
assignment-only command substitution.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5703-upload-pack-ref-in-want.sh | 52 +++++++++++++++++++-----------
 1 file changed, 33 insertions(+), 19 deletions(-)

diff --git a/t/t5703-upload-pack-ref-in-want.sh b/t/t5703-upload-pack-ref-in-want.sh
index 3a2c143c6d..9f6d837720 100755
--- a/t/t5703-upload-pack-ref-in-want.sh
+++ b/t/t5703-upload-pack-ref-in-want.sh
@@ -18,14 +18,16 @@ get_actual_commits () {
 		p
 		}' <out | test-tool pkt-line unpack-sideband >o.pack &&
 	git index-pack o.pack &&
-	git verify-pack -v o.idx | grep commit | cut -c-40 | sort >actual_commits
+	git verify-pack -v o.idx >objs &&
+	grep commit objs | cut -c-40 | sort >actual_commits
 }
 
 check_output () {
 	get_actual_refs &&
 	test_cmp expected_refs actual_refs &&
 	get_actual_commits &&
-	test_cmp expected_commits actual_commits
+	sort expected_commits >sorted_commits &&
+	test_cmp sorted_commits actual_commits
 }
 
 # c(o/foo) d(o/bar)
@@ -75,17 +77,19 @@ test_expect_success 'invalid want-ref line' '
 '
 
 test_expect_success 'basic want-ref' '
+	oid=$(git rev-parse f) &&
 	cat >expected_refs <<-EOF &&
-	$(git rev-parse f) refs/heads/master
+	$oid refs/heads/master
 	EOF
-	git rev-parse f | sort >expected_commits &&
+	git rev-parse f >expected_commits &&
 
+	oid=$(git rev-parse a) &&
 	test-tool pkt-line pack >in <<-EOF &&
 	command=fetch
 	0001
 	no-progress
 	want-ref refs/heads/master
-	have $(git rev-parse a)
+	have $oid
 	done
 	0000
 	EOF
@@ -95,19 +99,22 @@ test_expect_success 'basic want-ref' '
 '
 
 test_expect_success 'multiple want-ref lines' '
+	oid_c=$(git rev-parse c) &&
+	oid_d=$(git rev-parse d) &&
 	cat >expected_refs <<-EOF &&
-	$(git rev-parse c) refs/heads/o/foo
-	$(git rev-parse d) refs/heads/o/bar
+	$oid_c refs/heads/o/foo
+	$oid_d refs/heads/o/bar
 	EOF
-	git rev-parse c d | sort >expected_commits &&
+	git rev-parse c d >expected_commits &&
 
+	oid=$(git rev-parse b) &&
 	test-tool pkt-line pack >in <<-EOF &&
 	command=fetch
 	0001
 	no-progress
 	want-ref refs/heads/o/foo
 	want-ref refs/heads/o/bar
-	have $(git rev-parse b)
+	have $oid
 	done
 	0000
 	EOF
@@ -117,10 +124,11 @@ test_expect_success 'multiple want-ref lines' '
 '
 
 test_expect_success 'mix want and want-ref' '
+	oid=$(git rev-parse f) &&
 	cat >expected_refs <<-EOF &&
-	$(git rev-parse f) refs/heads/master
+	$oid refs/heads/master
 	EOF
-	git rev-parse e f | sort >expected_commits &&
+	git rev-parse e f >expected_commits &&
 
 	test-tool pkt-line pack >in <<-EOF &&
 	command=fetch
@@ -138,17 +146,19 @@ test_expect_success 'mix want and want-ref' '
 '
 
 test_expect_success 'want-ref with ref we already have commit for' '
+	oid=$(git rev-parse c) &&
 	cat >expected_refs <<-EOF &&
-	$(git rev-parse c) refs/heads/o/foo
+	$oid refs/heads/o/foo
 	EOF
 	>expected_commits &&
 
+	oid=$(git rev-parse c) &&
 	test-tool pkt-line pack >in <<-EOF &&
 	command=fetch
 	0001
 	no-progress
 	want-ref refs/heads/o/foo
-	have $(git rev-parse c)
+	have $oid
 	done
 	0000
 	EOF
@@ -211,13 +221,14 @@ test_expect_success 'fetching with exact OID' '
 
 	rm -rf local &&
 	cp -r "$LOCAL_PRISTINE" local &&
+	oid=$(git -C "$REPO" rev-parse d) &&
 	GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin \
-		$(git -C "$REPO" rev-parse d):refs/heads/actual &&
+		"$oid":refs/heads/actual &&
 
 	git -C "$REPO" rev-parse "d" >expected &&
 	git -C local rev-parse refs/heads/actual >actual &&
 	test_cmp expected actual &&
-	grep "want $(git -C "$REPO" rev-parse d)" log
+	grep "want $oid" log
 '
 
 test_expect_success 'fetching multiple refs' '
@@ -239,13 +250,14 @@ test_expect_success 'fetching ref and exact OID' '
 
 	rm -rf local &&
 	cp -r "$LOCAL_PRISTINE" local &&
+	oid=$(git -C "$REPO" rev-parse b) &&
 	GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin \
-		master $(git -C "$REPO" rev-parse b):refs/heads/actual &&
+		master "$oid":refs/heads/actual &&
 
 	git -C "$REPO" rev-parse "master" "b" >expected &&
 	git -C local rev-parse refs/remotes/origin/master refs/heads/actual >actual &&
 	test_cmp expected actual &&
-	grep "want $(git -C "$REPO" rev-parse b)" log &&
+	grep "want $oid" log &&
 	grep "want-ref refs/heads/master" log
 '
 
@@ -312,9 +324,11 @@ inconsistency () {
 	# repository appears to change during negotiation, for example, when
 	# different servers in a load-balancing arrangement serve (stateless)
 	# RPCs during a single negotiation.
+	oid1=$(git -C "$REPO" rev-parse $1) &&
+	oid2=$(git -C "$REPO" rev-parse $2) &&
 	printf "s/%s/%s/" \
-	       $(git -C "$REPO" rev-parse $1 | tr -d "\n") \
-	       $(git -C "$REPO" rev-parse $2 | tr -d "\n") \
+	       $(echo "$oid1" | tr -d "\n") \
+	       $(echo "$oid2" | tr -d "\n") \
 	       >"$HTTPD_ROOT_PATH/one-time-sed"
 }
 
-- 
2.24.0.399.gf8350c9437


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH 14/27] t7501: remove spaces after redirect operators
  2019-11-15  1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu
                   ` (12 preceding siblings ...)
  2019-11-15  1:01 ` [PATCH 13/27] t5703: stop losing return codes of git commands Denton Liu
@ 2019-11-15  1:01 ` Denton Liu
  2019-11-15  1:01 ` [PATCH 15/27] t7501: stop losing return codes of git commands Denton Liu
                   ` (14 subsequent siblings)
  28 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-15  1:01 UTC (permalink / raw)
  To: Git Mailing List

For shell scripts, the usual convention is for there to be no space
after redirection operators, (e.g. `>file`, not `> file`). Remove these
spaces wherever they appear.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7501-commit-basic-functionality.sh | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/t/t7501-commit-basic-functionality.sh b/t/t7501-commit-basic-functionality.sh
index f1349af56e..5765d33c53 100755
--- a/t/t7501-commit-basic-functionality.sh
+++ b/t/t7501-commit-basic-functionality.sh
@@ -150,7 +150,7 @@ test_expect_success 'setup: commit message from file' '
 test_expect_success 'amend commit' '
 	cat >editor <<-\EOF &&
 	#!/bin/sh
-	sed -e "s/a file/an amend commit/g" < "$1" > "$1-"
+	sed -e "s/a file/an amend commit/g" <"$1" >"$1-"
 	mv "$1-" "$1"
 	EOF
 	chmod 755 editor &&
@@ -263,7 +263,7 @@ test_expect_success 'using message from other commit' '
 test_expect_success 'editing message from other commit' '
 	cat >editor <<-\EOF &&
 	#!/bin/sh
-	sed -e "s/amend/older/g"  < "$1" > "$1-"
+	sed -e "s/amend/older/g"  <"$1" >"$1-"
 	mv "$1-" "$1"
 	EOF
 	chmod 755 editor &&
@@ -367,7 +367,7 @@ test_expect_success 'amend commit to fix author' '
 		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
 		expected &&
 	git commit --amend --author="$author" &&
-	git cat-file -p HEAD > current &&
+	git cat-file -p HEAD >current &&
 	test_cmp expected current
 
 '
@@ -382,7 +382,7 @@ test_expect_success 'amend commit to fix date' '
 		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
 		expected &&
 	git commit --amend --date="$newtick" &&
-	git cat-file -p HEAD > current &&
+	git cat-file -p HEAD >current &&
 	test_cmp expected current
 
 '
@@ -448,7 +448,7 @@ test_expect_success 'signoff gap' '
 	git commit -s -m "welcome
 
 $alt" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
+	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
 	(
 		echo welcome &&
 		echo &&
@@ -468,7 +468,7 @@ test_expect_success 'signoff gap 2' '
 
 We have now
 $alt" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
+	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
 	(
 		echo welcome &&
 		echo &&
@@ -489,7 +489,7 @@ test_expect_success 'signoff respects trailer config' '
 
 non-trailer line
 Myfooter: x" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
+	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
 	(
 		echo subject &&
 		echo &&
@@ -506,7 +506,7 @@ Myfooter: x" &&
 
 non-trailer line
 Myfooter: x" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
+	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
 	(
 		echo subject &&
 		echo &&
@@ -560,14 +560,14 @@ test_expect_success 'amend commit to fix author' '
 		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
 		expected &&
 	git commit --amend --author="$author" &&
-	git cat-file -p HEAD > current &&
+	git cat-file -p HEAD >current &&
 	test_cmp expected current
 
 '
 
 test_expect_success 'git commit <file> with dirty index' '
-	echo tacocat > elif &&
-	echo tehlulz > chz &&
+	echo tacocat >elif &&
+	echo tehlulz >chz &&
 	git add chz &&
 	git commit elif -m "tacocat is a palindrome" &&
 	git show --stat | grep elif &&
-- 
2.24.0.399.gf8350c9437


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH 15/27] t7501: stop losing return codes of git commands
  2019-11-15  1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu
                   ` (13 preceding siblings ...)
  2019-11-15  1:01 ` [PATCH 14/27] t7501: remove spaces after redirect operators Denton Liu
@ 2019-11-15  1:01 ` Denton Liu
  2019-11-16 10:35   ` Eric Sunshine
  2019-11-15  1:01 ` [PATCH 16/27] t7700: drop redirections to /dev/null Denton Liu
                   ` (13 subsequent siblings)
  28 siblings, 1 reply; 169+ messages in thread
From: Denton Liu @ 2019-11-15  1:01 UTC (permalink / raw)
  To: Git Mailing List

In a pipe, only the return code of the last command is used. Thus, all
other commands will have their return codes masked. Rewrite pipes so
that there are no git commands upstream so that we will know if a
command fails.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7501-commit-basic-functionality.sh | 69 +++++++++++++++------------
 1 file changed, 39 insertions(+), 30 deletions(-)

diff --git a/t/t7501-commit-basic-functionality.sh b/t/t7501-commit-basic-functionality.sh
index 5765d33c53..110b4bf459 100755
--- a/t/t7501-commit-basic-functionality.sh
+++ b/t/t7501-commit-basic-functionality.sh
@@ -285,9 +285,8 @@ test_expect_success 'overriding author from command line' '
 '
 
 test_expect_success PERL 'interactive add' '
-	echo 7 |
-	git commit --interactive |
-	grep "What now"
+	echo 7 | test_must_fail git commit --interactive >out &&
+	grep "What now" out
 '
 
 test_expect_success PERL "commit --interactive doesn't change index if editor aborts" '
@@ -362,10 +361,10 @@ test_expect_success 'amend commit to fix author' '
 	oldtick=$GIT_AUTHOR_DATE &&
 	test_tick &&
 	git reset --hard &&
-	git cat-file -p HEAD |
+	git cat-file -p HEAD >commit &&
 	sed -e "s/author.*/author $author $oldtick/" \
-		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
-		expected &&
+		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" \
+		commit >expected &&
 	git commit --amend --author="$author" &&
 	git cat-file -p HEAD >current &&
 	test_cmp expected current
@@ -377,10 +376,10 @@ test_expect_success 'amend commit to fix date' '
 	test_tick &&
 	newtick=$GIT_AUTHOR_DATE &&
 	git reset --hard &&
-	git cat-file -p HEAD |
+	git cat-file -p HEAD >commit &&
 	sed -e "s/author.*/author $author $newtick/" \
-		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
-		expected &&
+		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" \
+		commit >expected &&
 	git commit --amend --date="$newtick" &&
 	git cat-file -p HEAD >current &&
 	test_cmp expected current
@@ -409,12 +408,13 @@ test_expect_success 'sign off (1)' '
 	echo 1 >positive &&
 	git add positive &&
 	git commit -s -m "thank you" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
+	git cat-file commit HEAD >commit &&
+	sed -e "1,/^\$/d" commit >actual &&
 	(
 		echo thank you &&
 		echo &&
-		git var GIT_COMMITTER_IDENT |
-		sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
+		git var GIT_COMMITTER_IDENT >ident &&
+		sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" ident
 	) >expected &&
 	test_cmp expected actual
 
@@ -428,13 +428,14 @@ test_expect_success 'sign off (2)' '
 	git commit -s -m "thank you
 
 $existing" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
+	git cat-file commit HEAD >commit &&
+	sed -e "1,/^\$/d" commit >actual &&
 	(
 		echo thank you &&
 		echo &&
 		echo $existing &&
-		git var GIT_COMMITTER_IDENT |
-		sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
+		git var GIT_COMMITTER_IDENT >ident &&
+		sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" ident
 	) >expected &&
 	test_cmp expected actual
 
@@ -448,13 +449,14 @@ test_expect_success 'signoff gap' '
 	git commit -s -m "welcome
 
 $alt" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
+	git cat-file commit HEAD >commit &&
+	sed -e "1,/^\$/d" commit >actual &&
 	(
 		echo welcome &&
 		echo &&
 		echo $alt &&
-		git var GIT_COMMITTER_IDENT |
-		sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
+		git var GIT_COMMITTER_IDENT >ident &&
+		sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" ident
 	) >expected &&
 	test_cmp expected actual
 '
@@ -468,15 +470,16 @@ test_expect_success 'signoff gap 2' '
 
 We have now
 $alt" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
+	git cat-file commit HEAD >commit &&
+	sed -e "1,/^\$/d" commit >actual &&
 	(
 		echo welcome &&
 		echo &&
 		echo We have now &&
 		echo $alt &&
 		echo &&
-		git var GIT_COMMITTER_IDENT |
-		sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
+		git var GIT_COMMITTER_IDENT >ident &&
+		sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" ident
 	) >expected &&
 	test_cmp expected actual
 '
@@ -489,7 +492,8 @@ test_expect_success 'signoff respects trailer config' '
 
 non-trailer line
 Myfooter: x" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
+	git cat-file commit HEAD >commit &&
+	sed -e "1,/^\$/d" commit >actual &&
 	(
 		echo subject &&
 		echo &&
@@ -506,7 +510,8 @@ Myfooter: x" &&
 
 non-trailer line
 Myfooter: x" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
+	git cat-file commit HEAD >commit &&
+	sed -e "1,/^\$/d" commit >actual &&
 	(
 		echo subject &&
 		echo &&
@@ -538,7 +543,8 @@ test_expect_success 'multiple -m' '
 	>negative &&
 	git add negative &&
 	git commit -m "one" -m "two" -m "three" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
+	git cat-file commit HEAD >commit &&
+	sed -e "1,/^\$/d" commit >actual &&
 	(
 		echo one &&
 		echo &&
@@ -555,10 +561,10 @@ test_expect_success 'amend commit to fix author' '
 	oldtick=$GIT_AUTHOR_DATE &&
 	test_tick &&
 	git reset --hard &&
-	git cat-file -p HEAD |
+	git cat-file -p HEAD >commit &&
 	sed -e "s/author.*/author $author $oldtick/" \
-		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
-		expected &&
+		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" \
+		commit >expected &&
 	git commit --amend --author="$author" &&
 	git cat-file -p HEAD >current &&
 	test_cmp expected current
@@ -570,8 +576,10 @@ test_expect_success 'git commit <file> with dirty index' '
 	echo tehlulz >chz &&
 	git add chz &&
 	git commit elif -m "tacocat is a palindrome" &&
-	git show --stat | grep elif &&
-	git diff --cached | grep chz
+	git show --stat >stat &&
+	grep elif stat &&
+	git diff --cached >diff &&
+	grep chz diff
 '
 
 test_expect_success 'same tree (single parent)' '
@@ -584,7 +592,8 @@ test_expect_success 'same tree (single parent)' '
 test_expect_success 'same tree (single parent) --allow-empty' '
 
 	git commit --allow-empty -m "forced empty" &&
-	git cat-file commit HEAD | grep forced
+	git cat-file commit HEAD >commit &&
+	grep forced commit
 
 '
 
-- 
2.24.0.399.gf8350c9437


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH 16/27] t7700: drop redirections to /dev/null
  2019-11-15  1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu
                   ` (14 preceding siblings ...)
  2019-11-15  1:01 ` [PATCH 15/27] t7501: stop losing return codes of git commands Denton Liu
@ 2019-11-15  1:01 ` Denton Liu
  2019-11-15  1:01 ` [PATCH 17/27] t7700: remove spaces after redirect operators Denton Liu
                   ` (12 subsequent siblings)
  28 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-15  1:01 UTC (permalink / raw)
  To: Git Mailing List

Since output is silenced when running without `-v` and debugging output
is useful with `-v`, remove redirections to /dev/null as it is not
useful.

In one case where the output of stdout is consumed, redirect the output
of test_commit to stderr.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7700-repack.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index 4e855bc21b..e1a689d6a9 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -5,7 +5,7 @@ test_description='git repack works correctly'
 . ./test-lib.sh
 
 commit_and_pack() {
-	test_commit "$@" >/dev/null &&
+	test_commit "$@" 1>&2 &&
 	SHA1=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) &&
 	echo pack-${SHA1}.pack
 }
@@ -19,7 +19,7 @@ test_expect_success 'objects in packs marked .keep are not repacked' '
 	# Create two packs
 	# The first pack will contain all of the objects except one
 	git rev-list --objects --all | grep -v file2 |
-		git pack-objects pack > /dev/null &&
+		git pack-objects pack &&
 	# The second pack will contain the excluded object
 	packsha1=$(git rev-list --objects --all | grep file2 |
 		git pack-objects pack) &&
@@ -235,7 +235,7 @@ test_expect_success 'incremental repack does not complain' '
 
 test_expect_success 'bitmaps can be disabled on bare repos' '
 	git -c repack.writeBitmaps=false -C bare.git repack -ad &&
-	bitmap=$(ls bare.git/objects/pack/*.bitmap 2>/dev/null || :) &&
+	bitmap=$(ls bare.git/objects/pack/*.bitmap || :) &&
 	test -z "$bitmap"
 '
 
-- 
2.24.0.399.gf8350c9437


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH 17/27] t7700: remove spaces after redirect operators
  2019-11-15  1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu
                   ` (15 preceding siblings ...)
  2019-11-15  1:01 ` [PATCH 16/27] t7700: drop redirections to /dev/null Denton Liu
@ 2019-11-15  1:01 ` Denton Liu
  2019-11-15  1:01 ` [PATCH 18/27] t7700: move keywords onto their own line Denton Liu
                   ` (11 subsequent siblings)
  28 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-15  1:01 UTC (permalink / raw)
  To: Git Mailing List

For shell scripts, the usual convention is for there to be no space
after redirection operators, (e.g. `>file`, not `> file`). Remove these
spaces wherever they appear.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7700-repack.sh | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index e1a689d6a9..8936928387 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -11,8 +11,8 @@ commit_and_pack() {
 }
 
 test_expect_success 'objects in packs marked .keep are not repacked' '
-	echo content1 > file1 &&
-	echo content2 > file2 &&
+	echo content1 >file1 &&
+	echo content2 >file2 &&
 	git add . &&
 	test_tick &&
 	git commit -m initial_commit &&
@@ -75,8 +75,8 @@ test_expect_success 'writing bitmaps via config can duplicate .keep objects' '
 
 test_expect_success 'loose objects in alternate ODB are not repacked' '
 	mkdir alt_objects &&
-	echo $(pwd)/alt_objects > .git/objects/info/alternates &&
-	echo content3 > file3 &&
+	echo $(pwd)/alt_objects >.git/objects/info/alternates &&
+	echo content3 >file3 &&
 	objsha1=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) &&
 	git add file3 &&
 	test_tick &&
@@ -111,7 +111,7 @@ test_expect_success 'packed obs in alt ODB are repacked even when local repo is
 
 test_expect_success 'packed obs in alt ODB are repacked when local repo has packs' '
 	rm -f .git/objects/pack/* &&
-	echo new_content >> file1 &&
+	echo new_content >>file1 &&
 	git add file1 &&
 	test_tick &&
 	git commit -m more_content &&
@@ -169,12 +169,12 @@ test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
 	mv pack-* .git/objects/pack/ &&
 	test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
 		egrep "^$csha1 " | sort | uniq | wc -l) &&
-	echo > .git/objects/info/alternates &&
+	echo >.git/objects/info/alternates &&
 	test_must_fail git show $csha1
 '
 
 test_expect_success 'local packed unreachable obs that exist in alternate ODB are not loosened' '
-	echo $(pwd)/alt_objects > .git/objects/info/alternates &&
+	echo $(pwd)/alt_objects >.git/objects/info/alternates &&
 	echo "$csha1" | git pack-objects --non-empty --all --reflog pack &&
 	rm -f .git/objects/pack/* &&
 	mv pack-* .git/objects/pack/ &&
@@ -186,7 +186,7 @@ test_expect_success 'local packed unreachable obs that exist in alternate ODB ar
 	mv pack-* .git/objects/pack/ &&
 	test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
 		egrep "^$csha1 " | sort | uniq | wc -l) &&
-	echo > .git/objects/info/alternates &&
+	echo >.git/objects/info/alternates &&
 	test_must_fail git show $csha1
 '
 
@@ -196,7 +196,7 @@ test_expect_success 'objects made unreachable by grafts only are kept' '
 	H0=$(git rev-parse HEAD) &&
 	H1=$(git rev-parse HEAD^) &&
 	H2=$(git rev-parse HEAD^^) &&
-	echo "$H0 $H2" > .git/info/grafts &&
+	echo "$H0 $H2" >.git/info/grafts &&
 	git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all &&
 	git repack -a -d &&
 	git cat-file -t $H1
-- 
2.24.0.399.gf8350c9437


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH 18/27] t7700: move keywords onto their own line
  2019-11-15  1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu
                   ` (16 preceding siblings ...)
  2019-11-15  1:01 ` [PATCH 17/27] t7700: remove spaces after redirect operators Denton Liu
@ 2019-11-15  1:01 ` Denton Liu
  2019-11-15  1:01 ` [PATCH 19/27] t7700: s/test -f/test_path_is_file/ Denton Liu
                   ` (10 subsequent siblings)
  28 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-15  1:01 UTC (permalink / raw)
  To: Git Mailing List

The code style for tests is to have statements on their own line if
possible. Move keywords onto their own line so that they conform with
the test style.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7700-repack.sh | 51 +++++++++++++++++++++++++++++++----------------
 1 file changed, 34 insertions(+), 17 deletions(-)

diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index 8936928387..a96e876c4e 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -29,10 +29,12 @@ test_expect_success 'objects in packs marked .keep are not repacked' '
 	mv pack-* .git/objects/pack/ &&
 	git repack -A -d -l &&
 	git prune-packed &&
-	for p in .git/objects/pack/*.idx; do
+	for p in .git/objects/pack/*.idx
+	do
 		idx=$(basename $p)
 		test "pack-$packsha1.idx" = "$idx" && continue
-		if git verify-pack -v $p | egrep "^$objsha1"; then
+		if git verify-pack -v $p | egrep "^$objsha1"
+		then
 			found_duplicate_object=1
 			echo "DUPLICATE OBJECT FOUND"
 			break
@@ -45,10 +47,12 @@ test_expect_success 'writing bitmaps via command-line can duplicate .keep object
 	# build on $objsha1, $packsha1, and .keep state from previous
 	git repack -Adbl &&
 	test_when_finished "found_duplicate_object=" &&
-	for p in .git/objects/pack/*.idx; do
+	for p in .git/objects/pack/*.idx
+	do
 		idx=$(basename $p)
 		test "pack-$packsha1.idx" = "$idx" && continue
-		if git verify-pack -v $p | egrep "^$objsha1"; then
+		if git verify-pack -v $p | egrep "^$objsha1"
+		then
 			found_duplicate_object=1
 			echo "DUPLICATE OBJECT FOUND"
 			break
@@ -61,10 +65,12 @@ test_expect_success 'writing bitmaps via config can duplicate .keep objects' '
 	# build on $objsha1, $packsha1, and .keep state from previous
 	git -c repack.writebitmaps=true repack -Adl &&
 	test_when_finished "found_duplicate_object=" &&
-	for p in .git/objects/pack/*.idx; do
+	for p in .git/objects/pack/*.idx
+	do
 		idx=$(basename $p)
 		test "pack-$packsha1.idx" = "$idx" && continue
-		if git verify-pack -v $p | egrep "^$objsha1"; then
+		if git verify-pack -v $p | egrep "^$objsha1"
+		then
 			found_duplicate_object=1
 			echo "DUPLICATE OBJECT FOUND"
 			break
@@ -83,8 +89,10 @@ test_expect_success 'loose objects in alternate ODB are not repacked' '
 	git commit -m commit_file3 &&
 	git repack -a -d -l &&
 	git prune-packed &&
-	for p in .git/objects/pack/*.idx; do
-		if git verify-pack -v $p | egrep "^$objsha1"; then
+	for p in .git/objects/pack/*.idx
+	do
+		if git verify-pack -v $p | egrep "^$objsha1"
+		then
 			found_duplicate_object=1
 			echo "DUPLICATE OBJECT FOUND"
 			break
@@ -99,10 +107,13 @@ test_expect_success 'packed obs in alt ODB are repacked even when local repo is
 	git repack -a &&
 	myidx=$(ls -1 .git/objects/pack/*.idx) &&
 	test -f "$myidx" &&
-	for p in alt_objects/pack/*.idx; do
+	for p in alt_objects/pack/*.idx
+	do
 		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
-	done | while read sha1 rest; do
-		if ! ( git verify-pack -v $myidx | grep "^$sha1" ); then
+	done | while read sha1 rest
+	do
+		if ! ( git verify-pack -v $myidx | grep "^$sha1" )
+		then
 			echo "Missing object in local pack: $sha1"
 			return 1
 		fi
@@ -119,10 +130,13 @@ test_expect_success 'packed obs in alt ODB are repacked when local repo has pack
 	git repack -a -d &&
 	myidx=$(ls -1 .git/objects/pack/*.idx) &&
 	test -f "$myidx" &&
-	for p in alt_objects/pack/*.idx; do
+	for p in alt_objects/pack/*.idx
+	do
 		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
-	done | while read sha1 rest; do
-		if ! ( git verify-pack -v $myidx | grep "^$sha1" ); then
+	done | while read sha1 rest
+	do
+		if ! ( git verify-pack -v $myidx | grep "^$sha1" )
+		then
 			echo "Missing object in local pack: $sha1"
 			return 1
 		fi
@@ -144,10 +158,13 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
 	git repack -a -d &&
 	myidx=$(ls -1 .git/objects/pack/*.idx) &&
 	test -f "$myidx" &&
-	for p in alt_objects/pack/*.idx; do
+	for p in alt_objects/pack/*.idx
+	do
 		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
-	done | while read sha1 rest; do
-		if ! ( git verify-pack -v $myidx | grep "^$sha1" ); then
+	done | while read sha1 rest
+	do
+		if ! ( git verify-pack -v $myidx | grep "^$sha1" )
+		then
 			echo "Missing object in local pack: $sha1"
 			return 1
 		fi
-- 
2.24.0.399.gf8350c9437


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH 19/27] t7700: s/test -f/test_path_is_file/
  2019-11-15  1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu
                   ` (17 preceding siblings ...)
  2019-11-15  1:01 ` [PATCH 18/27] t7700: move keywords onto their own line Denton Liu
@ 2019-11-15  1:01 ` Denton Liu
  2019-11-15  1:01 ` [PATCH 20/27] t7700: stop losing return codes of git commands Denton Liu
                   ` (9 subsequent siblings)
  28 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-15  1:01 UTC (permalink / raw)
  To: Git Mailing List

Since we have debugging-friendly alternatives to `test -f`, replace
instances of `test -f` with `test_path_is_file` so that if a command
ever fails, we get better debugging information.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7700-repack.sh | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index a96e876c4e..1d14ddcbdb 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -106,7 +106,7 @@ test_expect_success 'packed obs in alt ODB are repacked even when local repo is
 	mv .git/objects/pack/* alt_objects/pack &&
 	git repack -a &&
 	myidx=$(ls -1 .git/objects/pack/*.idx) &&
-	test -f "$myidx" &&
+	test_path_is_file "$myidx" &&
 	for p in alt_objects/pack/*.idx
 	do
 		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
@@ -129,7 +129,7 @@ test_expect_success 'packed obs in alt ODB are repacked when local repo has pack
 	git repack &&
 	git repack -a -d &&
 	myidx=$(ls -1 .git/objects/pack/*.idx) &&
-	test -f "$myidx" &&
+	test_path_is_file "$myidx" &&
 	for p in alt_objects/pack/*.idx
 	do
 		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
@@ -148,7 +148,7 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
 	for p in alt_objects/pack/*.pack
 	do
 		base_name=$(basename $p .pack) &&
-		if test -f alt_objects/pack/$base_name.keep
+		if test_path_is_file alt_objects/pack/$base_name.keep
 		then
 			rm alt_objects/pack/$base_name.keep
 		else
@@ -157,7 +157,7 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
 	done &&
 	git repack -a -d &&
 	myidx=$(ls -1 .git/objects/pack/*.idx) &&
-	test -f "$myidx" &&
+	test_path_is_file "$myidx" &&
 	for p in alt_objects/pack/*.idx
 	do
 		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
-- 
2.24.0.399.gf8350c9437


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH 20/27] t7700: stop losing return codes of git commands
  2019-11-15  1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu
                   ` (18 preceding siblings ...)
  2019-11-15  1:01 ` [PATCH 19/27] t7700: s/test -f/test_path_is_file/ Denton Liu
@ 2019-11-15  1:01 ` Denton Liu
  2019-11-15  1:01 ` [PATCH 21/27] t: define test_grep_return_success() Denton Liu
                   ` (8 subsequent siblings)
  28 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-15  1:01 UTC (permalink / raw)
  To: Git Mailing List

In a pipe, only the return code of the last command is used. Thus, all
other commands will have their return codes masked. Rewrite pipes so
that there are no git commands upstream so that we will know if a
command fails.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7700-repack.sh | 64 ++++++++++++++++++++++++++++-------------------
 1 file changed, 38 insertions(+), 26 deletions(-)

diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index 1d14ddcbdb..ff50722e26 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -18,14 +18,13 @@ test_expect_success 'objects in packs marked .keep are not repacked' '
 	git commit -m initial_commit &&
 	# Create two packs
 	# The first pack will contain all of the objects except one
-	git rev-list --objects --all | grep -v file2 |
-		git pack-objects pack &&
+	git rev-list --objects --all >objs &&
+	grep -v file2 objs | git pack-objects pack &&
 	# The second pack will contain the excluded object
-	packsha1=$(git rev-list --objects --all | grep file2 |
-		git pack-objects pack) &&
+	packsha1=$(grep file2 objs | git pack-objects pack) &&
 	>pack-$packsha1.keep &&
-	objsha1=$(git verify-pack -v pack-$packsha1.idx | head -n 1 |
-		sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") &&
+	git verify-pack -v pack-$packsha1.idx >packlist &&
+	objsha1=$(head -n 1 packlist | sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") &&
 	mv pack-* .git/objects/pack/ &&
 	git repack -A -d -l &&
 	git prune-packed &&
@@ -33,7 +32,8 @@ test_expect_success 'objects in packs marked .keep are not repacked' '
 	do
 		idx=$(basename $p)
 		test "pack-$packsha1.idx" = "$idx" && continue
-		if git verify-pack -v $p | egrep "^$objsha1"
+		git verify-pack -v $p >packlist || return $?
+		if egrep "^$objsha1" packlist
 		then
 			found_duplicate_object=1
 			echo "DUPLICATE OBJECT FOUND"
@@ -51,7 +51,8 @@ test_expect_success 'writing bitmaps via command-line can duplicate .keep object
 	do
 		idx=$(basename $p)
 		test "pack-$packsha1.idx" = "$idx" && continue
-		if git verify-pack -v $p | egrep "^$objsha1"
+		git verify-pack -v $p >packlist || return $?
+		if egrep "^$objsha1" packlist
 		then
 			found_duplicate_object=1
 			echo "DUPLICATE OBJECT FOUND"
@@ -69,7 +70,8 @@ test_expect_success 'writing bitmaps via config can duplicate .keep objects' '
 	do
 		idx=$(basename $p)
 		test "pack-$packsha1.idx" = "$idx" && continue
-		if git verify-pack -v $p | egrep "^$objsha1"
+		git verify-pack -v $p >packlist || return $?
+		if egrep "^$objsha1" packlist
 		then
 			found_duplicate_object=1
 			echo "DUPLICATE OBJECT FOUND"
@@ -91,7 +93,8 @@ test_expect_success 'loose objects in alternate ODB are not repacked' '
 	git prune-packed &&
 	for p in .git/objects/pack/*.idx
 	do
-		if git verify-pack -v $p | egrep "^$objsha1"
+		git verify-pack -v $p >packlist || return $?
+		if egrep "^$objsha1" packlist
 		then
 			found_duplicate_object=1
 			echo "DUPLICATE OBJECT FOUND"
@@ -109,15 +112,18 @@ test_expect_success 'packed obs in alt ODB are repacked even when local repo is
 	test_path_is_file "$myidx" &&
 	for p in alt_objects/pack/*.idx
 	do
-		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
-	done | while read sha1 rest
+		git verify-pack -v $p >packlist || return $?
+		sed -n -e "/^[0-9a-f]\{40\}/p"
+	done >packs &&
+	git verify-pack -v $myidx >mypacklist &&
+	while read sha1 rest
 	do
-		if ! ( git verify-pack -v $myidx | grep "^$sha1" )
+		if ! grep "^$sha1" mypacklist
 		then
 			echo "Missing object in local pack: $sha1"
 			return 1
 		fi
-	done
+	done <packs
 '
 
 test_expect_success 'packed obs in alt ODB are repacked when local repo has packs' '
@@ -132,15 +138,18 @@ test_expect_success 'packed obs in alt ODB are repacked when local repo has pack
 	test_path_is_file "$myidx" &&
 	for p in alt_objects/pack/*.idx
 	do
-		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
-	done | while read sha1 rest
+		git verify-pack -v $p >packlist || return $?
+		sed -n -e "/^[0-9a-f]\{40\}/p" packlist
+	done >packs &&
+	git verify-pack -v $myidx >mypacklist &&
+	while read sha1 rest
 	do
-		if ! ( git verify-pack -v $myidx | grep "^$sha1" )
+		if ! grep "^$sha1" mypacklist
 		then
 			echo "Missing object in local pack: $sha1"
 			return 1
 		fi
-	done
+	done <packs
 '
 
 test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
@@ -160,15 +169,18 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
 	test_path_is_file "$myidx" &&
 	for p in alt_objects/pack/*.idx
 	do
-		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
-	done | while read sha1 rest
+		git verify-pack -v $p >packlist || return $?
+		sed -n -e "/^[0-9a-f]\{40\}/p" packlist
+	done >packs &&
+	git verify-pack -v $myidx >mypacklist &&
+	while read sha1 rest
 	do
-		if ! ( git verify-pack -v $myidx | grep "^$sha1" )
+		if ! grep "^$sha1" mypacklist
 		then
 			echo "Missing object in local pack: $sha1"
 			return 1
 		fi
-	done
+	done <packs
 '
 
 test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
@@ -184,8 +196,8 @@ test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
 	    --unpack-unreachable </dev/null pack &&
 	rm -f .git/objects/pack/* &&
 	mv pack-* .git/objects/pack/ &&
-	test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
-		egrep "^$csha1 " | sort | uniq | wc -l) &&
+	git verify-pack -v -- .git/objects/pack/*.idx >packlist &&
+	! egrep "^$csha1 " packlist &&
 	echo >.git/objects/info/alternates &&
 	test_must_fail git show $csha1
 '
@@ -201,8 +213,8 @@ test_expect_success 'local packed unreachable obs that exist in alternate ODB ar
 	    --unpack-unreachable </dev/null pack &&
 	rm -f .git/objects/pack/* &&
 	mv pack-* .git/objects/pack/ &&
-	test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
-		egrep "^$csha1 " | sort | uniq | wc -l) &&
+	git verify-pack -v -- .git/objects/pack/*.idx >packlist &&
+	! egrep "^$csha1 " &&
 	echo >.git/objects/info/alternates &&
 	test_must_fail git show $csha1
 '
-- 
2.24.0.399.gf8350c9437


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH 21/27] t: define test_grep_return_success()
  2019-11-15  1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu
                   ` (19 preceding siblings ...)
  2019-11-15  1:01 ` [PATCH 20/27] t7700: stop losing return codes of git commands Denton Liu
@ 2019-11-15  1:01 ` Denton Liu
  2019-11-15  5:26   ` Junio C Hamano
  2019-11-15  1:01 ` [PATCH 22/27] t0090: mask failing grep status Denton Liu
                   ` (7 subsequent siblings)
  28 siblings, 1 reply; 169+ messages in thread
From: Denton Liu @ 2019-11-15  1:01 UTC (permalink / raw)
  To: Git Mailing List

In a future patch, we plan on running tests with `set -o pipefail`.
However, since grep can return failure in the case that no lines are
matched, this can trigger a failure in a pipe in the case where grep is
being used as a filter.

Define the test_grep_return_success() function which acts as a wrapper
around grep but always returns 0 so that it can be used in the situation
described above.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/test-lib-functions.sh | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index b299ecc326..dddc4cc3b1 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -990,6 +990,11 @@ test_i18ngrep () {
 	return 1
 }
 
+# Calls grep but returns zero even if no matching lines are found.
+test_grep_return_success () {
+	grep "$@" || :
+}
+
 # Call any command "$@" but be more verbose about its
 # failure. This is handy for commands like "test" which do
 # not output anything when they fail.
-- 
2.24.0.399.gf8350c9437


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH 22/27] t0090: mask failing grep status
  2019-11-15  1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu
                   ` (20 preceding siblings ...)
  2019-11-15  1:01 ` [PATCH 21/27] t: define test_grep_return_success() Denton Liu
@ 2019-11-15  1:01 ` Denton Liu
  2019-11-15  1:01 ` [PATCH 23/27] t3600: mark git command as failing Denton Liu
                   ` (6 subsequent siblings)
  28 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-15  1:01 UTC (permalink / raw)
  To: Git Mailing List

In a future patch, we plan on running tests with `set -o pipefail`.
However, since grep can return failure in the case that no lines are
matched, this can trigger a failure in a pipe in the case where grep is
being used as a filter.

Use test_grep_return_success() instead of grep so that we don't fail
even if we have no matching lines.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t0090-cache-tree.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh
index 5a633690bf..b0f3b69d1d 100755
--- a/t/t0090-cache-tree.sh
+++ b/t/t0090-cache-tree.sh
@@ -22,7 +22,7 @@ generate_expected_cache_tree_rec () {
 	# ls-files might have foo/bar, foo/bar/baz, and foo/bar/quux
 	# We want to count only foo because it's the only direct child
 	git ls-files >files &&
-	subtrees=$(grep / files|cut -d / -f 1|uniq) &&
+	subtrees=$(test_grep_return_success / files|cut -d / -f 1|uniq) &&
 	subtree_count=$(echo "$subtrees"|awk -v c=0 '$1 != "" {++c} END {print c}') &&
 	entries=$(wc -l <files) &&
 	printf "SHA $dir (%d entries, %d subtrees)\n" "$entries" "$subtree_count" &&
-- 
2.24.0.399.gf8350c9437


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH 23/27] t3600: mark git command as failing
  2019-11-15  1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu
                   ` (21 preceding siblings ...)
  2019-11-15  1:01 ` [PATCH 22/27] t0090: mask failing grep status Denton Liu
@ 2019-11-15  1:01 ` Denton Liu
  2019-11-15  5:35   ` Junio C Hamano
  2019-11-15  1:01 ` [PATCH 24/27] t5004: ignore SIGPIPE in zipinfo Denton Liu
                   ` (5 subsequent siblings)
  28 siblings, 1 reply; 169+ messages in thread
From: Denton Liu @ 2019-11-15  1:01 UTC (permalink / raw)
  To: Git Mailing List

In a future patch, we plan on running tests with `set -o pipefail`.
Since we intentionally induce SIGPIPE, before the return code
was being masked away. However, now `git rm` will cause an error code to
be returned because of the SIGPIPE.

Mark the failing command with `test_must_fail ok=sigpipe` so that
failures induced by SIGPIPE don't propogate.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t3600-rm.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh
index 0ea858d652..d1b3703edb 100755
--- a/t/t3600-rm.sh
+++ b/t/t3600-rm.sh
@@ -252,7 +252,7 @@ test_expect_success 'choking "git rm" should not let it die with cruft' '
 		i=$(( $i + 1 ))
 	done | git update-index --index-info &&
 	# git command is intentionally placed upstream of pipe to induce SIGPIPE
-	git rm -n "some-file-*" | : &&
+	test_must_fail ok=sigpipe git rm -n "some-file-*" | : &&
 	test_path_is_missing .git/index.lock
 '
 
-- 
2.24.0.399.gf8350c9437


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH 24/27] t5004: ignore SIGPIPE in zipinfo
  2019-11-15  1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu
                   ` (22 preceding siblings ...)
  2019-11-15  1:01 ` [PATCH 23/27] t3600: mark git command as failing Denton Liu
@ 2019-11-15  1:01 ` Denton Liu
  2019-11-15  5:36   ` Junio C Hamano
  2019-11-15  1:01 ` [PATCH 25/27] t5703: mask failing grep status Denton Liu
                   ` (4 subsequent siblings)
  28 siblings, 1 reply; 169+ messages in thread
From: Denton Liu @ 2019-11-15  1:01 UTC (permalink / raw)
  To: Git Mailing List

In a future patch, we plan on running tests with `set -o pipefail`.
Since zipinfo is killed by SIGPIPE, it will return an error code which
will propogate as a result of the pipefail.

Mask away the return code of zipinfo so that the failure as a result of
the SIGPIPE does not propogate.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5004-archive-corner-cases.sh | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/t/t5004-archive-corner-cases.sh b/t/t5004-archive-corner-cases.sh
index 3e7b23cb32..4c6d42d474 100755
--- a/t/t5004-archive-corner-cases.sh
+++ b/t/t5004-archive-corner-cases.sh
@@ -153,7 +153,9 @@ test_expect_success ZIPINFO 'zip archive with many entries' '
 
 	# check the number of entries in the ZIP file directory
 	expr 65536 + 256 >expect &&
-	"$ZIPINFO" many.zip | head -2 | sed -n "2s/.* //p" >actual &&
+	{
+		"$ZIPINFO" many.zip || :
+	} | head -2 | sed -n "2s/.* //p" >actual &&
 	test_cmp expect actual
 '
 
-- 
2.24.0.399.gf8350c9437


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH 25/27] t5703: mask failing grep status
  2019-11-15  1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu
                   ` (23 preceding siblings ...)
  2019-11-15  1:01 ` [PATCH 24/27] t5004: ignore SIGPIPE in zipinfo Denton Liu
@ 2019-11-15  1:01 ` Denton Liu
  2019-11-15  1:01 ` [PATCH 26/27] t9902: disable pipefail Denton Liu
                   ` (3 subsequent siblings)
  28 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-15  1:01 UTC (permalink / raw)
  To: Git Mailing List

In a future patch, we plan on running tests with `set -o pipefail`.
However, since grep can return failure in the case that no lines are
matched, this can trigger a failure in a pipe in the case where grep is
being used as a filter.

Use test_grep_return_success() instead of grep so that we don't fail
even if we have no matching lines.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5703-upload-pack-ref-in-want.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/t/t5703-upload-pack-ref-in-want.sh b/t/t5703-upload-pack-ref-in-want.sh
index 9f6d837720..c4f9698398 100755
--- a/t/t5703-upload-pack-ref-in-want.sh
+++ b/t/t5703-upload-pack-ref-in-want.sh
@@ -19,7 +19,7 @@ get_actual_commits () {
 		}' <out | test-tool pkt-line unpack-sideband >o.pack &&
 	git index-pack o.pack &&
 	git verify-pack -v o.idx >objs &&
-	grep commit objs | cut -c-40 | sort >actual_commits
+	test_grep_return_success commit objs | cut -c-40 | sort >actual_commits
 }
 
 check_output () {
-- 
2.24.0.399.gf8350c9437


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH 26/27] t9902: disable pipefail
  2019-11-15  1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu
                   ` (24 preceding siblings ...)
  2019-11-15  1:01 ` [PATCH 25/27] t5703: mask failing grep status Denton Liu
@ 2019-11-15  1:01 ` Denton Liu
  2019-11-15  1:01 ` [PATCH 27/27] t: run tests with `set -o pipefail` on Bash Denton Liu
                   ` (2 subsequent siblings)
  28 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-15  1:01 UTC (permalink / raw)
  To: Git Mailing List

In a future patch, we plan on running tests with `set -o pipefail`.
However, these tests cannot run with pipefail. Since git-completion.bash
is not a testing script, it does not follow the same return code
conventions and it's expected that commands can fail within a pipeline.

Run `set +o pipefail` to disable pipefail in this script.

Note that this is being unconditionally run because this test will be
skipped if its not running on Bash.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t9902-completion.sh | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index e90ac565e1..75a512669e 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -7,6 +7,12 @@ test_description='test bash completion'
 
 . ./lib-bash.sh
 
+# These tests cannot run with pipefail. Since git-completion.bash is not
+# a testing script, it does not follow the same return code conventions
+# and it's expected that commands can fail within a pipeline. Ignore
+# these failures.
+set +o pipefail
+
 complete ()
 {
 	# do nothing
-- 
2.24.0.399.gf8350c9437


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH 27/27] t: run tests with `set -o pipefail` on Bash
  2019-11-15  1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu
                   ` (25 preceding siblings ...)
  2019-11-15  1:01 ` [PATCH 26/27] t9902: disable pipefail Denton Liu
@ 2019-11-15  1:01 ` Denton Liu
  2019-11-15  4:09 ` [PATCH 00/27] t: general test cleanup + `set -o pipefail` Jeff King
  2019-11-21  0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
  28 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-15  1:01 UTC (permalink / raw)
  To: Git Mailing List

The current convention is to ensure that git commands are not placed in
the upstream of a pipe. If they are, they could fail in an undetectable
manner since a pipe's return code is the last command in the pipe.
However, many old tests are still written with git commands in the
upstream of a pipe.

In the spirit of catching these failures, run tests with
`set -o pipefail` if the underlying shell is Bash. This way, we can
catch failures of Git commands that may occur even in the middle of a
pipeline.

In the future, more shells that support `set -o pipefail` may have it
enabled but let's start small for now.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/README      |  4 ++++
 t/test-lib.sh | 12 ++++++++++++
 2 files changed, 16 insertions(+)

diff --git a/t/README b/t/README
index 60d5b77bcc..ba96b6d113 100644
--- a/t/README
+++ b/t/README
@@ -415,6 +415,10 @@ GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=<boolean>, when true (which is
 the default when running tests), errors out when an abbreviated option
 is used.
 
+GIT_TEST_PIPEFAIL=<boolean>, when true, run 'set -o pipefail' to catch
+failures in commands that aren't the last in a pipe. Defaults to true on
+Bash and false otherwise.
+
 Naming Tests
 ------------
 
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 46c4440843..c0c43dfce9 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -64,6 +64,18 @@ then
 	export GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS
 fi
 
+# Use set -o pipefail on platforms that support it
+GIT_TEST_PIPEFAIL_DEFAULT=false
+# TODO: detect more platforms that support `set -o pipefail`
+if test -n "$BASH_VERSION"
+then
+	GIT_TEST_PIPEFAIL_DEFAULT=true
+fi
+if git env--helper --type=bool --default="$GIT_TEST_PIPEFAIL_DEFAULT" --exit-code GIT_TEST_PIPEFAIL
+then
+	set -o pipefail
+fi
+
 ################################################################
 # It appears that people try to run tests without building...
 "${GIT_TEST_INSTALLED:-$GIT_BUILD_DIR}/git$X" >/dev/null
-- 
2.24.0.399.gf8350c9437


^ permalink raw reply	[flat|nested] 169+ messages in thread

* Re: [PATCH 00/27] t: general test cleanup + `set -o pipefail`
  2019-11-15  1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu
                   ` (26 preceding siblings ...)
  2019-11-15  1:01 ` [PATCH 27/27] t: run tests with `set -o pipefail` on Bash Denton Liu
@ 2019-11-15  4:09 ` Jeff King
  2019-11-21  0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
  28 siblings, 0 replies; 169+ messages in thread
From: Jeff King @ 2019-11-15  4:09 UTC (permalink / raw)
  To: Denton Liu; +Cc: Git Mailing List

On Thu, Nov 14, 2019 at 05:00:29PM -0800, Denton Liu wrote:

> Patches 1-20 perform some general test cleanup to modernise the style.
> They should be relatively uncontroversial and can be merged earlier (or
> as a separate series) if desired. The reason these tests were identified
> for cleanup was because they failed under `set -o pipefail`.
> 
> Patches 21-27 should be considered RFC. In an attempt to catch git
> commands failing in the upstream of a pipe, we enable `set -o pipefail`
> on Bash. This may result in some funny-looking shell script constructs
> (e.g. needing to wrap `grep` since it may "fail") but overall, I think it
> is an improvement since we catch failure in more cases.

Using pipefail can have unexpected consequences for other commands if
they rely on SIGPIPE/EPIPE to signal the left-hand side of the pipe.
E.g., this:

  $ set -o pipefail
  $ yes | head >/dev/null
  $ echo $?

will consistently yield 141, since "yes" will always die to SIGPIPE
after "head" stops reading from it.

But much worse, this can be racy. Take something like this (which is a
real snippet in our test suite):

  git status -s -b | head -1

The "head" process will quit after reading one line. What's the exit
code of "git status"? It's either "0", if it managed to write everything
into the pipe buffer before the simultaneously-running "head" closed the
pipe. Or it's 141, if it didn't and got SIGPIPE.

You could argue that "git status" should not be on the left-hand side of
a pipe, but the same holds for any command on the left-hand side. E.g.,
grepping in our test scripts yields some bits like:

  t/t7003-filter-branch.sh:       echo "$faux_gpg_tag" | sed -e s/XXXXXX/$sha1/ | head -n 6 > expect &&
  t/t9400-git-cvsserver-server.sh:   test "$(echo $(grep -v ^D cvswork/CVS/Entries|cut -d/ -f2,3,5 | head -n 1))" = "empty/1.1/" &&

And it's not just "head" that doesn't read all of its input. Another
common one is "grep -q", which can quit as soon as it sees a match.

So I have a feeling that pipefail is going to create more headaches than
it solves.

-Peff

^ permalink raw reply	[flat|nested] 169+ messages in thread

* Re: [PATCH 21/27] t: define test_grep_return_success()
  2019-11-15  1:01 ` [PATCH 21/27] t: define test_grep_return_success() Denton Liu
@ 2019-11-15  5:26   ` Junio C Hamano
  0 siblings, 0 replies; 169+ messages in thread
From: Junio C Hamano @ 2019-11-15  5:26 UTC (permalink / raw)
  To: Denton Liu; +Cc: Git Mailing List

Denton Liu <liu.denton@gmail.com> writes:

> +# Calls grep but returns zero even if no matching lines are found.
> +test_grep_return_success () {
> +	grep "$@" || :
> +}

It makes sense to have a helper like this, but the name is quite a
mouthful.  I wonder if we can call it with a shorter name, e.g.
"test_filter" or something.


^ permalink raw reply	[flat|nested] 169+ messages in thread

* Re: [PATCH 23/27] t3600: mark git command as failing
  2019-11-15  1:01 ` [PATCH 23/27] t3600: mark git command as failing Denton Liu
@ 2019-11-15  5:35   ` Junio C Hamano
  0 siblings, 0 replies; 169+ messages in thread
From: Junio C Hamano @ 2019-11-15  5:35 UTC (permalink / raw)
  To: Denton Liu; +Cc: Git Mailing List

Denton Liu <liu.denton@gmail.com> writes:

> In a future patch, we plan on running tests with `set -o pipefail`.
> Since we intentionally induce SIGPIPE, before the return code
> was being masked away. However, now `git rm` will cause an error code to
> be returned because of the SIGPIPE.
>
> Mark the failing command with `test_must_fail ok=sigpipe` so that
> failures induced by SIGPIPE don't propogate.

Hmph, would this pipeline _always_ fail?  I somehow thought that a
process that writes into a pipe that is not being read would fail
only if the downstream dies and closes before it write(2)s, and if
the output from this "git rm -n" is small enough (say to fit within
the pipe buffer) and downstream no-op is slow enough to die, the
upstream may probably not notice and happily and successfully exit.

    : with slow downstream
    $ ( ( printf "%s\n" a b c d e); echo "my exit $?" 1>&2 ) |
      ( sleep 2; echo "downstream exit $?" ); echo "overall exit $?"
    my exit 0
    downstream exit 0
    overall exit 0

    : with slow upstream
    $ ( (sleep 2; printf "%s\n" a b c d e); echo "my exit $?" 1>&2 ) |
      ( echo "downstream exit $?" ); echo "overall exit $?"
    downstream exit 0
    my exit 141
    overall exit 0

So, no, I do not think this is a good idea.  It would be racy.


> Signed-off-by: Denton Liu <liu.denton@gmail.com>
> ---
>  t/t3600-rm.sh | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh
> index 0ea858d652..d1b3703edb 100755
> --- a/t/t3600-rm.sh
> +++ b/t/t3600-rm.sh
> @@ -252,7 +252,7 @@ test_expect_success 'choking "git rm" should not let it die with cruft' '
>  		i=$(( $i + 1 ))
>  	done | git update-index --index-info &&
>  	# git command is intentionally placed upstream of pipe to induce SIGPIPE
> -	git rm -n "some-file-*" | : &&
> +	test_must_fail ok=sigpipe git rm -n "some-file-*" | : &&
>  	test_path_is_missing .git/index.lock
>  '

^ permalink raw reply	[flat|nested] 169+ messages in thread

* Re: [PATCH 24/27] t5004: ignore SIGPIPE in zipinfo
  2019-11-15  1:01 ` [PATCH 24/27] t5004: ignore SIGPIPE in zipinfo Denton Liu
@ 2019-11-15  5:36   ` Junio C Hamano
  0 siblings, 0 replies; 169+ messages in thread
From: Junio C Hamano @ 2019-11-15  5:36 UTC (permalink / raw)
  To: Denton Liu; +Cc: Git Mailing List

Denton Liu <liu.denton@gmail.com> writes:

> In a future patch, we plan on running tests with `set -o pipefail`.
> Since zipinfo is killed by SIGPIPE, it will return an error code which

s/is killed/may be killed/ for the reasons I wrote for 23/27, I think.

Otherwise the idea behind the patch is good.

Thanks.

> will propogate as a result of the pipefail.
>
> Mask away the return code of zipinfo so that the failure as a result of
> the SIGPIPE does not propogate.
>
> Signed-off-by: Denton Liu <liu.denton@gmail.com>
> ---
>  t/t5004-archive-corner-cases.sh | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/t/t5004-archive-corner-cases.sh b/t/t5004-archive-corner-cases.sh
> index 3e7b23cb32..4c6d42d474 100755
> --- a/t/t5004-archive-corner-cases.sh
> +++ b/t/t5004-archive-corner-cases.sh
> @@ -153,7 +153,9 @@ test_expect_success ZIPINFO 'zip archive with many entries' '
>  
>  	# check the number of entries in the ZIP file directory
>  	expr 65536 + 256 >expect &&
> -	"$ZIPINFO" many.zip | head -2 | sed -n "2s/.* //p" >actual &&
> +	{
> +		"$ZIPINFO" many.zip || :
> +	} | head -2 | sed -n "2s/.* //p" >actual &&
>  	test_cmp expect actual
>  '

^ permalink raw reply	[flat|nested] 169+ messages in thread

* Re: [PATCH 01/27] lib-bash.sh: move `then` onto its own line
  2019-11-15  1:00 ` [PATCH 01/27] lib-bash.sh: move `then` onto its own line Denton Liu
@ 2019-11-15 18:22   ` Eric Sunshine
  2019-11-16  2:50     ` Junio C Hamano
  0 siblings, 1 reply; 169+ messages in thread
From: Eric Sunshine @ 2019-11-15 18:22 UTC (permalink / raw)
  To: Denton Liu; +Cc: Git Mailing List

On Thu, Nov 14, 2019 at 8:00 PM Denton Liu <liu.denton@gmail.com> wrote:
> The code style for tests is to have statements on their own line if
> possible. Move the `then` onto its own line so that it conforms with the
> test style.
>
> Signed-off-by: Denton Liu <liu.denton@gmail.com>
> ---
> diff --git a/t/lib-bash.sh b/t/lib-bash.sh
> @@ -2,7 +2,8 @@
> -if test -n "$BASH" && test -z "$POSIXLY_CORRECT"; then
> +if test -n "$BASH" && test -z "$POSIXLY_CORRECT"
> +then

Okay...

>         # we are in full-on bash mode
>         true
>  elif type bash >/dev/null 2>&1; then

... but why not move this 'then' to its own line, as well?

^ permalink raw reply	[flat|nested] 169+ messages in thread

* Re: [PATCH 01/27] lib-bash.sh: move `then` onto its own line
  2019-11-15 18:22   ` Eric Sunshine
@ 2019-11-16  2:50     ` Junio C Hamano
  0 siblings, 0 replies; 169+ messages in thread
From: Junio C Hamano @ 2019-11-16  2:50 UTC (permalink / raw)
  To: Eric Sunshine; +Cc: Denton Liu, Git Mailing List

Eric Sunshine <sunshine@sunshineco.com> writes:

> On Thu, Nov 14, 2019 at 8:00 PM Denton Liu <liu.denton@gmail.com> wrote:
>> The code style for tests is to have statements on their own line if
>> possible. Move the `then` onto its own line so that it conforms with the
>> test style.
>>
>> Signed-off-by: Denton Liu <liu.denton@gmail.com>
>> ---
>> diff --git a/t/lib-bash.sh b/t/lib-bash.sh
>> @@ -2,7 +2,8 @@
>> -if test -n "$BASH" && test -z "$POSIXLY_CORRECT"; then
>> +if test -n "$BASH" && test -z "$POSIXLY_CORRECT"
>> +then
>
> Okay...
>
>>         # we are in full-on bash mode
>>         true
>>  elif type bash >/dev/null 2>&1; then
>
> ... but why not move this 'then' to its own line, as well?

Good eyes ;-)

^ permalink raw reply	[flat|nested] 169+ messages in thread

* Re: [PATCH 10/27] t4138: stop losing return codes of git commands
  2019-11-15  1:00 ` [PATCH 10/27] t4138: stop losing return codes of git commands Denton Liu
@ 2019-11-16  9:00   ` Eric Sunshine
  0 siblings, 0 replies; 169+ messages in thread
From: Eric Sunshine @ 2019-11-16  9:00 UTC (permalink / raw)
  To: Denton Liu; +Cc: Git Mailing List

On Thu, Nov 14, 2019 at 8:01 PM Denton Liu <liu.denton@gmail.com> wrote:
> In a pipe, only the return code of the last command is used. Thus, all
> other commands will have their return codes masked. Rewrite pipes so
> that there are no git commands upstream so that we will know if a
> command fails.
>
> Signed-off-by: Denton Liu <liu.denton@gmail.com>
> ---
> diff --git a/t/t4138-apply-ws-expansion.sh b/t/t4138-apply-ws-expansion.sh
> @@ -17,8 +17,8 @@ test_expect_success setup '
> -       git diff --no-index before after |
> -               sed -e "s/before/test-1/" -e "s/after/test-1/" >patch1.patch &&
> +       test_must_fail git diff --no-index before after >patch1.patch.raw &&
> +       sed -e "s/before/test-1/" -e "s/after/test-1/" patch1.patch.raw >patch1.patch &&

I think this is a semantically incorrect use of test_must_fail(). What
you're interested here is that git-diff found differences (as opposed
to not finding any), so you want to test its exit code which reflects
whether or not the files were different. Hence, the following would be
more appropriate:

    test_expect_code 1 git diff --no-index before after >patch1.patch.raw &&

Same comment applies to remaining changes in this patch.

^ permalink raw reply	[flat|nested] 169+ messages in thread

* Re: [PATCH 12/27] t5317: use ! grep to check for no matching lines
  2019-11-15  1:00 ` [PATCH 12/27] t5317: use ! grep to check for no matching lines Denton Liu
@ 2019-11-16  9:27   ` Eric Sunshine
  0 siblings, 0 replies; 169+ messages in thread
From: Eric Sunshine @ 2019-11-16  9:27 UTC (permalink / raw)
  To: Denton Liu; +Cc: Git Mailing List

On Thu, Nov 14, 2019 at 8:01 PM Denton Liu <liu.denton@gmail.com> wrote:
> Several times in t5317, we would use `wc -l` to ensure that a grep
> result is empty. However, grep already has a way to do that... Its
> return code! Use ! grep in the cases where we are ensuring that there
> are no matching lines.
>
> Signed-off-by: Denton Liu <liu.denton@gmail.com>
> ---
> diff --git a/t/t5317-pack-objects-filter-objects.sh b/t/t5317-pack-objects-filter-objects.sh
> @@ -45,12 +45,7 @@ test_expect_success 'verify blob:none packfile has no blobs' '
>         git -C r1 verify-pack -v ../filter.pack >verify_result &&
> -       grep blob verify_result |
> -       awk -f print_1.awk |
> -       sort >observed &&
> -
> -       nr=$(wc -l <observed) &&
> -       test 0 -eq $nr
> +       ! grep blob verify_result

It's curious that this and other tests were doing so much unnecessary
extra work ('awk' and 'sort'). While it's clear that it's safe to drop
the 'awk' and 'sed' invocations, nevertheless, as a reviewer, I had to
spend extra time digging into it in order to understand why it was
like this in the first place, since I wanted to convince myself that
some earlier change hadn't broken the test in some unnoticed way.

It turns out that these tests were simply born this way[1], doing all
this unnecessary work for no reason, probably due to copy/paste
programming, and it seems no reviewer caught it. Likewise, the
unnecessary work wasn't noticed even when the code was later touched
for various cleanups[2,3].

To save future reviewers (and future readers of the commit history)
the effort of having to convince themselves of the safety of this
change, it might be a good idea to say something in the commit message
about the code's history.

[1]: 9535ce7337 (pack-objects: add list-objects filtering, 2017-11-21)
[2]: bdbc17e86a (tests: standardize pipe placement, 2018-10-05)
[3]: 61de0ff695 (tests: don't swallow Git errors upstream of pipes, 2018-10-05)

^ permalink raw reply	[flat|nested] 169+ messages in thread

* Re: [PATCH 13/27] t5703: stop losing return codes of git commands
  2019-11-15  1:01 ` [PATCH 13/27] t5703: stop losing return codes of git commands Denton Liu
@ 2019-11-16 10:11   ` Eric Sunshine
  0 siblings, 0 replies; 169+ messages in thread
From: Eric Sunshine @ 2019-11-16 10:11 UTC (permalink / raw)
  To: Denton Liu; +Cc: Git Mailing List

On Thu, Nov 14, 2019 at 8:01 PM Denton Liu <liu.denton@gmail.com> wrote:
> Signed-off-by: Denton Liu <liu.denton@gmail.com>
> ---
> diff --git a/t/t5703-upload-pack-ref-in-want.sh b/t/t5703-upload-pack-ref-in-want.sh
> @@ -312,9 +324,11 @@ inconsistency () {
> +       oid1=$(git -C "$REPO" rev-parse $1) &&
> +       oid2=$(git -C "$REPO" rev-parse $2) &&
>         printf "s/%s/%s/" \
> -              $(git -C "$REPO" rev-parse $1 | tr -d "\n") \
> -              $(git -C "$REPO" rev-parse $2 | tr -d "\n") \
> +              $(echo "$oid1" | tr -d "\n") \
> +              $(echo "$oid2" | tr -d "\n") \
>                >"$HTTPD_ROOT_PATH/one-time-sed"

This code is rather odd. The $(...) substitution already takes care of
stripping out newlines, so the 'tr' invocations in both the original
and the revised code are superfluous. As this patch series
incorporates various other cleanups, it would not be inappropriate to
create a patch which removes the unnecessary 'tr' invocations
preparatory to this patch. The final result should be a simple:

    printf "s/%s/%s/" $oid1 $oid2 >"$HTTPD_ROOT_PATH/one-time-sed"

or even simpler:

    printf "s/$oid1/$oid2/" >"$HTTPD_ROOT_PATH/one-time-sed"

In fact, given the way the tests actually employ "one-time-sed" via
$(cat one-time-sed) in t/lib-httpd/apply-one-time-sed.sh, it could
even be as simple as:

    echo "s/$oid1/$oid2/" >"$HTTPD_ROOT_PATH/one-time-sed"

which makes it consistent with the final "server loses a ref - ref in
want" test, which does use 'echo' rather than 'printf'. (That change
might also deserve its own patch.)

^ permalink raw reply	[flat|nested] 169+ messages in thread

* Re: [PATCH 15/27] t7501: stop losing return codes of git commands
  2019-11-15  1:01 ` [PATCH 15/27] t7501: stop losing return codes of git commands Denton Liu
@ 2019-11-16 10:35   ` Eric Sunshine
  0 siblings, 0 replies; 169+ messages in thread
From: Eric Sunshine @ 2019-11-16 10:35 UTC (permalink / raw)
  To: Denton Liu; +Cc: Git Mailing List

On Thu, Nov 14, 2019 at 8:01 PM Denton Liu <liu.denton@gmail.com> wrote:
> In a pipe, only the return code of the last command is used. Thus, all
> other commands will have their return codes masked. Rewrite pipes so
> that there are no git commands upstream so that we will know if a
> command fails.
>
> Signed-off-by: Denton Liu <liu.denton@gmail.com>
> ---
> diff --git a/t/t7501-commit-basic-functionality.sh b/t/t7501-commit-basic-functionality.sh
> @@ -285,9 +285,8 @@ test_expect_success 'overriding author from command line' '
>  test_expect_success PERL 'interactive add' '
> -       echo 7 |
> -       git commit --interactive |
> -       grep "What now"
> +       echo 7 | test_must_fail git commit --interactive >out &&
> +       grep "What now" out
>  '

git-commit documentation does not talk about the command's exit code,
so it's not immediately clear why this test should be using
test_must_fail() for the invocation. The implementation of git-commit
is more illuminating, showing that 1 is returned when there are no
changes to commit, and 0 for a successful commit. So, that raises the
question of whether this should be using "test_expect_code 1" rather
than test_must_fail(), however, there is existing precedence which
gives some guidance. In particular, the "nothing to commit" test of
t7501-commit-basic-functionality.sh does use test_must_fail() when
attempting to commit with no changes. It may make sense, therefore, to
mention something about this in the commit message to save future
readers from wondering why the command is "expected to fail".

^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail
  2019-11-15  1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu
                   ` (27 preceding siblings ...)
  2019-11-15  4:09 ` [PATCH 00/27] t: general test cleanup + `set -o pipefail` Jeff King
@ 2019-11-21  0:45 ` Denton Liu
  2019-11-21  0:45   ` [PATCH v2 01/21] lib-bash.sh: move `then` onto its own line Denton Liu
                     ` (21 more replies)
  28 siblings, 22 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-21  0:45 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

These patches perform some general test cleanup to modernise the style.
They should be relatively uncontroversial. The reason these tests were
identified for cleanup was because they failed under `set -o pipefail`.

I've gotten rid of the RFC part that actually enables `set -o pipefail`
on supported platforms. As Peff pointed out, there are a lot of
opportunities for racy SIGPIPE failures so that part still needs a lot
of work to be ironed out.

Those changes shouldn't hold back the first part of the series, however.
Let's try to get this test cleanup merged in sooner than later so that
any new test cases done by copy-paste will have their changes
represented.

Changes since v1:

* Removed the `set -o pipefail` changes

* Addressed Junio and Eric's comments on the first part of the series

Denton Liu (21):
  lib-bash.sh: move `then` onto its own line
  t0014: remove git command upstream of pipe
  t0090: stop losing return codes of git commands
  t3301: stop losing return codes of git commands
  t3600: use test_line_count() where possible
  t3600: stop losing return codes of git commands
  t3600: comment on inducing SIGPIPE in `git rm`
  t4015: stop losing return codes of git commands
  t4015: use test_write_lines()
  t4138: stop losing return codes of git commands
  t5317: stop losing return codes of git commands
  t5317: use ! grep to check for no matching lines
  t5703: simplify one-time-sed generation logic
  t5703: stop losing return codes of git commands
  t7501: remove spaces after redirect operators
  t7501: stop losing return codes of git commands
  t7700: drop redirections to /dev/null
  t7700: remove spaces after redirect operators
  t7700: move keywords onto their own line
  t7700: s/test -f/test_path_is_file/
  t7700: stop losing return codes of git commands

 t/lib-bash.sh                          |   6 +-
 t/t0014-alias.sh                       |   4 +-
 t/t0090-cache-tree.sh                  |   5 +-
 t/t3301-notes.sh                       | 230 ++++++++++++++++++-------
 t/t3600-rm.sh                          |  14 +-
 t/t4015-diff-whitespace.sh             | 123 +++++++------
 t/t4138-apply-ws-expansion.sh          |  16 +-
 t/t5317-pack-objects-filter-objects.sh |  34 ++--
 t/t5703-upload-pack-ref-in-want.sh     |  53 +++---
 t/t7501-commit-basic-functionality.sh  |  83 +++++----
 t/t7700-repack.sh                      | 125 ++++++++------
 11 files changed, 428 insertions(+), 265 deletions(-)

Range-diff against v1:
 1:  a1a1199254 !  1:  da6ff63918 lib-bash.sh: move `then` onto its own line
    @@ t/lib-bash.sh
     +then
      	# we are in full-on bash mode
      	true
    - elif type bash >/dev/null 2>&1; then
    +-elif type bash >/dev/null 2>&1; then
    ++elif type bash >/dev/null 2>&1
    ++then
    + 	# execute in full-on bash mode
    + 	unset POSIXLY_CORRECT
    + 	exec bash "$0" "$@"
 2:  735d3fce93 =  2:  c0a513145d t0014: remove git command upstream of pipe
 3:  c29a54880a =  3:  52d8933ac9 t0090: stop losing return codes of git commands
 4:  5d634f8e5d =  4:  e8eafa1551 t3301: stop losing return codes of git commands
 5:  49069d12c0 =  5:  97ad3604dd t3600: use test_line_count() where possible
 6:  e4c43b686a =  6:  e0152ff3c1 t3600: stop losing return codes of git commands
 7:  91001a5be3 =  7:  54e9e78e03 t3600: comment on inducing SIGPIPE in `git rm`
 8:  738e0f1c27 =  8:  7c9e9a4b81 t4015: stop losing return codes of git commands
 9:  63b0028057 =  9:  9fb33ea04e t4015: use test_write_lines()
10:  8f9945bb16 ! 10:  6c91594492 t4138: stop losing return codes of git commands
    @@ t/t4138-apply-ws-expansion.sh: test_expect_success setup '
      	printf "\t%s\n" 4 5 6 >>after &&
     -	git diff --no-index before after |
     -		sed -e "s/before/test-1/" -e "s/after/test-1/" >patch1.patch &&
    -+	test_must_fail git diff --no-index before after >patch1.patch.raw &&
    ++	test_expect_code 1 git diff --no-index before after >patch1.patch.raw &&
     +	sed -e "s/before/test-1/" -e "s/after/test-1/" patch1.patch.raw >patch1.patch &&
      	printf "%64s\n" 1 2 3 4 5 6 >test-1 &&
      	printf "%64s\n" 1 2 3 a b c 4 5 6 >expect-1 &&
    @@ t/t4138-apply-ws-expansion.sh: test_expect_success setup '
      	printf "\t%s\n" d e f >>after &&
     -	git diff --no-index before after |
     -		sed -e "s/before/test-2/" -e "s/after/test-2/" >patch2.patch &&
    -+	test_must_fail git diff --no-index before after >patch2.patch.raw &&
    ++	test_expect_code 1 git diff --no-index before after >patch2.patch.raw &&
     +	sed -e "s/before/test-2/" -e "s/after/test-2/" patch2.patch.raw >patch2.patch &&
      	printf "%64s\n" a b c d e f >test-2 &&
      	printf "%64s\n" a b c >expect-2 &&
    @@ t/t4138-apply-ws-expansion.sh: test_expect_success setup '
      	printf "\t%s\n" d e f >>after &&
     -	git diff --no-index before after |
     -	sed -e "s/before/test-3/" -e "s/after/test-3/" >patch3.patch &&
    -+	test_must_fail git diff --no-index before after >patch3.patch.raw &&
    ++	test_expect_code 1 git diff --no-index before after >patch3.patch.raw &&
     +	sed -e "s/before/test-3/" -e "s/after/test-3/" patch3.patch.raw >patch3.patch &&
      	printf "%64s\n" a b c d e f >test-3 &&
      	printf "%64s\n" a b c >expect-3 &&
    @@ t/t4138-apply-ws-expansion.sh: test_expect_success setup '
      	done &&
     -	git diff --no-index before after |
     -	sed -e "s/before/test-4/" -e "s/after/test-4/" >patch4.patch &&
    -+	test_must_fail git diff --no-index before after >patch4.patch.raw &&
    ++	test_expect_code 1 git diff --no-index before after >patch4.patch.raw &&
     +	sed -e "s/before/test-4/" -e "s/after/test-4/" patch4.patch.raw >patch4.patch &&
      	>test-4 &&
      	x=0 &&
11:  823ed38115 = 11:  04beafae8e t5317: stop losing return codes of git commands
12:  6342f480d5 ! 12:  b24745bd60 t5317: use ! grep to check for no matching lines
    @@ Commit message
     
         Several times in t5317, we would use `wc -l` to ensure that a grep
         result is empty. However, grep already has a way to do that... Its
    -    return code! Use ! grep in the cases where we are ensuring that there
    +    return code! Use `! grep` in the cases where we are ensuring that there
         are no matching lines.
     
    +    It turns out that these tests were simply born this way[1], doing all
    +    this unnecessary work for no reason, probably due to copy/paste
    +    programming, and it seems no reviewer caught it. Likewise, the
    +    unnecessary work wasn't noticed even when the code was later touched
    +    for various cleanups[2,3].
    +
    +    [1]: 9535ce7337 (pack-objects: add list-objects filtering, 2017-11-21)
    +    [2]: bdbc17e86a (tests: standardize pipe placement, 2018-10-05)
    +    [3]: 61de0ff695 (tests: don't swallow Git errors upstream of pipes, 2018-10-05)
    +
    +    Helped-by: Eric Sunshine <sunshine@sunshineco.com>
         Signed-off-by: Denton Liu <liu.denton@gmail.com>
     
    +
    + ## Notes ##
    +    Thanks for your help, Eric. I shamelessly stole your message text for
    +    the commit message.
    +
      ## t/t5317-pack-objects-filter-objects.sh ##
     @@ t/t5317-pack-objects-filter-objects.sh: test_expect_success 'verify blob:none packfile has no blobs' '
      	git -C r1 index-pack ../filter.pack &&
 -:  ---------- > 13:  d5fb60be6b t5703: simplify one-time-sed generation logic
13:  89b68fc876 ! 14:  4071168d8b t5703: stop losing return codes of git commands
    @@ t/t5703-upload-pack-ref-in-want.sh: test_expect_success 'fetching ref and exact
      	grep "want-ref refs/heads/master" log
      '
      
    -@@ t/t5703-upload-pack-ref-in-want.sh: inconsistency () {
    - 	# repository appears to change during negotiation, for example, when
    - 	# different servers in a load-balancing arrangement serve (stateless)
    - 	# RPCs during a single negotiation.
    -+	oid1=$(git -C "$REPO" rev-parse $1) &&
    -+	oid2=$(git -C "$REPO" rev-parse $2) &&
    - 	printf "s/%s/%s/" \
    --	       $(git -C "$REPO" rev-parse $1 | tr -d "\n") \
    --	       $(git -C "$REPO" rev-parse $2 | tr -d "\n") \
    -+	       $(echo "$oid1" | tr -d "\n") \
    -+	       $(echo "$oid2" | tr -d "\n") \
    - 	       >"$HTTPD_ROOT_PATH/one-time-sed"
    - }
    - 
14:  6ab0dafb54 = 15:  63eebe1df6 t7501: remove spaces after redirect operators
15:  952d3fdfe4 ! 16:  4675d3dbc4 t7501: stop losing return codes of git commands
    @@ Commit message
         that there are no git commands upstream so that we will know if a
         command fails.
     
    +    In the 'interactive add' test case, we prepend a `test_must_fail` to
    +    `git commit --interactive`. When there are no changes to commit,
    +    `git commit` will exit with status code 1. Following along with the rest
    +    of the file, we use `test_must_fail` to test for this case.
    +
         Signed-off-by: Denton Liu <liu.denton@gmail.com>
     
      ## t/t7501-commit-basic-functionality.sh ##
16:  e30db4d20e = 17:  3cc6e4455c t7700: drop redirections to /dev/null
17:  664145360d = 18:  43f184dbd5 t7700: remove spaces after redirect operators
18:  6a63a98b1c = 19:  9389a74fe0 t7700: move keywords onto their own line
19:  4749dbcb88 = 20:  079a42c45b t7700: s/test -f/test_path_is_file/
20:  6821af454c = 21:  a455fbb625 t7700: stop losing return codes of git commands
21:  6d0243d9bc <  -:  ---------- t: define test_grep_return_success()
22:  d56a851930 <  -:  ---------- t0090: mask failing grep status
23:  df8fab5f1c <  -:  ---------- t3600: mark git command as failing
24:  ca29fdaddd <  -:  ---------- t5004: ignore SIGPIPE in zipinfo
25:  4d3c28d90e <  -:  ---------- t5703: mask failing grep status
26:  d89c2c24ae <  -:  ---------- t9902: disable pipefail
27:  7036c96fc7 <  -:  ---------- t: run tests with `set -o pipefail` on Bash
-- 
2.24.0.450.g7a9a4598a9


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v2 01/21] lib-bash.sh: move `then` onto its own line
  2019-11-21  0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
@ 2019-11-21  0:45   ` Denton Liu
  2019-11-21  0:45   ` [PATCH v2 02/21] t0014: remove git command upstream of pipe Denton Liu
                     ` (20 subsequent siblings)
  21 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-21  0:45 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

The code style for tests is to have statements on their own line if
possible. Move the `then` onto its own line so that it conforms with the
test style.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/lib-bash.sh | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/t/lib-bash.sh b/t/lib-bash.sh
index 2be955fafb..b0b6060929 100644
--- a/t/lib-bash.sh
+++ b/t/lib-bash.sh
@@ -2,10 +2,12 @@
 # to run under Bash; primarily intended for tests of the completion
 # script.
 
-if test -n "$BASH" && test -z "$POSIXLY_CORRECT"; then
+if test -n "$BASH" && test -z "$POSIXLY_CORRECT"
+then
 	# we are in full-on bash mode
 	true
-elif type bash >/dev/null 2>&1; then
+elif type bash >/dev/null 2>&1
+then
 	# execute in full-on bash mode
 	unset POSIXLY_CORRECT
 	exec bash "$0" "$@"
-- 
2.24.0.450.g7a9a4598a9


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v2 02/21] t0014: remove git command upstream of pipe
  2019-11-21  0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
  2019-11-21  0:45   ` [PATCH v2 01/21] lib-bash.sh: move `then` onto its own line Denton Liu
@ 2019-11-21  0:45   ` Denton Liu
  2019-11-21  0:45   ` [PATCH v2 03/21] t0090: stop losing return codes of git commands Denton Liu
                     ` (19 subsequent siblings)
  21 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-21  0:45 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Before, the `git frotz` command would fail but its return code was
hidden since it was in the upstream of a pipe. Break the pipeline into
two commands so that the return code is no longer lost. Also, mark
`git frotz` with test_must_fail since it's supposed to fail.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t0014-alias.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/t/t0014-alias.sh b/t/t0014-alias.sh
index 2694c81afd..8d3d9144c0 100755
--- a/t/t0014-alias.sh
+++ b/t/t0014-alias.sh
@@ -38,8 +38,8 @@ test_expect_success 'looping aliases - internal execution' '
 #'
 
 test_expect_success 'run-command formats empty args properly' '
-    GIT_TRACE=1 git frotz a "" b " " c 2>&1 |
-    sed -ne "/run_command:/s/.*trace: run_command: //p" >actual &&
+    test_must_fail env GIT_TRACE=1 git frotz a "" b " " c 2>actual.raw &&
+    sed -ne "/run_command:/s/.*trace: run_command: //p" actual.raw >actual &&
     echo "git-frotz a '\'''\'' b '\'' '\'' c" >expect &&
     test_cmp expect actual
 '
-- 
2.24.0.450.g7a9a4598a9


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v2 03/21] t0090: stop losing return codes of git commands
  2019-11-21  0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
  2019-11-21  0:45   ` [PATCH v2 01/21] lib-bash.sh: move `then` onto its own line Denton Liu
  2019-11-21  0:45   ` [PATCH v2 02/21] t0014: remove git command upstream of pipe Denton Liu
@ 2019-11-21  0:45   ` Denton Liu
  2019-11-21  0:45   ` [PATCH v2 04/21] t3301: " Denton Liu
                     ` (18 subsequent siblings)
  21 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-21  0:45 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

In generate_expected_cache_tree_rec(), there are currently two instances
of `git ls-files` in the upstream of a pipe. In the case where the
upstream git command fails, its return code will be lost. Extract the
`git ls-files` into its own call so that if it ever fails, its return
code is not lost.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t0090-cache-tree.sh | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh
index ce9a4a5f32..5a633690bf 100755
--- a/t/t0090-cache-tree.sh
+++ b/t/t0090-cache-tree.sh
@@ -21,9 +21,10 @@ generate_expected_cache_tree_rec () {
 	parent="$2" &&
 	# ls-files might have foo/bar, foo/bar/baz, and foo/bar/quux
 	# We want to count only foo because it's the only direct child
-	subtrees=$(git ls-files|grep /|cut -d / -f 1|uniq) &&
+	git ls-files >files &&
+	subtrees=$(grep / files|cut -d / -f 1|uniq) &&
 	subtree_count=$(echo "$subtrees"|awk -v c=0 '$1 != "" {++c} END {print c}') &&
-	entries=$(git ls-files|wc -l) &&
+	entries=$(wc -l <files) &&
 	printf "SHA $dir (%d entries, %d subtrees)\n" "$entries" "$subtree_count" &&
 	for subtree in $subtrees
 	do
-- 
2.24.0.450.g7a9a4598a9


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v2 04/21] t3301: stop losing return codes of git commands
  2019-11-21  0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                     ` (2 preceding siblings ...)
  2019-11-21  0:45   ` [PATCH v2 03/21] t0090: stop losing return codes of git commands Denton Liu
@ 2019-11-21  0:45   ` " Denton Liu
  2019-11-21  0:45   ` [PATCH v2 05/21] t3600: use test_line_count() where possible Denton Liu
                     ` (17 subsequent siblings)
  21 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-21  0:45 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Currently, there are two ways where the return codes of git commands are
lost. The first way is when a command is in the upstream of a pipe. In a
pipe, only the return code of the last command is used. Thus, all other
commands will have their return codes masked. Rewrite pipes so that
there are no git commands upstream.

The other way is when a command is in a non-assignment command
substitution. The return code will be lost in favour of the surrounding
command's. Rewrite instances of this so that git commands are either run
on their own or in an assignment-only command substitution.

This patch fixes a real buggy test: in 'copy note with "git notes
copy"', `git notes` was mistyped as `git note`.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t3301-notes.sh | 230 +++++++++++++++++++++++++++++++++--------------
 1 file changed, 163 insertions(+), 67 deletions(-)

diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh
index d66a5f6faa..8f43303007 100755
--- a/t/t3301-notes.sh
+++ b/t/t3301-notes.sh
@@ -54,7 +54,9 @@ test_expect_success 'create notes' '
 	test_path_is_missing .git/NOTES_EDITMSG &&
 	git ls-tree -r refs/notes/commits >actual &&
 	test_line_count = 1 actual &&
-	test "b4" = "$(git notes show)" &&
+	echo b4 >expect &&
+	git notes show >actual &&
+	test_cmp expect actual &&
 	git show HEAD^ &&
 	test_must_fail git notes show HEAD^
 '
@@ -79,14 +81,21 @@ test_expect_success 'edit existing notes' '
 	test_path_is_missing .git/NOTES_EDITMSG &&
 	git ls-tree -r refs/notes/commits >actual &&
 	test_line_count = 1 actual &&
-	test "b3" = "$(git notes show)" &&
+	echo b3 >expect &&
+	git notes show >actual &&
+	test_cmp expect actual &&
 	git show HEAD^ &&
 	test_must_fail git notes show HEAD^
 '
 
 test_expect_success 'show notes from treeish' '
-	test "b3" = "$(git notes --ref commits^{tree} show)" &&
-	test "b4" = "$(git notes --ref commits@{1} show)"
+	echo b3 >expect &&
+	git notes --ref commits^{tree} show >actual &&
+	test_cmp expect actual &&
+
+	echo b4 >expect &&
+	git notes --ref commits@{1} show >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'cannot edit notes from non-ref' '
@@ -99,7 +108,9 @@ test_expect_success 'cannot "git notes add -m" where notes already exists' '
 	test_path_is_missing .git/NOTES_EDITMSG &&
 	git ls-tree -r refs/notes/commits >actual &&
 	test_line_count = 1 actual &&
-	test "b3" = "$(git notes show)" &&
+	echo b3 >expect &&
+	git notes show >actual &&
+	test_cmp expect actual &&
 	git show HEAD^ &&
 	test_must_fail git notes show HEAD^
 '
@@ -109,7 +120,9 @@ test_expect_success 'can overwrite existing note with "git notes add -f -m"' '
 	test_path_is_missing .git/NOTES_EDITMSG &&
 	git ls-tree -r refs/notes/commits >actual &&
 	test_line_count = 1 actual &&
-	test "b1" = "$(git notes show)" &&
+	echo b1 >expect &&
+	git notes show >actual &&
+	test_cmp expect actual &&
 	git show HEAD^ &&
 	test_must_fail git notes show HEAD^
 '
@@ -119,7 +132,9 @@ test_expect_success 'add w/no options on existing note morphs into edit' '
 	test_path_is_missing .git/NOTES_EDITMSG &&
 	git ls-tree -r refs/notes/commits >actual &&
 	test_line_count = 1 actual &&
-	test "b2" = "$(git notes show)" &&
+	echo b2 >expect &&
+	git notes show >actual &&
+	test_cmp expect actual &&
 	git show HEAD^ &&
 	test_must_fail git notes show HEAD^
 '
@@ -129,7 +144,9 @@ test_expect_success 'can overwrite existing note with "git notes add -f"' '
 	test_path_is_missing .git/NOTES_EDITMSG &&
 	git ls-tree -r refs/notes/commits >actual &&
 	test_line_count = 1 actual &&
-	test "b1" = "$(git notes show)" &&
+	echo b1 >expect &&
+	git notes show >actual &&
+	test_cmp expect actual &&
 	git show HEAD^ &&
 	test_must_fail git notes show HEAD^
 '
@@ -146,7 +163,8 @@ test_expect_success 'show notes' '
 		Notes:
 		${indent}b1
 	EOF
-	! (git cat-file commit HEAD | grep b1) &&
+	git cat-file commit HEAD >commits &&
+	! grep b1 commits &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -472,9 +490,11 @@ test_expect_success 'removing with --stdin --ignore-missing' '
 test_expect_success 'list notes with "git notes list"' '
 	commit_2=$(git rev-parse 2nd) &&
 	commit_3=$(git rev-parse 3rd) &&
+	note_2=$(git rev-parse refs/notes/commits:$commit_2) &&
+	note_3=$(git rev-parse refs/notes/commits:$commit_3) &&
 	sort -t" " -k2 >expect <<-EOF &&
-		$(git rev-parse refs/notes/commits:$commit_2) $commit_2
-		$(git rev-parse refs/notes/commits:$commit_3) $commit_3
+		$note_2 $commit_2
+		$note_3 $commit_3
 	EOF
 	git notes list >actual &&
 	test_cmp expect actual
@@ -486,9 +506,7 @@ test_expect_success 'list notes with "git notes"' '
 '
 
 test_expect_success 'list specific note with "git notes list <object>"' '
-	cat >expect <<-EOF &&
-		$(git rev-parse refs/notes/commits:$commit_3)
-	EOF
+	git rev-parse refs/notes/commits:$commit_3 >expect &&
 	git notes list HEAD^^ >actual &&
 	test_cmp expect actual
 '
@@ -512,10 +530,11 @@ test_expect_success 'append to existing note with "git notes append"' '
 
 test_expect_success '"git notes list" does not expand to "git notes list HEAD"' '
 	commit_5=$(git rev-parse 5th) &&
+	note_5=$(git rev-parse refs/notes/commits:$commit_5) &&
 	sort -t" " -k2 >expect_list <<-EOF &&
-		$(git rev-parse refs/notes/commits:$commit_2) $commit_2
-		$(git rev-parse refs/notes/commits:$commit_3) $commit_3
-		$(git rev-parse refs/notes/commits:$commit_5) $commit_5
+		$note_2 $commit_2
+		$note_3 $commit_3
+		$note_5 $commit_5
 	EOF
 	git notes list >actual &&
 	test_cmp expect_list actual
@@ -721,7 +740,8 @@ test_expect_success 'Allow notes on non-commits (trees, blobs, tags)' '
 	git notes show HEAD: >actual &&
 	test_cmp expect actual &&
 	echo "Note on a blob" >expect &&
-	filename=$(git ls-tree --name-only HEAD | head -n1) &&
+	git ls-tree --name-only HEAD >files &&
+	filename=$(head -n1 files) &&
 	git notes add -m "Note on a blob" HEAD:$filename &&
 	git notes show HEAD:$filename >actual &&
 	test_cmp expect actual &&
@@ -745,10 +765,13 @@ test_expect_success 'create note from other note with "git notes add -C"' '
 		Notes:
 		${indent}order test
 	EOF
-	git notes add -C $(git notes list HEAD^) &&
+	note=$(git notes list HEAD^) &&
+	git notes add -C $note &&
 	git log -1 >actual &&
 	test_cmp expect actual &&
-	test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
+	git notes list HEAD^ >expect &&
+	git notes list HEAD >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'create note from non-existing note with "git notes add -C" fails' '
@@ -777,11 +800,12 @@ test_expect_success 'create note from blob with "git notes add -C" reuses blob i
 		Notes:
 		${indent}This is a blob object
 	EOF
-	blob=$(echo "This is a blob object" | git hash-object -w --stdin) &&
-	git notes add -C $blob &&
+	echo "This is a blob object" | git hash-object -w --stdin >blob &&
+	git notes add -C $(cat blob) &&
 	git log -1 >actual &&
 	test_cmp expect actual &&
-	test "$(git notes list HEAD)" = "$blob"
+	git notes list HEAD >actual &&
+	test_cmp blob actual
 '
 
 test_expect_success 'create note from other note with "git notes add -c"' '
@@ -797,7 +821,8 @@ test_expect_success 'create note from other note with "git notes add -c"' '
 		Notes:
 		${indent}yet another note
 	EOF
-	MSG="yet another note" git notes add -c $(git notes list HEAD^^) &&
+	note=$(git notes list HEAD^^) &&
+	MSG="yet another note" git notes add -c $note &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -822,7 +847,8 @@ test_expect_success 'append to note from other note with "git notes append -C"'
 		${indent}
 		${indent}yet another note
 	EOF
-	git notes append -C $(git notes list HEAD^) HEAD^ &&
+	note=$(git notes list HEAD^) &&
+	git notes append -C $note HEAD^ &&
 	git log -1 HEAD^ >actual &&
 	test_cmp expect actual
 '
@@ -839,7 +865,8 @@ test_expect_success 'create note from other note with "git notes append -c"' '
 		Notes:
 		${indent}other note
 	EOF
-	MSG="other note" git notes append -c $(git notes list HEAD^) &&
+	note=$(git notes list HEAD^) &&
+	MSG="other note" git notes append -c $note &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -858,7 +885,8 @@ test_expect_success 'append to note from other note with "git notes append -c"'
 		${indent}
 		${indent}yet another note
 	EOF
-	MSG="yet another note" git notes append -c $(git notes list HEAD) &&
+	note=$(git notes list HEAD) &&
+	MSG="yet another note" git notes append -c $note &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -878,7 +906,9 @@ test_expect_success 'copy note with "git notes copy"' '
 	git notes copy 8th 4th &&
 	git log 3rd..4th >actual &&
 	test_cmp expect actual &&
-	test "$(git note list 4th)" = "$(git note list 8th)"
+	git notes list 4th >expect &&
+	git notes list 8th >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'copy note with "git notes copy" with default' '
@@ -899,14 +929,30 @@ test_expect_success 'copy note with "git notes copy" with default' '
 	git notes copy HEAD^ &&
 	git log -1 >actual &&
 	test_cmp expect actual &&
-	test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
+	git notes list HEAD^ >expect &&
+	git notes list HEAD >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'prevent overwrite with "git notes copy"' '
 	test_must_fail git notes copy HEAD~2 HEAD &&
+	cat >expect <<-EOF &&
+		commit $commit
+		Author: A U Thor <author@example.com>
+		Date:   Thu Apr 7 15:23:13 2005 -0700
+
+		${indent}11th
+
+		Notes:
+		${indent}other note
+		${indent}
+		${indent}yet another note
+	EOF
 	git log -1 >actual &&
 	test_cmp expect actual &&
-	test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
+	git notes list HEAD^ >expect &&
+	git notes list HEAD >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'allow overwrite with "git notes copy -f"' '
@@ -924,7 +970,9 @@ test_expect_success 'allow overwrite with "git notes copy -f"' '
 	git notes copy -f HEAD~3 HEAD &&
 	git log -1 >actual &&
 	test_cmp expect actual &&
-	test "$(git notes list HEAD)" = "$(git notes list HEAD~3)"
+	git notes list HEAD~3 >expect &&
+	git notes list HEAD >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'allow overwrite with "git notes copy -f" with default' '
@@ -944,7 +992,9 @@ test_expect_success 'allow overwrite with "git notes copy -f" with default' '
 	git notes copy -f HEAD~2 &&
 	git log -1 >actual &&
 	test_cmp expect actual &&
-	test "$(git notes list HEAD)" = "$(git notes list HEAD~2)"
+	git notes list HEAD~2 >expect &&
+	git notes list HEAD >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'cannot copy note from object without notes' '
@@ -979,13 +1029,21 @@ test_expect_success 'git notes copy --stdin' '
 		${indent}
 		${indent}yet another note
 	EOF
-	(echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^) &&
-	echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
-	git notes copy --stdin &&
+	from=$(git rev-parse HEAD~3) &&
+	to=$(git rev-parse HEAD^) &&
+	echo "$from" "$to" >copy &&
+	from=$(git rev-parse HEAD~2) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >>copy &&
+	git notes copy --stdin <copy &&
 	git log -2 >actual &&
 	test_cmp expect actual &&
-	test "$(git notes list HEAD)" = "$(git notes list HEAD~2)" &&
-	test "$(git notes list HEAD^)" = "$(git notes list HEAD~3)"
+	git notes list HEAD~2 >expect &&
+	git notes list HEAD >actual &&
+	test_cmp expect actual &&
+	git notes list HEAD~3 >expect &&
+	git notes list HEAD^ >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'git notes copy --for-rewrite (unconfigured)' '
@@ -1006,9 +1064,13 @@ test_expect_success 'git notes copy --for-rewrite (unconfigured)' '
 
 		${indent}14th
 	EOF
-	(echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^) &&
-	echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
-	git notes copy --for-rewrite=foo &&
+	from=$(git rev-parse HEAD~3) &&
+	to=$(git rev-parse HEAD^) &&
+	echo "$from" "$to" >copy &&
+	from=$(git rev-parse HEAD~2) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >>copy &&
+	git notes copy --for-rewrite=foo <copy &&
 	git log -2 >actual &&
 	test_cmp expect actual
 '
@@ -1041,17 +1103,23 @@ test_expect_success 'git notes copy --for-rewrite (enabled)' '
 	EOF
 	test_config notes.rewriteMode overwrite &&
 	test_config notes.rewriteRef "refs/notes/*" &&
-	(echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^) &&
-	echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
-	git notes copy --for-rewrite=foo &&
+	from=$(git rev-parse HEAD~3) &&
+	to=$(git rev-parse HEAD^) &&
+	echo "$from" "$to" >copy &&
+	from=$(git rev-parse HEAD~2) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >>copy &&
+	git notes copy --for-rewrite=foo <copy &&
 	git log -2 >actual &&
 	test_cmp expect actual
 '
 
 test_expect_success 'git notes copy --for-rewrite (disabled)' '
 	test_config notes.rewrite.bar false &&
-	echo $(git rev-parse HEAD~3) $(git rev-parse HEAD) |
-	git notes copy --for-rewrite=bar &&
+	from=$(git rev-parse HEAD~3) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
+	git notes copy --for-rewrite=bar <copy &&
 	git log -2 >actual &&
 	test_cmp expect actual
 '
@@ -1071,8 +1139,10 @@ test_expect_success 'git notes copy --for-rewrite (overwrite)' '
 	git notes add -f -m"a fresh note" HEAD^ &&
 	test_config notes.rewriteMode overwrite &&
 	test_config notes.rewriteRef "refs/notes/*" &&
-	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
-	git notes copy --for-rewrite=foo &&
+	from=$(git rev-parse HEAD^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
+	git notes copy --for-rewrite=foo <copy &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -1080,8 +1150,10 @@ test_expect_success 'git notes copy --for-rewrite (overwrite)' '
 test_expect_success 'git notes copy --for-rewrite (ignore)' '
 	test_config notes.rewriteMode ignore &&
 	test_config notes.rewriteRef "refs/notes/*" &&
-	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
-	git notes copy --for-rewrite=foo &&
+	from=$(git rev-parse HEAD^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
+	git notes copy --for-rewrite=foo <copy &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -1103,8 +1175,10 @@ test_expect_success 'git notes copy --for-rewrite (append)' '
 	git notes add -f -m"another fresh note" HEAD^ &&
 	test_config notes.rewriteMode concatenate &&
 	test_config notes.rewriteRef "refs/notes/*" &&
-	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
-	git notes copy --for-rewrite=foo &&
+	from=$(git rev-parse HEAD^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
+	git notes copy --for-rewrite=foo <copy &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -1131,9 +1205,13 @@ test_expect_success 'git notes copy --for-rewrite (append two to one)' '
 	git notes add -f -m"append 2" HEAD^^ &&
 	test_config notes.rewriteMode concatenate &&
 	test_config notes.rewriteRef "refs/notes/*" &&
-	(echo $(git rev-parse HEAD^) $(git rev-parse HEAD) &&
-	echo $(git rev-parse HEAD^^) $(git rev-parse HEAD)) |
-	git notes copy --for-rewrite=foo &&
+	from=$(git rev-parse HEAD^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
+	from=$(git rev-parse HEAD^^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >>copy &&
+	git notes copy --for-rewrite=foo <copy &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -1142,8 +1220,10 @@ test_expect_success 'git notes copy --for-rewrite (append empty)' '
 	git notes remove HEAD^ &&
 	test_config notes.rewriteMode concatenate &&
 	test_config notes.rewriteRef "refs/notes/*" &&
-	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
-	git notes copy --for-rewrite=foo &&
+	from=$(git rev-parse HEAD^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
+	git notes copy --for-rewrite=foo <copy &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -1163,8 +1243,10 @@ test_expect_success 'GIT_NOTES_REWRITE_MODE works' '
 	test_config notes.rewriteMode concatenate &&
 	test_config notes.rewriteRef "refs/notes/*" &&
 	git notes add -f -m"replacement note 1" HEAD^ &&
-	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
-	GIT_NOTES_REWRITE_MODE=overwrite git notes copy --for-rewrite=foo &&
+	from=$(git rev-parse HEAD^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
+	GIT_NOTES_REWRITE_MODE=overwrite git notes copy --for-rewrite=foo <copy &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -1184,9 +1266,11 @@ test_expect_success 'GIT_NOTES_REWRITE_REF works' '
 	git notes add -f -m"replacement note 2" HEAD^ &&
 	test_config notes.rewriteMode overwrite &&
 	test_unconfig notes.rewriteRef &&
-	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
+	from=$(git rev-parse HEAD^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
 	GIT_NOTES_REWRITE_REF=refs/notes/commits:refs/notes/other \
-		git notes copy --for-rewrite=foo &&
+		git notes copy --for-rewrite=foo <copy &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -1195,9 +1279,11 @@ test_expect_success 'GIT_NOTES_REWRITE_REF overrides config' '
 	git notes add -f -m"replacement note 3" HEAD^ &&
 	test_config notes.rewriteMode overwrite &&
 	test_config notes.rewriteRef refs/notes/other &&
-	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
+	from=$(git rev-parse HEAD^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
 	GIT_NOTES_REWRITE_REF=refs/notes/commits \
-		git notes copy --for-rewrite=foo &&
+		git notes copy --for-rewrite=foo <copy &&
 	git log -1 >actual &&
 	grep "replacement note 3" actual
 '
@@ -1212,26 +1298,36 @@ test_expect_success 'git notes copy diagnoses too many or too few parameters' '
 test_expect_success 'git notes get-ref expands refs/heads/master to refs/notes/refs/heads/master' '
 	test_unconfig core.notesRef &&
 	sane_unset GIT_NOTES_REF &&
-	test "$(git notes --ref=refs/heads/master get-ref)" = "refs/notes/refs/heads/master"
+	echo refs/notes/refs/heads/master >expect &&
+	git notes --ref=refs/heads/master get-ref >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'git notes get-ref (no overrides)' '
 	test_unconfig core.notesRef &&
 	sane_unset GIT_NOTES_REF &&
-	test "$(git notes get-ref)" = "refs/notes/commits"
+	echo refs/notes/commits >expect &&
+	git notes get-ref >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'git notes get-ref (core.notesRef)' '
 	test_config core.notesRef refs/notes/foo &&
-	test "$(git notes get-ref)" = "refs/notes/foo"
+	echo refs/notes/foo >expect &&
+	git notes get-ref >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'git notes get-ref (GIT_NOTES_REF)' '
-	test "$(GIT_NOTES_REF=refs/notes/bar git notes get-ref)" = "refs/notes/bar"
+	echo refs/notes/bar >expect &&
+	GIT_NOTES_REF=refs/notes/bar git notes get-ref >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'git notes get-ref (--ref)' '
-	test "$(GIT_NOTES_REF=refs/notes/bar git notes --ref=baz get-ref)" = "refs/notes/baz"
+	echo refs/notes/baz >expect &&
+	GIT_NOTES_REF=refs/notes/bar git notes --ref=baz get-ref >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'setup testing of empty notes' '
-- 
2.24.0.450.g7a9a4598a9


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v2 05/21] t3600: use test_line_count() where possible
  2019-11-21  0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                     ` (3 preceding siblings ...)
  2019-11-21  0:45   ` [PATCH v2 04/21] t3301: " Denton Liu
@ 2019-11-21  0:45   ` Denton Liu
  2019-11-21  0:46   ` [PATCH v2 06/21] t3600: stop losing return codes of git commands Denton Liu
                     ` (16 subsequent siblings)
  21 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-21  0:45 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Since we have a helper function that can test the number of lines in a
file that gives better debugging information on failure, use
test_line_count() to test the number of lines.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t3600-rm.sh | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh
index 8c8cca5bfb..f6e659b7e9 100755
--- a/t/t3600-rm.sh
+++ b/t/t3600-rm.sh
@@ -113,9 +113,10 @@ test_expect_success '"rm" command printed' '
 	echo frotz >test-file &&
 	git add test-file &&
 	git commit -m "add file for rm test" &&
-	git rm test-file >rm-output &&
-	test $(grep "^rm " rm-output | wc -l) = 1 &&
-	rm -f test-file rm-output &&
+	git rm test-file >rm-output.raw &&
+	grep "^rm " rm-output.raw >rm-output &&
+	test_line_count = 1 rm-output &&
+	rm -f test-file rm-output.raw rm-output &&
 	git commit -m "remove file from rm test"
 '
 
-- 
2.24.0.450.g7a9a4598a9


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v2 06/21] t3600: stop losing return codes of git commands
  2019-11-21  0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                     ` (4 preceding siblings ...)
  2019-11-21  0:45   ` [PATCH v2 05/21] t3600: use test_line_count() where possible Denton Liu
@ 2019-11-21  0:46   ` Denton Liu
  2019-11-21  0:46   ` [PATCH v2 07/21] t3600: comment on inducing SIGPIPE in `git rm` Denton Liu
                     ` (15 subsequent siblings)
  21 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-21  0:46 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

When a command is in a non-assignment command substitution, the return
code will be lost in favour of the surrounding command's. As a result,
if a git command fails, we won't know about it. Rewrite instances of
this so that git commands are either run in an assignment-only command
substitution so that their return codes aren't lost.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t3600-rm.sh | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh
index f6e659b7e9..0c3bf10edd 100755
--- a/t/t3600-rm.sh
+++ b/t/t3600-rm.sh
@@ -304,7 +304,8 @@ EOF
 
 test_expect_success 'rm removes empty submodules from work tree' '
 	mkdir submod &&
-	git update-index --add --cacheinfo 160000 $(git rev-parse HEAD) submod &&
+	hash=$(git rev-parse HEAD) &&
+	git update-index --add --cacheinfo 160000 "$hash" submod &&
 	git config -f .gitmodules submodule.sub.url ./. &&
 	git config -f .gitmodules submodule.sub.path submod &&
 	git submodule init &&
@@ -623,7 +624,8 @@ test_expect_success 'setup subsubmodule' '
 	git submodule update &&
 	(
 		cd submod &&
-		git update-index --add --cacheinfo 160000 $(git rev-parse HEAD) subsubmod &&
+		hash=$(git rev-parse HEAD) &&
+		git update-index --add --cacheinfo 160000 "$hash" subsubmod &&
 		git config -f .gitmodules submodule.sub.url ../. &&
 		git config -f .gitmodules submodule.sub.path subsubmod &&
 		git submodule init &&
-- 
2.24.0.450.g7a9a4598a9


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v2 07/21] t3600: comment on inducing SIGPIPE in `git rm`
  2019-11-21  0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                     ` (5 preceding siblings ...)
  2019-11-21  0:46   ` [PATCH v2 06/21] t3600: stop losing return codes of git commands Denton Liu
@ 2019-11-21  0:46   ` Denton Liu
  2019-11-21  0:46   ` [PATCH v2 08/21] t4015: stop losing return codes of git commands Denton Liu
                     ` (14 subsequent siblings)
  21 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-21  0:46 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Add a comment about intentionally inducing SIGPIPE since this is unusual
and future developers should be aware. Also, even though we are trying
to refactor git commands out of the upstream of pipes, we cannot do it
here since we rely on it being upstream to induce SIGPIPE. Comment on
that as well so that future developers do not try to change it.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t3600-rm.sh | 1 +
 1 file changed, 1 insertion(+)

diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh
index 0c3bf10edd..0ea858d652 100755
--- a/t/t3600-rm.sh
+++ b/t/t3600-rm.sh
@@ -251,6 +251,7 @@ test_expect_success 'choking "git rm" should not let it die with cruft' '
 		echo "100644 $hash 0	some-file-$i"
 		i=$(( $i + 1 ))
 	done | git update-index --index-info &&
+	# git command is intentionally placed upstream of pipe to induce SIGPIPE
 	git rm -n "some-file-*" | : &&
 	test_path_is_missing .git/index.lock
 '
-- 
2.24.0.450.g7a9a4598a9


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v2 08/21] t4015: stop losing return codes of git commands
  2019-11-21  0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                     ` (6 preceding siblings ...)
  2019-11-21  0:46   ` [PATCH v2 07/21] t3600: comment on inducing SIGPIPE in `git rm` Denton Liu
@ 2019-11-21  0:46   ` Denton Liu
  2019-11-21  0:46   ` [PATCH v2 09/21] t4015: use test_write_lines() Denton Liu
                     ` (13 subsequent siblings)
  21 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-21  0:46 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Currently, there are two ways where the return codes of git commands are
lost. The first way is when a command is in the upstream of a pipe. In a
pipe, only the return code of the last command is used. Thus, all other
commands will have their return codes masked. Rewrite pipes so that
there are no git commands upstream.

The other way is when a command is in a non-assignment command
substitution. The return code will be lost in favour of the surrounding
command's. Rewrite instances of this so that git commands are either run
on their own or in an assignment-only command substitution.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t4015-diff-whitespace.sh | 119 ++++++++++++++++++++++---------------
 1 file changed, 72 insertions(+), 47 deletions(-)

diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh
index eadaf57262..7fb83c8eff 100755
--- a/t/t4015-diff-whitespace.sh
+++ b/t/t4015-diff-whitespace.sh
@@ -16,7 +16,8 @@ test_expect_success "Ray Lehtiniemi's example" '
 	} while (0);
 	EOF
 	git update-index --add x &&
-	before=$(git rev-parse --short $(git hash-object x)) &&
+	old_hash_x=$(git hash-object x) &&
+	before=$(git rev-parse --short "$old_hash_x") &&
 
 	cat <<-\EOF >x &&
 	do
@@ -25,7 +26,8 @@ test_expect_success "Ray Lehtiniemi's example" '
 	}
 	while (0);
 	EOF
-	after=$(git rev-parse --short $(git hash-object x)) &&
+	new_hash_x=$(git hash-object x) &&
+	after=$(git rev-parse --short "$new_hash_x") &&
 
 	cat <<-EOF >expect &&
 	diff --git a/x b/x
@@ -63,7 +65,8 @@ test_expect_success 'another test, without options' '
 	EOF
 
 	git update-index x &&
-	before=$(git rev-parse --short $(git hash-object x)) &&
+	old_hash_x=$(git hash-object x) &&
+	before=$(git rev-parse --short "$old_hash_x") &&
 
 	tr "_" " " <<-\EOF >x &&
 	_	whitespace at beginning
@@ -73,7 +76,8 @@ test_expect_success 'another test, without options' '
 	unchanged line
 	CR at end
 	EOF
-	after=$(git rev-parse --short $(git hash-object x)) &&
+	new_hash_x=$(git hash-object x) &&
+	after=$(git rev-parse --short "$new_hash_x") &&
 
 	tr "Q_" "\015 " <<-EOF >expect &&
 	diff --git a/x b/x
@@ -526,13 +530,15 @@ test_expect_success 'ignore-blank-lines: mix changes and blank lines' '
 test_expect_success 'check mixed spaces and tabs in indent' '
 	# This is indented with SP HT SP.
 	echo " 	 foo();" >x &&
-	git diff --check | grep "space before tab in indent"
+	test_must_fail git diff --check >check &&
+	grep "space before tab in indent" check
 '
 
 test_expect_success 'check mixed tabs and spaces in indent' '
 	# This is indented with HT SP HT.
 	echo "	 	foo();" >x &&
-	git diff --check | grep "space before tab in indent"
+	test_must_fail git diff --check >check &&
+	grep "space before tab in indent" check
 '
 
 test_expect_success 'check with no whitespace errors' '
@@ -753,20 +759,23 @@ test_expect_success 'check tab-in-indent excluded from wildcard whitespace attri
 test_expect_success 'line numbers in --check output are correct' '
 	echo "" >x &&
 	echo "foo(); " >>x &&
-	git diff --check | grep "x:2:"
+	test_must_fail git diff --check >check &&
+	grep "x:2:" check
 '
 
 test_expect_success 'checkdiff detects new trailing blank lines (1)' '
 	echo "foo();" >x &&
 	echo "" >>x &&
-	git diff --check | grep "new blank line"
+	test_must_fail git diff --check >check &&
+	grep "new blank line" check
 '
 
 test_expect_success 'checkdiff detects new trailing blank lines (2)' '
 	{ echo a; echo b; echo; echo; } >x &&
 	git add x &&
 	{ echo a; echo; echo; echo; echo; } >x &&
-	git diff --check | grep "new blank line"
+	test_must_fail git diff --check >check &&
+	grep "new blank line" check
 '
 
 test_expect_success 'checkdiff allows new blank lines' '
@@ -794,14 +803,16 @@ test_expect_success 'whitespace-only changes reported across renames' '
 	git reset --hard &&
 	for i in 1 2 3 4 5 6 7 8 9; do echo "$i$i$i$i$i$i"; done >x &&
 	git add x &&
-	before=$(git rev-parse --short $(git hash-object x)) &&
+	hash_x=$(git hash-object x) &&
+	before=$(git rev-parse --short "$hash_x") &&
 	git commit -m "base" &&
 	sed -e "5s/^/ /" x >z &&
 	git rm x &&
 	git add z &&
-	after=$(git rev-parse --short $(git hash-object z)) &&
-	git diff -w -M --cached |
-	sed -e "/^similarity index /s/[0-9][0-9]*/NUM/" >actual &&
+	hash_z=$(git hash-object z) &&
+	after=$(git rev-parse --short "$hash_z") &&
+	git diff -w -M --cached >actual.raw &&
+	sed -e "/^similarity index /s/[0-9][0-9]*/NUM/" actual.raw >actual &&
 	cat <<-EOF >expect &&
 	diff --git a/x b/z
 	similarity index NUM%
@@ -840,7 +851,8 @@ test_expect_success 'combined diff with autocrlf conversion' '
 	git config core.autocrlf true &&
 	test_must_fail git merge master &&
 
-	git diff | sed -e "1,/^@@@/d" >actual &&
+	git diff >actual.raw &&
+	sed -e "1,/^@@@/d" actual.raw >actual &&
 	! grep "^-" actual
 
 '
@@ -864,11 +876,14 @@ test_expect_success 'diff that introduces a line with only tabs' '
 	git config core.whitespace blank-at-eol &&
 	git reset --hard &&
 	echo "test" >x &&
-	before=$(git rev-parse --short $(git hash-object x)) &&
+	old_hash_x=$(git hash-object x) &&
+	before=$(git rev-parse --short "$old_hash_x") &&
 	git commit -m "initial" x &&
 	echo "{NTN}" | tr "NT" "\n\t" >>x &&
-	after=$(git rev-parse --short $(git hash-object x)) &&
-	git diff --color | test_decode_color >current &&
+	new_hash_x=$(git hash-object x) &&
+	after=$(git rev-parse --short "$new_hash_x") &&
+	git diff --color >current.raw &&
+	test_decode_color <current.raw >current &&
 
 	cat >expected <<-EOF &&
 	<BOLD>diff --git a/x b/x<RESET>
@@ -891,17 +906,19 @@ test_expect_success 'diff that introduces and removes ws breakages' '
 		echo "0. blank-at-eol " &&
 		echo "1. blank-at-eol "
 	} >x &&
-	before=$(git rev-parse --short $(git hash-object x)) &&
+	old_hash_x=$(git hash-object x) &&
+	before=$(git rev-parse --short "$old_hash_x") &&
 	git commit -a --allow-empty -m preimage &&
 	{
 		echo "0. blank-at-eol " &&
 		echo "1. still-blank-at-eol " &&
 		echo "2. and a new line "
 	} >x &&
-	after=$(git rev-parse --short $(git hash-object x)) &&
+	new_hash_x=$(git hash-object x) &&
+	after=$(git rev-parse --short "$new_hash_x") &&
 
-	git diff --color |
-	test_decode_color >current &&
+	git diff --color >current.raw &&
+	test_decode_color <current.raw >current &&
 
 	cat >expected <<-EOF &&
 	<BOLD>diff --git a/x b/x<RESET>
@@ -925,14 +942,16 @@ test_expect_success 'ws-error-highlight test setup' '
 		echo "0. blank-at-eol " &&
 		echo "1. blank-at-eol "
 	} >x &&
-	before=$(git rev-parse --short $(git hash-object x)) &&
+	old_hash_x=$(git hash-object x) &&
+	before=$(git rev-parse --short "$old_hash_x") &&
 	git commit -a --allow-empty -m preimage &&
 	{
 		echo "0. blank-at-eol " &&
 		echo "1. still-blank-at-eol " &&
 		echo "2. and a new line "
 	} >x &&
-	after=$(git rev-parse --short $(git hash-object x)) &&
+	new_hash_x=$(git hash-object x) &&
+	after=$(git rev-parse --short "$new_hash_x") &&
 
 	cat >expect.default-old <<-EOF &&
 	<BOLD>diff --git a/x b/x<RESET>
@@ -974,32 +993,32 @@ test_expect_success 'ws-error-highlight test setup' '
 
 test_expect_success 'test --ws-error-highlight option' '
 
-	git diff --color --ws-error-highlight=default,old |
-	test_decode_color >current &&
+	git diff --color --ws-error-highlight=default,old >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.default-old current &&
 
-	git diff --color --ws-error-highlight=all |
-	test_decode_color >current &&
+	git diff --color --ws-error-highlight=all >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.all current &&
 
-	git diff --color --ws-error-highlight=none |
-	test_decode_color >current &&
+	git diff --color --ws-error-highlight=none >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.none current
 
 '
 
 test_expect_success 'test diff.wsErrorHighlight config' '
 
-	git -c diff.wsErrorHighlight=default,old diff --color |
-	test_decode_color >current &&
+	git -c diff.wsErrorHighlight=default,old diff --color >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.default-old current &&
 
-	git -c diff.wsErrorHighlight=all diff --color |
-	test_decode_color >current &&
+	git -c diff.wsErrorHighlight=all diff --color >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.all current &&
 
-	git -c diff.wsErrorHighlight=none diff --color |
-	test_decode_color >current &&
+	git -c diff.wsErrorHighlight=none diff --color >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.none current
 
 '
@@ -1007,18 +1026,18 @@ test_expect_success 'test diff.wsErrorHighlight config' '
 test_expect_success 'option overrides diff.wsErrorHighlight' '
 
 	git -c diff.wsErrorHighlight=none \
-		diff --color --ws-error-highlight=default,old |
-	test_decode_color >current &&
+		diff --color --ws-error-highlight=default,old >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.default-old current &&
 
 	git -c diff.wsErrorHighlight=default \
-		diff --color --ws-error-highlight=all |
-	test_decode_color >current &&
+		diff --color --ws-error-highlight=all >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.all current &&
 
 	git -c diff.wsErrorHighlight=all \
-		diff --color --ws-error-highlight=none |
-	test_decode_color >current &&
+		diff --color --ws-error-highlight=none >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.none current
 
 '
@@ -1038,7 +1057,8 @@ test_expect_success 'detect moved code, complete file' '
 	git mv test.c main.c &&
 	test_config color.diff.oldMoved "normal red" &&
 	test_config color.diff.newMoved "normal green" &&
-	git diff HEAD --color-moved=zebra --color --no-renames | test_decode_color >actual &&
+	git diff HEAD --color-moved=zebra --color --no-renames >actual.raw &&
+	test_decode_color <actual.raw >actual &&
 	cat >expected <<-EOF &&
 	<BOLD>diff --git a/main.c b/main.c<RESET>
 	<BOLD>new file mode 100644<RESET>
@@ -1141,9 +1161,12 @@ test_expect_success 'detect malicious moved code, inside file' '
 			bar();
 		}
 	EOF
-	after_main=$(git rev-parse --short $(git hash-object main.c)) &&
-	after_test=$(git rev-parse --short $(git hash-object test.c)) &&
-	git diff HEAD --no-renames --color-moved=zebra --color | test_decode_color >actual &&
+	hash_main=$(git hash-object main.c) &&
+	after_main=$(git rev-parse --short "$hash_main") &&
+	hash_test=$(git hash-object test.c) &&
+	after_test=$(git rev-parse --short "$hash_test") &&
+	git diff HEAD --no-renames --color-moved=zebra --color >actual.raw &&
+	test_decode_color <actual.raw >actual &&
 	cat <<-EOF >expected &&
 	<BOLD>diff --git a/main.c b/main.c<RESET>
 	<BOLD>index $before_main..$after_main 100644<RESET>
@@ -1192,7 +1215,8 @@ test_expect_success 'plain moved code, inside file' '
 	test_config color.diff.oldMovedAlternative "blue" &&
 	test_config color.diff.newMovedAlternative "yellow" &&
 	# needs previous test as setup
-	git diff HEAD --no-renames --color-moved=plain --color | test_decode_color >actual &&
+	git diff HEAD --no-renames --color-moved=plain --color >actual.raw &&
+	test_decode_color <actual.raw >actual &&
 	cat <<-EOF >expected &&
 	<BOLD>diff --git a/main.c b/main.c<RESET>
 	<BOLD>index $before_main..$after_main 100644<RESET>
@@ -1771,7 +1795,8 @@ test_expect_success 'move detection with submodules' '
 	! grep BRED decoded_actual &&
 
 	# nor did we mess with it another way
-	git diff --submodule=diff --color | test_decode_color >expect &&
+	git diff --submodule=diff --color >expect.raw &&
+	test_decode_color <expect.raw >expect &&
 	test_cmp expect decoded_actual &&
 	rm -rf bananas &&
 	git submodule deinit bananas
-- 
2.24.0.450.g7a9a4598a9


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v2 09/21] t4015: use test_write_lines()
  2019-11-21  0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                     ` (7 preceding siblings ...)
  2019-11-21  0:46   ` [PATCH v2 08/21] t4015: stop losing return codes of git commands Denton Liu
@ 2019-11-21  0:46   ` Denton Liu
  2019-11-21  0:46   ` [PATCH v2 10/21] t4138: stop losing return codes of git commands Denton Liu
                     ` (12 subsequent siblings)
  21 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-21  0:46 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Instead of rolling our own method to write out some lines into a file,
use the existing test_write_lines().

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t4015-diff-whitespace.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh
index 7fb83c8eff..4c540b1d70 100755
--- a/t/t4015-diff-whitespace.sh
+++ b/t/t4015-diff-whitespace.sh
@@ -771,9 +771,9 @@ test_expect_success 'checkdiff detects new trailing blank lines (1)' '
 '
 
 test_expect_success 'checkdiff detects new trailing blank lines (2)' '
-	{ echo a; echo b; echo; echo; } >x &&
+	test_write_lines a b "" "" >x &&
 	git add x &&
-	{ echo a; echo; echo; echo; echo; } >x &&
+	test_write_lines a "" "" "" "" >x &&
 	test_must_fail git diff --check >check &&
 	grep "new blank line" check
 '
-- 
2.24.0.450.g7a9a4598a9


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v2 10/21] t4138: stop losing return codes of git commands
  2019-11-21  0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                     ` (8 preceding siblings ...)
  2019-11-21  0:46   ` [PATCH v2 09/21] t4015: use test_write_lines() Denton Liu
@ 2019-11-21  0:46   ` Denton Liu
  2019-11-21  0:46   ` [PATCH v2 11/21] t5317: " Denton Liu
                     ` (11 subsequent siblings)
  21 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-21  0:46 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

In a pipe, only the return code of the last command is used. Thus, all
other commands will have their return codes masked. Rewrite pipes so
that there are no git commands upstream so that we will know if a
command fails.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t4138-apply-ws-expansion.sh | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/t/t4138-apply-ws-expansion.sh b/t/t4138-apply-ws-expansion.sh
index 3b636a63a3..b19faeb67a 100755
--- a/t/t4138-apply-ws-expansion.sh
+++ b/t/t4138-apply-ws-expansion.sh
@@ -17,8 +17,8 @@ test_expect_success setup '
 	printf "\t%s\n" 1 2 3 >after &&
 	printf "%64s\n" a b c >>after &&
 	printf "\t%s\n" 4 5 6 >>after &&
-	git diff --no-index before after |
-		sed -e "s/before/test-1/" -e "s/after/test-1/" >patch1.patch &&
+	test_expect_code 1 git diff --no-index before after >patch1.patch.raw &&
+	sed -e "s/before/test-1/" -e "s/after/test-1/" patch1.patch.raw >patch1.patch &&
 	printf "%64s\n" 1 2 3 4 5 6 >test-1 &&
 	printf "%64s\n" 1 2 3 a b c 4 5 6 >expect-1 &&
 
@@ -33,8 +33,8 @@ test_expect_success setup '
 		x=$(( $x + 1 ))
 	done &&
 	printf "\t%s\n" d e f >>after &&
-	git diff --no-index before after |
-		sed -e "s/before/test-2/" -e "s/after/test-2/" >patch2.patch &&
+	test_expect_code 1 git diff --no-index before after >patch2.patch.raw &&
+	sed -e "s/before/test-2/" -e "s/after/test-2/" patch2.patch.raw >patch2.patch &&
 	printf "%64s\n" a b c d e f >test-2 &&
 	printf "%64s\n" a b c >expect-2 &&
 	x=1 &&
@@ -56,8 +56,8 @@ test_expect_success setup '
 		x=$(( $x + 1 ))
 	done &&
 	printf "\t%s\n" d e f >>after &&
-	git diff --no-index before after |
-	sed -e "s/before/test-3/" -e "s/after/test-3/" >patch3.patch &&
+	test_expect_code 1 git diff --no-index before after >patch3.patch.raw &&
+	sed -e "s/before/test-3/" -e "s/after/test-3/" patch3.patch.raw >patch3.patch &&
 	printf "%64s\n" a b c d e f >test-3 &&
 	printf "%64s\n" a b c >expect-3 &&
 	x=0 &&
@@ -84,8 +84,8 @@ test_expect_success setup '
 		printf "\t%02d\n" $x >>after
 		x=$(( $x + 1 ))
 	done &&
-	git diff --no-index before after |
-	sed -e "s/before/test-4/" -e "s/after/test-4/" >patch4.patch &&
+	test_expect_code 1 git diff --no-index before after >patch4.patch.raw &&
+	sed -e "s/before/test-4/" -e "s/after/test-4/" patch4.patch.raw >patch4.patch &&
 	>test-4 &&
 	x=0 &&
 	while test $x -lt 50
-- 
2.24.0.450.g7a9a4598a9


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v2 11/21] t5317: stop losing return codes of git commands
  2019-11-21  0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                     ` (9 preceding siblings ...)
  2019-11-21  0:46   ` [PATCH v2 10/21] t4138: stop losing return codes of git commands Denton Liu
@ 2019-11-21  0:46   ` " Denton Liu
  2019-11-21  0:46   ` [PATCH v2 12/21] t5317: use ! grep to check for no matching lines Denton Liu
                     ` (10 subsequent siblings)
  21 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-21  0:46 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Currently, there are two ways where the return codes of git commands are
lost. The first way is when a command is in the upstream of a pipe. In a
pipe, only the return code of the last command is used. Thus, all other
commands will have their return codes masked. Rewrite pipes so that
there are no git commands upstream.

The other way is when a command is in a non-assignment command
substitution. The return code will be lost in favour of the surrounding
command's. Rewrite instances of this such that git commands output to a
file and surrounding commands only call command substitutions with
non-git commands.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5317-pack-objects-filter-objects.sh | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/t/t5317-pack-objects-filter-objects.sh b/t/t5317-pack-objects-filter-objects.sh
index 2d2f5d0229..a8bbad74e2 100755
--- a/t/t5317-pack-objects-filter-objects.sh
+++ b/t/t5317-pack-objects-filter-objects.sh
@@ -72,7 +72,8 @@ test_expect_success 'get an error for missing tree object' '
 	echo foo >r5/foo &&
 	git -C r5 add foo &&
 	git -C r5 commit -m "foo" &&
-	del=$(git -C r5 rev-parse HEAD^{tree} | sed "s|..|&/|") &&
+	git -C r5 rev-parse HEAD^{tree} >tree &&
+	del=$(sed "s|..|&/|" tree) &&
 	rm r5/.git/objects/$del &&
 	test_must_fail git -C r5 pack-objects --revs --stdout 2>bad_tree <<-EOF &&
 	HEAD
@@ -230,10 +231,9 @@ test_expect_success 'verify explicitly specifying oversized blob in input' '
 	awk -f print_2.awk ls_files_result |
 	sort >expected &&
 
-	git -C r2 pack-objects --revs --stdout --filter=blob:limit=1k >filter.pack <<-EOF &&
-	HEAD
-	$(git -C r2 rev-parse HEAD:large.10000)
-	EOF
+	echo HEAD >objects &&
+	git -C r2 rev-parse HEAD:large.10000 >>objects &&
+	git -C r2 pack-objects --revs --stdout --filter=blob:limit=1k <objects >filter.pack &&
 	git -C r2 index-pack ../filter.pack &&
 
 	git -C r2 verify-pack -v ../filter.pack >verify_result &&
@@ -377,7 +377,8 @@ test_expect_success 'verify sparse:oid=OID' '
 	awk -f print_2.awk ls_files_result |
 	sort >expected &&
 
-	oid=$(git -C r4 ls-files -s pattern | awk -f print_2.awk) &&
+	git -C r4 ls-files -s pattern >staged &&
+	oid=$(awk -f print_2.awk staged) &&
 	git -C r4 pack-objects --revs --stdout --filter=sparse:oid=$oid >filter.pack <<-EOF &&
 	HEAD
 	EOF
-- 
2.24.0.450.g7a9a4598a9


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v2 12/21] t5317: use ! grep to check for no matching lines
  2019-11-21  0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                     ` (10 preceding siblings ...)
  2019-11-21  0:46   ` [PATCH v2 11/21] t5317: " Denton Liu
@ 2019-11-21  0:46   ` Denton Liu
  2019-11-21 12:59     ` Eric Sunshine
  2019-11-21  0:46   ` [PATCH v2 13/21] t5703: simplify one-time-sed generation logic Denton Liu
                     ` (9 subsequent siblings)
  21 siblings, 1 reply; 169+ messages in thread
From: Denton Liu @ 2019-11-21  0:46 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Several times in t5317, we would use `wc -l` to ensure that a grep
result is empty. However, grep already has a way to do that... Its
return code! Use `! grep` in the cases where we are ensuring that there
are no matching lines.

It turns out that these tests were simply born this way[1], doing all
this unnecessary work for no reason, probably due to copy/paste
programming, and it seems no reviewer caught it. Likewise, the
unnecessary work wasn't noticed even when the code was later touched
for various cleanups[2,3].

[1]: 9535ce7337 (pack-objects: add list-objects filtering, 2017-11-21)
[2]: bdbc17e86a (tests: standardize pipe placement, 2018-10-05)
[3]: 61de0ff695 (tests: don't swallow Git errors upstream of pipes, 2018-10-05)

Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Denton Liu <liu.denton@gmail.com>
---

Notes:
    Thanks for your help, Eric. I shamelessly stole your message text for
    the commit message.

 t/t5317-pack-objects-filter-objects.sh | 21 +++------------------
 1 file changed, 3 insertions(+), 18 deletions(-)

diff --git a/t/t5317-pack-objects-filter-objects.sh b/t/t5317-pack-objects-filter-objects.sh
index a8bbad74e2..dc0446574b 100755
--- a/t/t5317-pack-objects-filter-objects.sh
+++ b/t/t5317-pack-objects-filter-objects.sh
@@ -45,12 +45,7 @@ test_expect_success 'verify blob:none packfile has no blobs' '
 	git -C r1 index-pack ../filter.pack &&
 
 	git -C r1 verify-pack -v ../filter.pack >verify_result &&
-	grep blob verify_result |
-	awk -f print_1.awk |
-	sort >observed &&
-
-	nr=$(wc -l <observed) &&
-	test 0 -eq $nr
+	! grep blob verify_result
 '
 
 test_expect_success 'verify normal and blob:none packfiles have same commits/trees' '
@@ -149,12 +144,7 @@ test_expect_success 'verify blob:limit=500 omits all blobs' '
 	git -C r2 index-pack ../filter.pack &&
 
 	git -C r2 verify-pack -v ../filter.pack >verify_result &&
-	grep blob verify_result |
-	awk -f print_1.awk |
-	sort >observed &&
-
-	nr=$(wc -l <observed) &&
-	test 0 -eq $nr
+	! grep blob verify_result
 '
 
 test_expect_success 'verify blob:limit=1000' '
@@ -164,12 +154,7 @@ test_expect_success 'verify blob:limit=1000' '
 	git -C r2 index-pack ../filter.pack &&
 
 	git -C r2 verify-pack -v ../filter.pack >verify_result &&
-	grep blob verify_result |
-	awk -f print_1.awk |
-	sort >observed &&
-
-	nr=$(wc -l <observed) &&
-	test 0 -eq $nr
+	! grep blob verify_result
 '
 
 test_expect_success 'verify blob:limit=1001' '
-- 
2.24.0.450.g7a9a4598a9


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v2 13/21] t5703: simplify one-time-sed generation logic
  2019-11-21  0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                     ` (11 preceding siblings ...)
  2019-11-21  0:46   ` [PATCH v2 12/21] t5317: use ! grep to check for no matching lines Denton Liu
@ 2019-11-21  0:46   ` Denton Liu
  2019-11-21 13:12     ` Eric Sunshine
  2019-11-21  0:46   ` [PATCH v2 14/21] t5703: stop losing return codes of git commands Denton Liu
                     ` (8 subsequent siblings)
  21 siblings, 1 reply; 169+ messages in thread
From: Denton Liu @ 2019-11-21  0:46 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

In inconsistency(), we had two `git rev-parse` invocations in the
upstream of a pipe within a command substitution. In case this
invocation ever failed, its exit code would be swallowed up and we would
not know about it.

Pull the command substitutions out into variable assignments so that
their return codes are not lost.

Drop the pipe into tr because command substitutions should already strip
leading and trailing whitespace, including newlines.

Finally, convert the printf into an echo because it isn't necessary
anymore.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5703-upload-pack-ref-in-want.sh | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/t/t5703-upload-pack-ref-in-want.sh b/t/t5703-upload-pack-ref-in-want.sh
index 3a2c143c6d..88338c4e09 100755
--- a/t/t5703-upload-pack-ref-in-want.sh
+++ b/t/t5703-upload-pack-ref-in-want.sh
@@ -312,10 +312,9 @@ inconsistency () {
 	# repository appears to change during negotiation, for example, when
 	# different servers in a load-balancing arrangement serve (stateless)
 	# RPCs during a single negotiation.
-	printf "s/%s/%s/" \
-	       $(git -C "$REPO" rev-parse $1 | tr -d "\n") \
-	       $(git -C "$REPO" rev-parse $2 | tr -d "\n") \
-	       >"$HTTPD_ROOT_PATH/one-time-sed"
+	oid1=$(git -C "$REPO" rev-parse $1) &&
+	oid2=$(git -C "$REPO" rev-parse $2) &&
+	echo "s/$oid1/$oid2/" >"$HTTPD_ROOT_PATH/one-time-sed"
 }
 
 test_expect_success 'server is initially ahead - no ref in want' '
-- 
2.24.0.450.g7a9a4598a9


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v2 14/21] t5703: stop losing return codes of git commands
  2019-11-21  0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                     ` (12 preceding siblings ...)
  2019-11-21  0:46   ` [PATCH v2 13/21] t5703: simplify one-time-sed generation logic Denton Liu
@ 2019-11-21  0:46   ` Denton Liu
  2019-11-21  0:46   ` [PATCH v2 15/21] t7501: remove spaces after redirect operators Denton Liu
                     ` (7 subsequent siblings)
  21 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-21  0:46 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Currently, there are two ways where the return codes of git commands are
lost. The first way is when a command is in the upstream of a pipe. In a
pipe, only the return code of the last command is used. Thus, all other
commands will have their return codes masked. Rewrite pipes so that
there are no git commands upstream.

The other way is when a command is in a non-assignment command
substitution. The return code will be lost in favour of the surrounding
command's. Rewrite instances of this such that git commands are in an
assignment-only command substitution.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5703-upload-pack-ref-in-want.sh | 46 +++++++++++++++++++-----------
 1 file changed, 29 insertions(+), 17 deletions(-)

diff --git a/t/t5703-upload-pack-ref-in-want.sh b/t/t5703-upload-pack-ref-in-want.sh
index 88338c4e09..1424fabd4a 100755
--- a/t/t5703-upload-pack-ref-in-want.sh
+++ b/t/t5703-upload-pack-ref-in-want.sh
@@ -18,14 +18,16 @@ get_actual_commits () {
 		p
 		}' <out | test-tool pkt-line unpack-sideband >o.pack &&
 	git index-pack o.pack &&
-	git verify-pack -v o.idx | grep commit | cut -c-40 | sort >actual_commits
+	git verify-pack -v o.idx >objs &&
+	grep commit objs | cut -c-40 | sort >actual_commits
 }
 
 check_output () {
 	get_actual_refs &&
 	test_cmp expected_refs actual_refs &&
 	get_actual_commits &&
-	test_cmp expected_commits actual_commits
+	sort expected_commits >sorted_commits &&
+	test_cmp sorted_commits actual_commits
 }
 
 # c(o/foo) d(o/bar)
@@ -75,17 +77,19 @@ test_expect_success 'invalid want-ref line' '
 '
 
 test_expect_success 'basic want-ref' '
+	oid=$(git rev-parse f) &&
 	cat >expected_refs <<-EOF &&
-	$(git rev-parse f) refs/heads/master
+	$oid refs/heads/master
 	EOF
-	git rev-parse f | sort >expected_commits &&
+	git rev-parse f >expected_commits &&
 
+	oid=$(git rev-parse a) &&
 	test-tool pkt-line pack >in <<-EOF &&
 	command=fetch
 	0001
 	no-progress
 	want-ref refs/heads/master
-	have $(git rev-parse a)
+	have $oid
 	done
 	0000
 	EOF
@@ -95,19 +99,22 @@ test_expect_success 'basic want-ref' '
 '
 
 test_expect_success 'multiple want-ref lines' '
+	oid_c=$(git rev-parse c) &&
+	oid_d=$(git rev-parse d) &&
 	cat >expected_refs <<-EOF &&
-	$(git rev-parse c) refs/heads/o/foo
-	$(git rev-parse d) refs/heads/o/bar
+	$oid_c refs/heads/o/foo
+	$oid_d refs/heads/o/bar
 	EOF
-	git rev-parse c d | sort >expected_commits &&
+	git rev-parse c d >expected_commits &&
 
+	oid=$(git rev-parse b) &&
 	test-tool pkt-line pack >in <<-EOF &&
 	command=fetch
 	0001
 	no-progress
 	want-ref refs/heads/o/foo
 	want-ref refs/heads/o/bar
-	have $(git rev-parse b)
+	have $oid
 	done
 	0000
 	EOF
@@ -117,10 +124,11 @@ test_expect_success 'multiple want-ref lines' '
 '
 
 test_expect_success 'mix want and want-ref' '
+	oid=$(git rev-parse f) &&
 	cat >expected_refs <<-EOF &&
-	$(git rev-parse f) refs/heads/master
+	$oid refs/heads/master
 	EOF
-	git rev-parse e f | sort >expected_commits &&
+	git rev-parse e f >expected_commits &&
 
 	test-tool pkt-line pack >in <<-EOF &&
 	command=fetch
@@ -138,17 +146,19 @@ test_expect_success 'mix want and want-ref' '
 '
 
 test_expect_success 'want-ref with ref we already have commit for' '
+	oid=$(git rev-parse c) &&
 	cat >expected_refs <<-EOF &&
-	$(git rev-parse c) refs/heads/o/foo
+	$oid refs/heads/o/foo
 	EOF
 	>expected_commits &&
 
+	oid=$(git rev-parse c) &&
 	test-tool pkt-line pack >in <<-EOF &&
 	command=fetch
 	0001
 	no-progress
 	want-ref refs/heads/o/foo
-	have $(git rev-parse c)
+	have $oid
 	done
 	0000
 	EOF
@@ -211,13 +221,14 @@ test_expect_success 'fetching with exact OID' '
 
 	rm -rf local &&
 	cp -r "$LOCAL_PRISTINE" local &&
+	oid=$(git -C "$REPO" rev-parse d) &&
 	GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin \
-		$(git -C "$REPO" rev-parse d):refs/heads/actual &&
+		"$oid":refs/heads/actual &&
 
 	git -C "$REPO" rev-parse "d" >expected &&
 	git -C local rev-parse refs/heads/actual >actual &&
 	test_cmp expected actual &&
-	grep "want $(git -C "$REPO" rev-parse d)" log
+	grep "want $oid" log
 '
 
 test_expect_success 'fetching multiple refs' '
@@ -239,13 +250,14 @@ test_expect_success 'fetching ref and exact OID' '
 
 	rm -rf local &&
 	cp -r "$LOCAL_PRISTINE" local &&
+	oid=$(git -C "$REPO" rev-parse b) &&
 	GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin \
-		master $(git -C "$REPO" rev-parse b):refs/heads/actual &&
+		master "$oid":refs/heads/actual &&
 
 	git -C "$REPO" rev-parse "master" "b" >expected &&
 	git -C local rev-parse refs/remotes/origin/master refs/heads/actual >actual &&
 	test_cmp expected actual &&
-	grep "want $(git -C "$REPO" rev-parse b)" log &&
+	grep "want $oid" log &&
 	grep "want-ref refs/heads/master" log
 '
 
-- 
2.24.0.450.g7a9a4598a9


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v2 15/21] t7501: remove spaces after redirect operators
  2019-11-21  0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                     ` (13 preceding siblings ...)
  2019-11-21  0:46   ` [PATCH v2 14/21] t5703: stop losing return codes of git commands Denton Liu
@ 2019-11-21  0:46   ` Denton Liu
  2019-11-21  0:46   ` [PATCH v2 16/21] t7501: stop losing return codes of git commands Denton Liu
                     ` (6 subsequent siblings)
  21 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-21  0:46 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

For shell scripts, the usual convention is for there to be no space
after redirection operators, (e.g. `>file`, not `> file`). Remove these
spaces wherever they appear.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7501-commit-basic-functionality.sh | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/t/t7501-commit-basic-functionality.sh b/t/t7501-commit-basic-functionality.sh
index f1349af56e..5765d33c53 100755
--- a/t/t7501-commit-basic-functionality.sh
+++ b/t/t7501-commit-basic-functionality.sh
@@ -150,7 +150,7 @@ test_expect_success 'setup: commit message from file' '
 test_expect_success 'amend commit' '
 	cat >editor <<-\EOF &&
 	#!/bin/sh
-	sed -e "s/a file/an amend commit/g" < "$1" > "$1-"
+	sed -e "s/a file/an amend commit/g" <"$1" >"$1-"
 	mv "$1-" "$1"
 	EOF
 	chmod 755 editor &&
@@ -263,7 +263,7 @@ test_expect_success 'using message from other commit' '
 test_expect_success 'editing message from other commit' '
 	cat >editor <<-\EOF &&
 	#!/bin/sh
-	sed -e "s/amend/older/g"  < "$1" > "$1-"
+	sed -e "s/amend/older/g"  <"$1" >"$1-"
 	mv "$1-" "$1"
 	EOF
 	chmod 755 editor &&
@@ -367,7 +367,7 @@ test_expect_success 'amend commit to fix author' '
 		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
 		expected &&
 	git commit --amend --author="$author" &&
-	git cat-file -p HEAD > current &&
+	git cat-file -p HEAD >current &&
 	test_cmp expected current
 
 '
@@ -382,7 +382,7 @@ test_expect_success 'amend commit to fix date' '
 		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
 		expected &&
 	git commit --amend --date="$newtick" &&
-	git cat-file -p HEAD > current &&
+	git cat-file -p HEAD >current &&
 	test_cmp expected current
 
 '
@@ -448,7 +448,7 @@ test_expect_success 'signoff gap' '
 	git commit -s -m "welcome
 
 $alt" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
+	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
 	(
 		echo welcome &&
 		echo &&
@@ -468,7 +468,7 @@ test_expect_success 'signoff gap 2' '
 
 We have now
 $alt" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
+	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
 	(
 		echo welcome &&
 		echo &&
@@ -489,7 +489,7 @@ test_expect_success 'signoff respects trailer config' '
 
 non-trailer line
 Myfooter: x" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
+	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
 	(
 		echo subject &&
 		echo &&
@@ -506,7 +506,7 @@ Myfooter: x" &&
 
 non-trailer line
 Myfooter: x" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
+	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
 	(
 		echo subject &&
 		echo &&
@@ -560,14 +560,14 @@ test_expect_success 'amend commit to fix author' '
 		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
 		expected &&
 	git commit --amend --author="$author" &&
-	git cat-file -p HEAD > current &&
+	git cat-file -p HEAD >current &&
 	test_cmp expected current
 
 '
 
 test_expect_success 'git commit <file> with dirty index' '
-	echo tacocat > elif &&
-	echo tehlulz > chz &&
+	echo tacocat >elif &&
+	echo tehlulz >chz &&
 	git add chz &&
 	git commit elif -m "tacocat is a palindrome" &&
 	git show --stat | grep elif &&
-- 
2.24.0.450.g7a9a4598a9


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v2 16/21] t7501: stop losing return codes of git commands
  2019-11-21  0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                     ` (14 preceding siblings ...)
  2019-11-21  0:46   ` [PATCH v2 15/21] t7501: remove spaces after redirect operators Denton Liu
@ 2019-11-21  0:46   ` Denton Liu
  2019-11-21  0:46   ` [PATCH v2 17/21] t7700: drop redirections to /dev/null Denton Liu
                     ` (5 subsequent siblings)
  21 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-21  0:46 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

In a pipe, only the return code of the last command is used. Thus, all
other commands will have their return codes masked. Rewrite pipes so
that there are no git commands upstream so that we will know if a
command fails.

In the 'interactive add' test case, we prepend a `test_must_fail` to
`git commit --interactive`. When there are no changes to commit,
`git commit` will exit with status code 1. Following along with the rest
of the file, we use `test_must_fail` to test for this case.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7501-commit-basic-functionality.sh | 69 +++++++++++++++------------
 1 file changed, 39 insertions(+), 30 deletions(-)

diff --git a/t/t7501-commit-basic-functionality.sh b/t/t7501-commit-basic-functionality.sh
index 5765d33c53..110b4bf459 100755
--- a/t/t7501-commit-basic-functionality.sh
+++ b/t/t7501-commit-basic-functionality.sh
@@ -285,9 +285,8 @@ test_expect_success 'overriding author from command line' '
 '
 
 test_expect_success PERL 'interactive add' '
-	echo 7 |
-	git commit --interactive |
-	grep "What now"
+	echo 7 | test_must_fail git commit --interactive >out &&
+	grep "What now" out
 '
 
 test_expect_success PERL "commit --interactive doesn't change index if editor aborts" '
@@ -362,10 +361,10 @@ test_expect_success 'amend commit to fix author' '
 	oldtick=$GIT_AUTHOR_DATE &&
 	test_tick &&
 	git reset --hard &&
-	git cat-file -p HEAD |
+	git cat-file -p HEAD >commit &&
 	sed -e "s/author.*/author $author $oldtick/" \
-		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
-		expected &&
+		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" \
+		commit >expected &&
 	git commit --amend --author="$author" &&
 	git cat-file -p HEAD >current &&
 	test_cmp expected current
@@ -377,10 +376,10 @@ test_expect_success 'amend commit to fix date' '
 	test_tick &&
 	newtick=$GIT_AUTHOR_DATE &&
 	git reset --hard &&
-	git cat-file -p HEAD |
+	git cat-file -p HEAD >commit &&
 	sed -e "s/author.*/author $author $newtick/" \
-		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
-		expected &&
+		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" \
+		commit >expected &&
 	git commit --amend --date="$newtick" &&
 	git cat-file -p HEAD >current &&
 	test_cmp expected current
@@ -409,12 +408,13 @@ test_expect_success 'sign off (1)' '
 	echo 1 >positive &&
 	git add positive &&
 	git commit -s -m "thank you" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
+	git cat-file commit HEAD >commit &&
+	sed -e "1,/^\$/d" commit >actual &&
 	(
 		echo thank you &&
 		echo &&
-		git var GIT_COMMITTER_IDENT |
-		sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
+		git var GIT_COMMITTER_IDENT >ident &&
+		sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" ident
 	) >expected &&
 	test_cmp expected actual
 
@@ -428,13 +428,14 @@ test_expect_success 'sign off (2)' '
 	git commit -s -m "thank you
 
 $existing" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
+	git cat-file commit HEAD >commit &&
+	sed -e "1,/^\$/d" commit >actual &&
 	(
 		echo thank you &&
 		echo &&
 		echo $existing &&
-		git var GIT_COMMITTER_IDENT |
-		sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
+		git var GIT_COMMITTER_IDENT >ident &&
+		sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" ident
 	) >expected &&
 	test_cmp expected actual
 
@@ -448,13 +449,14 @@ test_expect_success 'signoff gap' '
 	git commit -s -m "welcome
 
 $alt" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
+	git cat-file commit HEAD >commit &&
+	sed -e "1,/^\$/d" commit >actual &&
 	(
 		echo welcome &&
 		echo &&
 		echo $alt &&
-		git var GIT_COMMITTER_IDENT |
-		sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
+		git var GIT_COMMITTER_IDENT >ident &&
+		sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" ident
 	) >expected &&
 	test_cmp expected actual
 '
@@ -468,15 +470,16 @@ test_expect_success 'signoff gap 2' '
 
 We have now
 $alt" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
+	git cat-file commit HEAD >commit &&
+	sed -e "1,/^\$/d" commit >actual &&
 	(
 		echo welcome &&
 		echo &&
 		echo We have now &&
 		echo $alt &&
 		echo &&
-		git var GIT_COMMITTER_IDENT |
-		sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
+		git var GIT_COMMITTER_IDENT >ident &&
+		sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" ident
 	) >expected &&
 	test_cmp expected actual
 '
@@ -489,7 +492,8 @@ test_expect_success 'signoff respects trailer config' '
 
 non-trailer line
 Myfooter: x" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
+	git cat-file commit HEAD >commit &&
+	sed -e "1,/^\$/d" commit >actual &&
 	(
 		echo subject &&
 		echo &&
@@ -506,7 +510,8 @@ Myfooter: x" &&
 
 non-trailer line
 Myfooter: x" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
+	git cat-file commit HEAD >commit &&
+	sed -e "1,/^\$/d" commit >actual &&
 	(
 		echo subject &&
 		echo &&
@@ -538,7 +543,8 @@ test_expect_success 'multiple -m' '
 	>negative &&
 	git add negative &&
 	git commit -m "one" -m "two" -m "three" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
+	git cat-file commit HEAD >commit &&
+	sed -e "1,/^\$/d" commit >actual &&
 	(
 		echo one &&
 		echo &&
@@ -555,10 +561,10 @@ test_expect_success 'amend commit to fix author' '
 	oldtick=$GIT_AUTHOR_DATE &&
 	test_tick &&
 	git reset --hard &&
-	git cat-file -p HEAD |
+	git cat-file -p HEAD >commit &&
 	sed -e "s/author.*/author $author $oldtick/" \
-		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
-		expected &&
+		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" \
+		commit >expected &&
 	git commit --amend --author="$author" &&
 	git cat-file -p HEAD >current &&
 	test_cmp expected current
@@ -570,8 +576,10 @@ test_expect_success 'git commit <file> with dirty index' '
 	echo tehlulz >chz &&
 	git add chz &&
 	git commit elif -m "tacocat is a palindrome" &&
-	git show --stat | grep elif &&
-	git diff --cached | grep chz
+	git show --stat >stat &&
+	grep elif stat &&
+	git diff --cached >diff &&
+	grep chz diff
 '
 
 test_expect_success 'same tree (single parent)' '
@@ -584,7 +592,8 @@ test_expect_success 'same tree (single parent)' '
 test_expect_success 'same tree (single parent) --allow-empty' '
 
 	git commit --allow-empty -m "forced empty" &&
-	git cat-file commit HEAD | grep forced
+	git cat-file commit HEAD >commit &&
+	grep forced commit
 
 '
 
-- 
2.24.0.450.g7a9a4598a9


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v2 17/21] t7700: drop redirections to /dev/null
  2019-11-21  0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                     ` (15 preceding siblings ...)
  2019-11-21  0:46   ` [PATCH v2 16/21] t7501: stop losing return codes of git commands Denton Liu
@ 2019-11-21  0:46   ` Denton Liu
  2019-11-21  0:46   ` [PATCH v2 18/21] t7700: remove spaces after redirect operators Denton Liu
                     ` (4 subsequent siblings)
  21 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-21  0:46 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Since output is silenced when running without `-v` and debugging output
is useful with `-v`, remove redirections to /dev/null as it is not
useful.

In one case where the output of stdout is consumed, redirect the output
of test_commit to stderr.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7700-repack.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index 4e855bc21b..e1a689d6a9 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -5,7 +5,7 @@ test_description='git repack works correctly'
 . ./test-lib.sh
 
 commit_and_pack() {
-	test_commit "$@" >/dev/null &&
+	test_commit "$@" 1>&2 &&
 	SHA1=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) &&
 	echo pack-${SHA1}.pack
 }
@@ -19,7 +19,7 @@ test_expect_success 'objects in packs marked .keep are not repacked' '
 	# Create two packs
 	# The first pack will contain all of the objects except one
 	git rev-list --objects --all | grep -v file2 |
-		git pack-objects pack > /dev/null &&
+		git pack-objects pack &&
 	# The second pack will contain the excluded object
 	packsha1=$(git rev-list --objects --all | grep file2 |
 		git pack-objects pack) &&
@@ -235,7 +235,7 @@ test_expect_success 'incremental repack does not complain' '
 
 test_expect_success 'bitmaps can be disabled on bare repos' '
 	git -c repack.writeBitmaps=false -C bare.git repack -ad &&
-	bitmap=$(ls bare.git/objects/pack/*.bitmap 2>/dev/null || :) &&
+	bitmap=$(ls bare.git/objects/pack/*.bitmap || :) &&
 	test -z "$bitmap"
 '
 
-- 
2.24.0.450.g7a9a4598a9


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v2 18/21] t7700: remove spaces after redirect operators
  2019-11-21  0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                     ` (16 preceding siblings ...)
  2019-11-21  0:46   ` [PATCH v2 17/21] t7700: drop redirections to /dev/null Denton Liu
@ 2019-11-21  0:46   ` Denton Liu
  2019-11-21  0:46   ` [PATCH v2 19/21] t7700: move keywords onto their own line Denton Liu
                     ` (3 subsequent siblings)
  21 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-21  0:46 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

For shell scripts, the usual convention is for there to be no space
after redirection operators, (e.g. `>file`, not `> file`). Remove these
spaces wherever they appear.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7700-repack.sh | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index e1a689d6a9..8936928387 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -11,8 +11,8 @@ commit_and_pack() {
 }
 
 test_expect_success 'objects in packs marked .keep are not repacked' '
-	echo content1 > file1 &&
-	echo content2 > file2 &&
+	echo content1 >file1 &&
+	echo content2 >file2 &&
 	git add . &&
 	test_tick &&
 	git commit -m initial_commit &&
@@ -75,8 +75,8 @@ test_expect_success 'writing bitmaps via config can duplicate .keep objects' '
 
 test_expect_success 'loose objects in alternate ODB are not repacked' '
 	mkdir alt_objects &&
-	echo $(pwd)/alt_objects > .git/objects/info/alternates &&
-	echo content3 > file3 &&
+	echo $(pwd)/alt_objects >.git/objects/info/alternates &&
+	echo content3 >file3 &&
 	objsha1=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) &&
 	git add file3 &&
 	test_tick &&
@@ -111,7 +111,7 @@ test_expect_success 'packed obs in alt ODB are repacked even when local repo is
 
 test_expect_success 'packed obs in alt ODB are repacked when local repo has packs' '
 	rm -f .git/objects/pack/* &&
-	echo new_content >> file1 &&
+	echo new_content >>file1 &&
 	git add file1 &&
 	test_tick &&
 	git commit -m more_content &&
@@ -169,12 +169,12 @@ test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
 	mv pack-* .git/objects/pack/ &&
 	test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
 		egrep "^$csha1 " | sort | uniq | wc -l) &&
-	echo > .git/objects/info/alternates &&
+	echo >.git/objects/info/alternates &&
 	test_must_fail git show $csha1
 '
 
 test_expect_success 'local packed unreachable obs that exist in alternate ODB are not loosened' '
-	echo $(pwd)/alt_objects > .git/objects/info/alternates &&
+	echo $(pwd)/alt_objects >.git/objects/info/alternates &&
 	echo "$csha1" | git pack-objects --non-empty --all --reflog pack &&
 	rm -f .git/objects/pack/* &&
 	mv pack-* .git/objects/pack/ &&
@@ -186,7 +186,7 @@ test_expect_success 'local packed unreachable obs that exist in alternate ODB ar
 	mv pack-* .git/objects/pack/ &&
 	test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
 		egrep "^$csha1 " | sort | uniq | wc -l) &&
-	echo > .git/objects/info/alternates &&
+	echo >.git/objects/info/alternates &&
 	test_must_fail git show $csha1
 '
 
@@ -196,7 +196,7 @@ test_expect_success 'objects made unreachable by grafts only are kept' '
 	H0=$(git rev-parse HEAD) &&
 	H1=$(git rev-parse HEAD^) &&
 	H2=$(git rev-parse HEAD^^) &&
-	echo "$H0 $H2" > .git/info/grafts &&
+	echo "$H0 $H2" >.git/info/grafts &&
 	git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all &&
 	git repack -a -d &&
 	git cat-file -t $H1
-- 
2.24.0.450.g7a9a4598a9


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v2 19/21] t7700: move keywords onto their own line
  2019-11-21  0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                     ` (17 preceding siblings ...)
  2019-11-21  0:46   ` [PATCH v2 18/21] t7700: remove spaces after redirect operators Denton Liu
@ 2019-11-21  0:46   ` Denton Liu
  2019-11-21  0:46   ` [PATCH v2 20/21] t7700: s/test -f/test_path_is_file/ Denton Liu
                     ` (2 subsequent siblings)
  21 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-21  0:46 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

The code style for tests is to have statements on their own line if
possible. Move keywords onto their own line so that they conform with
the test style.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7700-repack.sh | 51 +++++++++++++++++++++++++++++++----------------
 1 file changed, 34 insertions(+), 17 deletions(-)

diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index 8936928387..a96e876c4e 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -29,10 +29,12 @@ test_expect_success 'objects in packs marked .keep are not repacked' '
 	mv pack-* .git/objects/pack/ &&
 	git repack -A -d -l &&
 	git prune-packed &&
-	for p in .git/objects/pack/*.idx; do
+	for p in .git/objects/pack/*.idx
+	do
 		idx=$(basename $p)
 		test "pack-$packsha1.idx" = "$idx" && continue
-		if git verify-pack -v $p | egrep "^$objsha1"; then
+		if git verify-pack -v $p | egrep "^$objsha1"
+		then
 			found_duplicate_object=1
 			echo "DUPLICATE OBJECT FOUND"
 			break
@@ -45,10 +47,12 @@ test_expect_success 'writing bitmaps via command-line can duplicate .keep object
 	# build on $objsha1, $packsha1, and .keep state from previous
 	git repack -Adbl &&
 	test_when_finished "found_duplicate_object=" &&
-	for p in .git/objects/pack/*.idx; do
+	for p in .git/objects/pack/*.idx
+	do
 		idx=$(basename $p)
 		test "pack-$packsha1.idx" = "$idx" && continue
-		if git verify-pack -v $p | egrep "^$objsha1"; then
+		if git verify-pack -v $p | egrep "^$objsha1"
+		then
 			found_duplicate_object=1
 			echo "DUPLICATE OBJECT FOUND"
 			break
@@ -61,10 +65,12 @@ test_expect_success 'writing bitmaps via config can duplicate .keep objects' '
 	# build on $objsha1, $packsha1, and .keep state from previous
 	git -c repack.writebitmaps=true repack -Adl &&
 	test_when_finished "found_duplicate_object=" &&
-	for p in .git/objects/pack/*.idx; do
+	for p in .git/objects/pack/*.idx
+	do
 		idx=$(basename $p)
 		test "pack-$packsha1.idx" = "$idx" && continue
-		if git verify-pack -v $p | egrep "^$objsha1"; then
+		if git verify-pack -v $p | egrep "^$objsha1"
+		then
 			found_duplicate_object=1
 			echo "DUPLICATE OBJECT FOUND"
 			break
@@ -83,8 +89,10 @@ test_expect_success 'loose objects in alternate ODB are not repacked' '
 	git commit -m commit_file3 &&
 	git repack -a -d -l &&
 	git prune-packed &&
-	for p in .git/objects/pack/*.idx; do
-		if git verify-pack -v $p | egrep "^$objsha1"; then
+	for p in .git/objects/pack/*.idx
+	do
+		if git verify-pack -v $p | egrep "^$objsha1"
+		then
 			found_duplicate_object=1
 			echo "DUPLICATE OBJECT FOUND"
 			break
@@ -99,10 +107,13 @@ test_expect_success 'packed obs in alt ODB are repacked even when local repo is
 	git repack -a &&
 	myidx=$(ls -1 .git/objects/pack/*.idx) &&
 	test -f "$myidx" &&
-	for p in alt_objects/pack/*.idx; do
+	for p in alt_objects/pack/*.idx
+	do
 		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
-	done | while read sha1 rest; do
-		if ! ( git verify-pack -v $myidx | grep "^$sha1" ); then
+	done | while read sha1 rest
+	do
+		if ! ( git verify-pack -v $myidx | grep "^$sha1" )
+		then
 			echo "Missing object in local pack: $sha1"
 			return 1
 		fi
@@ -119,10 +130,13 @@ test_expect_success 'packed obs in alt ODB are repacked when local repo has pack
 	git repack -a -d &&
 	myidx=$(ls -1 .git/objects/pack/*.idx) &&
 	test -f "$myidx" &&
-	for p in alt_objects/pack/*.idx; do
+	for p in alt_objects/pack/*.idx
+	do
 		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
-	done | while read sha1 rest; do
-		if ! ( git verify-pack -v $myidx | grep "^$sha1" ); then
+	done | while read sha1 rest
+	do
+		if ! ( git verify-pack -v $myidx | grep "^$sha1" )
+		then
 			echo "Missing object in local pack: $sha1"
 			return 1
 		fi
@@ -144,10 +158,13 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
 	git repack -a -d &&
 	myidx=$(ls -1 .git/objects/pack/*.idx) &&
 	test -f "$myidx" &&
-	for p in alt_objects/pack/*.idx; do
+	for p in alt_objects/pack/*.idx
+	do
 		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
-	done | while read sha1 rest; do
-		if ! ( git verify-pack -v $myidx | grep "^$sha1" ); then
+	done | while read sha1 rest
+	do
+		if ! ( git verify-pack -v $myidx | grep "^$sha1" )
+		then
 			echo "Missing object in local pack: $sha1"
 			return 1
 		fi
-- 
2.24.0.450.g7a9a4598a9


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v2 20/21] t7700: s/test -f/test_path_is_file/
  2019-11-21  0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                     ` (18 preceding siblings ...)
  2019-11-21  0:46   ` [PATCH v2 19/21] t7700: move keywords onto their own line Denton Liu
@ 2019-11-21  0:46   ` Denton Liu
  2019-11-21  0:46   ` [PATCH v2 21/21] t7700: stop losing return codes of git commands Denton Liu
  2019-11-22 18:59   ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
  21 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-21  0:46 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Since we have debugging-friendly alternatives to `test -f`, replace
instances of `test -f` with `test_path_is_file` so that if a command
ever fails, we get better debugging information.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7700-repack.sh | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index a96e876c4e..1d14ddcbdb 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -106,7 +106,7 @@ test_expect_success 'packed obs in alt ODB are repacked even when local repo is
 	mv .git/objects/pack/* alt_objects/pack &&
 	git repack -a &&
 	myidx=$(ls -1 .git/objects/pack/*.idx) &&
-	test -f "$myidx" &&
+	test_path_is_file "$myidx" &&
 	for p in alt_objects/pack/*.idx
 	do
 		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
@@ -129,7 +129,7 @@ test_expect_success 'packed obs in alt ODB are repacked when local repo has pack
 	git repack &&
 	git repack -a -d &&
 	myidx=$(ls -1 .git/objects/pack/*.idx) &&
-	test -f "$myidx" &&
+	test_path_is_file "$myidx" &&
 	for p in alt_objects/pack/*.idx
 	do
 		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
@@ -148,7 +148,7 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
 	for p in alt_objects/pack/*.pack
 	do
 		base_name=$(basename $p .pack) &&
-		if test -f alt_objects/pack/$base_name.keep
+		if test_path_is_file alt_objects/pack/$base_name.keep
 		then
 			rm alt_objects/pack/$base_name.keep
 		else
@@ -157,7 +157,7 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
 	done &&
 	git repack -a -d &&
 	myidx=$(ls -1 .git/objects/pack/*.idx) &&
-	test -f "$myidx" &&
+	test_path_is_file "$myidx" &&
 	for p in alt_objects/pack/*.idx
 	do
 		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
-- 
2.24.0.450.g7a9a4598a9


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v2 21/21] t7700: stop losing return codes of git commands
  2019-11-21  0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                     ` (19 preceding siblings ...)
  2019-11-21  0:46   ` [PATCH v2 20/21] t7700: s/test -f/test_path_is_file/ Denton Liu
@ 2019-11-21  0:46   ` Denton Liu
  2019-11-22 18:59   ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
  21 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-21  0:46 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

In a pipe, only the return code of the last command is used. Thus, all
other commands will have their return codes masked. Rewrite pipes so
that there are no git commands upstream so that we will know if a
command fails.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7700-repack.sh | 64 ++++++++++++++++++++++++++++-------------------
 1 file changed, 38 insertions(+), 26 deletions(-)

diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index 1d14ddcbdb..ff50722e26 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -18,14 +18,13 @@ test_expect_success 'objects in packs marked .keep are not repacked' '
 	git commit -m initial_commit &&
 	# Create two packs
 	# The first pack will contain all of the objects except one
-	git rev-list --objects --all | grep -v file2 |
-		git pack-objects pack &&
+	git rev-list --objects --all >objs &&
+	grep -v file2 objs | git pack-objects pack &&
 	# The second pack will contain the excluded object
-	packsha1=$(git rev-list --objects --all | grep file2 |
-		git pack-objects pack) &&
+	packsha1=$(grep file2 objs | git pack-objects pack) &&
 	>pack-$packsha1.keep &&
-	objsha1=$(git verify-pack -v pack-$packsha1.idx | head -n 1 |
-		sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") &&
+	git verify-pack -v pack-$packsha1.idx >packlist &&
+	objsha1=$(head -n 1 packlist | sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") &&
 	mv pack-* .git/objects/pack/ &&
 	git repack -A -d -l &&
 	git prune-packed &&
@@ -33,7 +32,8 @@ test_expect_success 'objects in packs marked .keep are not repacked' '
 	do
 		idx=$(basename $p)
 		test "pack-$packsha1.idx" = "$idx" && continue
-		if git verify-pack -v $p | egrep "^$objsha1"
+		git verify-pack -v $p >packlist || return $?
+		if egrep "^$objsha1" packlist
 		then
 			found_duplicate_object=1
 			echo "DUPLICATE OBJECT FOUND"
@@ -51,7 +51,8 @@ test_expect_success 'writing bitmaps via command-line can duplicate .keep object
 	do
 		idx=$(basename $p)
 		test "pack-$packsha1.idx" = "$idx" && continue
-		if git verify-pack -v $p | egrep "^$objsha1"
+		git verify-pack -v $p >packlist || return $?
+		if egrep "^$objsha1" packlist
 		then
 			found_duplicate_object=1
 			echo "DUPLICATE OBJECT FOUND"
@@ -69,7 +70,8 @@ test_expect_success 'writing bitmaps via config can duplicate .keep objects' '
 	do
 		idx=$(basename $p)
 		test "pack-$packsha1.idx" = "$idx" && continue
-		if git verify-pack -v $p | egrep "^$objsha1"
+		git verify-pack -v $p >packlist || return $?
+		if egrep "^$objsha1" packlist
 		then
 			found_duplicate_object=1
 			echo "DUPLICATE OBJECT FOUND"
@@ -91,7 +93,8 @@ test_expect_success 'loose objects in alternate ODB are not repacked' '
 	git prune-packed &&
 	for p in .git/objects/pack/*.idx
 	do
-		if git verify-pack -v $p | egrep "^$objsha1"
+		git verify-pack -v $p >packlist || return $?
+		if egrep "^$objsha1" packlist
 		then
 			found_duplicate_object=1
 			echo "DUPLICATE OBJECT FOUND"
@@ -109,15 +112,18 @@ test_expect_success 'packed obs in alt ODB are repacked even when local repo is
 	test_path_is_file "$myidx" &&
 	for p in alt_objects/pack/*.idx
 	do
-		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
-	done | while read sha1 rest
+		git verify-pack -v $p >packlist || return $?
+		sed -n -e "/^[0-9a-f]\{40\}/p"
+	done >packs &&
+	git verify-pack -v $myidx >mypacklist &&
+	while read sha1 rest
 	do
-		if ! ( git verify-pack -v $myidx | grep "^$sha1" )
+		if ! grep "^$sha1" mypacklist
 		then
 			echo "Missing object in local pack: $sha1"
 			return 1
 		fi
-	done
+	done <packs
 '
 
 test_expect_success 'packed obs in alt ODB are repacked when local repo has packs' '
@@ -132,15 +138,18 @@ test_expect_success 'packed obs in alt ODB are repacked when local repo has pack
 	test_path_is_file "$myidx" &&
 	for p in alt_objects/pack/*.idx
 	do
-		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
-	done | while read sha1 rest
+		git verify-pack -v $p >packlist || return $?
+		sed -n -e "/^[0-9a-f]\{40\}/p" packlist
+	done >packs &&
+	git verify-pack -v $myidx >mypacklist &&
+	while read sha1 rest
 	do
-		if ! ( git verify-pack -v $myidx | grep "^$sha1" )
+		if ! grep "^$sha1" mypacklist
 		then
 			echo "Missing object in local pack: $sha1"
 			return 1
 		fi
-	done
+	done <packs
 '
 
 test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
@@ -160,15 +169,18 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
 	test_path_is_file "$myidx" &&
 	for p in alt_objects/pack/*.idx
 	do
-		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
-	done | while read sha1 rest
+		git verify-pack -v $p >packlist || return $?
+		sed -n -e "/^[0-9a-f]\{40\}/p" packlist
+	done >packs &&
+	git verify-pack -v $myidx >mypacklist &&
+	while read sha1 rest
 	do
-		if ! ( git verify-pack -v $myidx | grep "^$sha1" )
+		if ! grep "^$sha1" mypacklist
 		then
 			echo "Missing object in local pack: $sha1"
 			return 1
 		fi
-	done
+	done <packs
 '
 
 test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
@@ -184,8 +196,8 @@ test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
 	    --unpack-unreachable </dev/null pack &&
 	rm -f .git/objects/pack/* &&
 	mv pack-* .git/objects/pack/ &&
-	test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
-		egrep "^$csha1 " | sort | uniq | wc -l) &&
+	git verify-pack -v -- .git/objects/pack/*.idx >packlist &&
+	! egrep "^$csha1 " packlist &&
 	echo >.git/objects/info/alternates &&
 	test_must_fail git show $csha1
 '
@@ -201,8 +213,8 @@ test_expect_success 'local packed unreachable obs that exist in alternate ODB ar
 	    --unpack-unreachable </dev/null pack &&
 	rm -f .git/objects/pack/* &&
 	mv pack-* .git/objects/pack/ &&
-	test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
-		egrep "^$csha1 " | sort | uniq | wc -l) &&
+	git verify-pack -v -- .git/objects/pack/*.idx >packlist &&
+	! egrep "^$csha1 " &&
 	echo >.git/objects/info/alternates &&
 	test_must_fail git show $csha1
 '
-- 
2.24.0.450.g7a9a4598a9


^ permalink raw reply	[flat|nested] 169+ messages in thread

* Re: [PATCH v2 12/21] t5317: use ! grep to check for no matching lines
  2019-11-21  0:46   ` [PATCH v2 12/21] t5317: use ! grep to check for no matching lines Denton Liu
@ 2019-11-21 12:59     ` Eric Sunshine
  0 siblings, 0 replies; 169+ messages in thread
From: Eric Sunshine @ 2019-11-21 12:59 UTC (permalink / raw)
  To: Denton Liu; +Cc: Git Mailing List, Junio C Hamano, Jeff King

On Wed, Nov 20, 2019 at 7:46 PM Denton Liu <liu.denton@gmail.com> wrote:
> Several times in t5317, we would use `wc -l` to ensure that a grep
> result is empty. However, grep already has a way to do that... Its
> return code! Use `! grep` in the cases where we are ensuring that there
> are no matching lines.
>
> It turns out that these tests were simply born this way[1], doing all
> this unnecessary work for no reason, probably due to copy/paste
> programming, and it seems no reviewer caught it. Likewise, the
> unnecessary work wasn't noticed even when the code was later touched
> for various cleanups[2,3].
>
> Signed-off-by: Denton Liu <liu.denton@gmail.com>
> ---
>     Thanks for your help, Eric. I shamelessly stole your message text for
>     the commit message.

That's fine, but you ought to amend it a bit since it makes no sense
when extracted verbatim from my longer review comment which provided
needed context. In particular, the bit:

    ...doing all this unnecessary work for no reason...

is confusing since the reader doesn't know what "this unnecessary
work" is. My review email had an entire preceding paragraph that
provided context. It should at least be amended to say something along
the lines of:

    While at it, drop unnecessary invocations of 'awk' and 'sort' in
    each affected test since those commands do not influence the
    outcome. It's not clear why that extra work was being done in the
    first place, and the code's history doesn't shed any light on the
    matter since these tests were simply born this way[1], doing all
    the unnecessary work for no reason, probably due to copy/paste
    programming...

^ permalink raw reply	[flat|nested] 169+ messages in thread

* Re: [PATCH v2 13/21] t5703: simplify one-time-sed generation logic
  2019-11-21  0:46   ` [PATCH v2 13/21] t5703: simplify one-time-sed generation logic Denton Liu
@ 2019-11-21 13:12     ` Eric Sunshine
  2019-11-21 23:22       ` Denton Liu
  0 siblings, 1 reply; 169+ messages in thread
From: Eric Sunshine @ 2019-11-21 13:12 UTC (permalink / raw)
  To: Denton Liu; +Cc: Git Mailing List, Junio C Hamano, Jeff King

On Wed, Nov 20, 2019 at 7:46 PM Denton Liu <liu.denton@gmail.com> wrote:
> In inconsistency(), we had two `git rev-parse` invocations in the
> upstream of a pipe within a command substitution. In case this
> invocation ever failed, its exit code would be swallowed up and we would
> not know about it.
>
> Pull the command substitutions out into variable assignments so that
> their return codes are not lost.
>
> Drop the pipe into tr because command substitutions should already strip
> leading and trailing whitespace, including newlines.

Saying that command substitution _should_ strip the whitespace leaves
the reader in doubt as to whether there are situations in which it
might or might not do so. More accurately, command substitution _does_
strip the whitespace, so please drop "should" from this sentence
altogether.

> Finally, convert the printf into an echo because it isn't necessary
> anymore.

This is quite misleading. 'printf' was _never_ necessary; 'echo' was
an appropriate alternative even before the other changes made by this
patch. Worse, though, this sentence provides no context about _why_ it
is safe to change 'printf' to 'echo', so the reader is left with even
more questions trying to understand the validity of this change than
if you had merely omitted this sentence. My review email[1] provided
exact reasoning about why this change is safe. Paraphrasing that
explanation for this patch's commit message would go a long way toward
convincing the reader that the change makes sense.

[1]: https://lore.kernel.org/git/CAPig+cTj5qOCFRoD4cZOg7BjVvetQWTgdRHzSvAfgtX2YgUXPg@mail.gmail.com/

^ permalink raw reply	[flat|nested] 169+ messages in thread

* Re: [PATCH v2 13/21] t5703: simplify one-time-sed generation logic
  2019-11-21 13:12     ` Eric Sunshine
@ 2019-11-21 23:22       ` Denton Liu
  0 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-21 23:22 UTC (permalink / raw)
  To: Eric Sunshine; +Cc: Git Mailing List, Junio C Hamano, Jeff King

Hi Eric,

On Thu, Nov 21, 2019 at 08:12:00AM -0500, Eric Sunshine wrote:
> On Wed, Nov 20, 2019 at 7:46 PM Denton Liu <liu.denton@gmail.com> wrote:
> > In inconsistency(), we had two `git rev-parse` invocations in the
> > upstream of a pipe within a command substitution. In case this
> > invocation ever failed, its exit code would be swallowed up and we would
> > not know about it.
> >
> > Pull the command substitutions out into variable assignments so that
> > their return codes are not lost.
> >
> > Drop the pipe into tr because command substitutions should already strip
> > leading and trailing whitespace, including newlines.
> 
> Saying that command substitution _should_ strip the whitespace leaves
> the reader in doubt as to whether there are situations in which it
> might or might not do so. More accurately, command substitution _does_
> strip the whitespace, so please drop "should" from this sentence
> altogether.

Good point. I think in general, I have a very passive writing style so
I'll make a note to write my commit messages more assertively.

> 
> > Finally, convert the printf into an echo because it isn't necessary
> > anymore.
> 
> This is quite misleading. 'printf' was _never_ necessary; 'echo' was
> an appropriate alternative even before the other changes made by this
> patch. Worse, though, this sentence provides no context about _why_ it
> is safe to change 'printf' to 'echo', so the reader is left with even
> more questions trying to understand the validity of this change than
> if you had merely omitted this sentence. My review email[1] provided
> exact reasoning about why this change is safe. Paraphrasing that
> explanation for this patch's commit message would go a long way toward
> convincing the reader that the change makes sense.

Will do.

Thanks,

Denton

> 
> [1]: https://lore.kernel.org/git/CAPig+cTj5qOCFRoD4cZOg7BjVvetQWTgdRHzSvAfgtX2YgUXPg@mail.gmail.com/

^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail
  2019-11-21  0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                     ` (20 preceding siblings ...)
  2019-11-21  0:46   ` [PATCH v2 21/21] t7700: stop losing return codes of git commands Denton Liu
@ 2019-11-22 18:59   ` Denton Liu
  2019-11-22 18:59     ` [PATCH v3 01/22] lib-bash.sh: move `then` onto its own line Denton Liu
                       ` (22 more replies)
  21 siblings, 23 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-22 18:59 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

These patches perform some general test cleanup to modernise the style.
They should be relatively uncontroversial. The reason these tests were
identified for cleanup was because they failed under `set -o pipefail`.

I've gotten rid of the RFC part that actually enables `set -o pipefail`
on supported platforms. As Peff pointed out, there are a lot of
opportunities for racy SIGPIPE failures so that part still needs a lot
of work to be ironed out.

Those changes shouldn't hold back the first part of the series, however.
Let's try to get this test cleanup merged in sooner than later so that
any new test cases done by copy-paste will have their changes
represented.

Changes since v1:

* Removed the `set -o pipefail` changes

* Addressed Junio and Eric's comments on the first part of the series

Denton Liu (22):
  lib-bash.sh: move `then` onto its own line
  apply-one-time-sed.sh: modernize style
  t0014: remove git command upstream of pipe
  t0090: stop losing return codes of git commands
  t3301: stop losing return codes of git commands
  t3600: use test_line_count() where possible
  t3600: stop losing return codes of git commands
  t3600: comment on inducing SIGPIPE in `git rm`
  t4015: stop losing return codes of git commands
  t4015: use test_write_lines()
  t4138: stop losing return codes of git commands
  t5317: stop losing return codes of git commands
  t5317: use ! grep to check for no matching lines
  t5703: simplify one-time-sed generation logic
  t5703: stop losing return codes of git commands
  t7501: remove spaces after redirect operators
  t7501: stop losing return codes of git commands
  t7700: drop redirections to /dev/null
  t7700: remove spaces after redirect operators
  t7700: move keywords onto their own line
  t7700: s/test -f/test_path_is_file/
  t7700: stop losing return codes of git commands

 t/lib-bash.sh                          |   6 +-
 t/lib-httpd/apply-one-time-sed.sh      |   8 +-
 t/t0014-alias.sh                       |   4 +-
 t/t0090-cache-tree.sh                  |   5 +-
 t/t3301-notes.sh                       | 230 ++++++++++++++++++-------
 t/t3600-rm.sh                          |  14 +-
 t/t4015-diff-whitespace.sh             | 123 +++++++------
 t/t4138-apply-ws-expansion.sh          |  16 +-
 t/t5317-pack-objects-filter-objects.sh |  34 ++--
 t/t5703-upload-pack-ref-in-want.sh     |  53 +++---
 t/t7501-commit-basic-functionality.sh  |  83 +++++----
 t/t7700-repack.sh                      | 125 ++++++++------
 12 files changed, 433 insertions(+), 268 deletions(-)

Range-diff against v2:
 1:  9085cc00af =  1:  9085cc00af lib-bash.sh: move `then` onto its own line
 -:  ---------- >  2:  1fddaab701 apply-one-time-sed.sh: modernize style
 2:  9ec5244905 =  3:  f69e5345ba t0014: remove git command upstream of pipe
 3:  613a58491a =  4:  28ddc6c79d t0090: stop losing return codes of git commands
 4:  ee40bc972f =  5:  4d5f868e50 t3301: stop losing return codes of git commands
 5:  702a25f328 =  6:  658db8866e t3600: use test_line_count() where possible
 6:  6ebfed9234 =  7:  a7d76f9cb9 t3600: stop losing return codes of git commands
 7:  7ca9099fa7 =  8:  d35c054344 t3600: comment on inducing SIGPIPE in `git rm`
 8:  64ecf82b94 =  9:  bd6f6487b9 t4015: stop losing return codes of git commands
 9:  8d1f457d19 = 10:  6993316839 t4015: use test_write_lines()
10:  0a843a25c8 = 11:  5e88c755ed t4138: stop losing return codes of git commands
11:  4ace91a8b9 = 12:  56eebcc249 t5317: stop losing return codes of git commands
12:  7a15dd95f8 ! 13:  85c2f8ca27 t5317: use ! grep to check for no matching lines
    @@ Commit message
         return code! Use `! grep` in the cases where we are ensuring that there
         are no matching lines.
     
    -    It turns out that these tests were simply born this way[1], doing all
    -    this unnecessary work for no reason, probably due to copy/paste
    -    programming, and it seems no reviewer caught it. Likewise, the
    -    unnecessary work wasn't noticed even when the code was later touched
    -    for various cleanups[2,3].
    +    While at it, drop unnecessary invocations of 'awk' and 'sort' in each
    +    affected test since those commands do not influence the outcome. It's
    +    not clear why that extra work was being done in the first place, and the
    +    code's history doesn't shed any light on the matter since these tests
    +    were simply born this way[1], doing all the unnecessary work for no
    +    reason, probably due to copy/paste programming...
     
         [1]: 9535ce7337 (pack-objects: add list-objects filtering, 2017-11-21)
    -    [2]: bdbc17e86a (tests: standardize pipe placement, 2018-10-05)
    -    [3]: 61de0ff695 (tests: don't swallow Git errors upstream of pipes, 2018-10-05)
     
         Helped-by: Eric Sunshine <sunshine@sunshineco.com>
     
13:  439994027d ! 14:  f7e8ae79fa t5703: simplify one-time-sed generation logic
    @@ Commit message
         Pull the command substitutions out into variable assignments so that
         their return codes are not lost.
     
    -    Drop the pipe into tr because command substitutions should already strip
    -    leading and trailing whitespace, including newlines.
    +    Drop the pipe into `tr` because the $(...) substitution already takes
    +    care of stripping out newlines, so the `tr` invocations in the code are
    +    superfluous.
     
    -    Finally, convert the printf into an echo because it isn't necessary
    -    anymore.
    +    Finally, given the way the tests actually employ "one-time-sed" via
    +    $(cat one-time-sed) in t/lib-httpd/apply-one-time-sed.sh, convert the
    +    `printf` into an `echo`. This makes it consistent with the final "server
    +    loses a ref - ref in want" test, which does use `echo` rather than
    +    `printf`.
    +
    +    Helped-by: Eric Sunshine <sunshine@sunshineco.com>
     
      ## t/t5703-upload-pack-ref-in-want.sh ##
     @@ t/t5703-upload-pack-ref-in-want.sh: inconsistency () {
14:  859328b168 = 15:  28ef8f3a59 t5703: stop losing return codes of git commands
15:  d5e5be76c2 = 16:  0824965707 t7501: remove spaces after redirect operators
16:  d4154e621d = 17:  5058d21880 t7501: stop losing return codes of git commands
17:  2045c6e30e = 18:  297f383897 t7700: drop redirections to /dev/null
18:  20563779ee = 19:  2521ade74d t7700: remove spaces after redirect operators
19:  37a6d826bc = 20:  560f618334 t7700: move keywords onto their own line
20:  ea4338a43a = 21:  bd27805e4b t7700: s/test -f/test_path_is_file/
21:  98aec252fc = 22:  e9835b8542 t7700: stop losing return codes of git commands
-- 
2.24.0.497.g17aadd8971


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v3 01/22] lib-bash.sh: move `then` onto its own line
  2019-11-22 18:59   ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
@ 2019-11-22 18:59     ` Denton Liu
  2019-11-22 18:59     ` [PATCH v3 02/22] apply-one-time-sed.sh: modernize style Denton Liu
                       ` (21 subsequent siblings)
  22 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-22 18:59 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

The code style for tests is to have statements on their own line if
possible. Move the `then` onto its own line so that it conforms with the
test style.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/lib-bash.sh | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/t/lib-bash.sh b/t/lib-bash.sh
index 2be955fafb..b0b6060929 100644
--- a/t/lib-bash.sh
+++ b/t/lib-bash.sh
@@ -2,10 +2,12 @@
 # to run under Bash; primarily intended for tests of the completion
 # script.
 
-if test -n "$BASH" && test -z "$POSIXLY_CORRECT"; then
+if test -n "$BASH" && test -z "$POSIXLY_CORRECT"
+then
 	# we are in full-on bash mode
 	true
-elif type bash >/dev/null 2>&1; then
+elif type bash >/dev/null 2>&1
+then
 	# execute in full-on bash mode
 	unset POSIXLY_CORRECT
 	exec bash "$0" "$@"
-- 
2.24.0.497.g17aadd8971


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v3 02/22] apply-one-time-sed.sh: modernize style
  2019-11-22 18:59   ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
  2019-11-22 18:59     ` [PATCH v3 01/22] lib-bash.sh: move `then` onto its own line Denton Liu
@ 2019-11-22 18:59     ` Denton Liu
  2019-11-23  1:32       ` Junio C Hamano
  2019-11-22 18:59     ` [PATCH v3 03/22] t0014: remove git command upstream of pipe Denton Liu
                       ` (20 subsequent siblings)
  22 siblings, 1 reply; 169+ messages in thread
From: Denton Liu @ 2019-11-22 18:59 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Convert `[ ... ]` to use `test`.

Move the `then`s onto their own lines so that it conforms with the
general test style.

Instead of redirecting input into sed, allow it to open its own input.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/lib-httpd/apply-one-time-sed.sh | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/t/lib-httpd/apply-one-time-sed.sh b/t/lib-httpd/apply-one-time-sed.sh
index fcef728925..3e9a615311 100644
--- a/t/lib-httpd/apply-one-time-sed.sh
+++ b/t/lib-httpd/apply-one-time-sed.sh
@@ -7,11 +7,13 @@
 #
 # This can be used to simulate the effects of the repository changing in
 # between HTTP request-response pairs.
-if [ -e one-time-sed ]; then
+if test -e one-time-sed
+then
 	"$GIT_EXEC_PATH/git-http-backend" >out
-	sed "$(cat one-time-sed)" <out >out_modified
+	sed "$(cat one-time-sed)" out >out_modified
 
-	if diff out out_modified >/dev/null; then
+	if diff out out_modified >/dev/null
+	then
 		cat out
 	else
 		cat out_modified
-- 
2.24.0.497.g17aadd8971


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v3 03/22] t0014: remove git command upstream of pipe
  2019-11-22 18:59   ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
  2019-11-22 18:59     ` [PATCH v3 01/22] lib-bash.sh: move `then` onto its own line Denton Liu
  2019-11-22 18:59     ` [PATCH v3 02/22] apply-one-time-sed.sh: modernize style Denton Liu
@ 2019-11-22 18:59     ` Denton Liu
  2019-11-22 18:59     ` [PATCH v3 04/22] t0090: stop losing return codes of git commands Denton Liu
                       ` (19 subsequent siblings)
  22 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-22 18:59 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Before, the `git frotz` command would fail but its return code was
hidden since it was in the upstream of a pipe. Break the pipeline into
two commands so that the return code is no longer lost. Also, mark
`git frotz` with test_must_fail since it's supposed to fail.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t0014-alias.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/t/t0014-alias.sh b/t/t0014-alias.sh
index 2694c81afd..8d3d9144c0 100755
--- a/t/t0014-alias.sh
+++ b/t/t0014-alias.sh
@@ -38,8 +38,8 @@ test_expect_success 'looping aliases - internal execution' '
 #'
 
 test_expect_success 'run-command formats empty args properly' '
-    GIT_TRACE=1 git frotz a "" b " " c 2>&1 |
-    sed -ne "/run_command:/s/.*trace: run_command: //p" >actual &&
+    test_must_fail env GIT_TRACE=1 git frotz a "" b " " c 2>actual.raw &&
+    sed -ne "/run_command:/s/.*trace: run_command: //p" actual.raw >actual &&
     echo "git-frotz a '\'''\'' b '\'' '\'' c" >expect &&
     test_cmp expect actual
 '
-- 
2.24.0.497.g17aadd8971


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v3 04/22] t0090: stop losing return codes of git commands
  2019-11-22 18:59   ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                       ` (2 preceding siblings ...)
  2019-11-22 18:59     ` [PATCH v3 03/22] t0014: remove git command upstream of pipe Denton Liu
@ 2019-11-22 18:59     ` Denton Liu
  2019-11-22 18:59     ` [PATCH v3 05/22] t3301: " Denton Liu
                       ` (18 subsequent siblings)
  22 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-22 18:59 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

In generate_expected_cache_tree_rec(), there are currently two instances
of `git ls-files` in the upstream of a pipe. In the case where the
upstream git command fails, its return code will be lost. Extract the
`git ls-files` into its own call so that if it ever fails, its return
code is not lost.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t0090-cache-tree.sh | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh
index ce9a4a5f32..5a633690bf 100755
--- a/t/t0090-cache-tree.sh
+++ b/t/t0090-cache-tree.sh
@@ -21,9 +21,10 @@ generate_expected_cache_tree_rec () {
 	parent="$2" &&
 	# ls-files might have foo/bar, foo/bar/baz, and foo/bar/quux
 	# We want to count only foo because it's the only direct child
-	subtrees=$(git ls-files|grep /|cut -d / -f 1|uniq) &&
+	git ls-files >files &&
+	subtrees=$(grep / files|cut -d / -f 1|uniq) &&
 	subtree_count=$(echo "$subtrees"|awk -v c=0 '$1 != "" {++c} END {print c}') &&
-	entries=$(git ls-files|wc -l) &&
+	entries=$(wc -l <files) &&
 	printf "SHA $dir (%d entries, %d subtrees)\n" "$entries" "$subtree_count" &&
 	for subtree in $subtrees
 	do
-- 
2.24.0.497.g17aadd8971


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v3 05/22] t3301: stop losing return codes of git commands
  2019-11-22 18:59   ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                       ` (3 preceding siblings ...)
  2019-11-22 18:59     ` [PATCH v3 04/22] t0090: stop losing return codes of git commands Denton Liu
@ 2019-11-22 18:59     ` " Denton Liu
  2019-11-22 18:59     ` [PATCH v3 06/22] t3600: use test_line_count() where possible Denton Liu
                       ` (17 subsequent siblings)
  22 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-22 18:59 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Currently, there are two ways where the return codes of git commands are
lost. The first way is when a command is in the upstream of a pipe. In a
pipe, only the return code of the last command is used. Thus, all other
commands will have their return codes masked. Rewrite pipes so that
there are no git commands upstream.

The other way is when a command is in a non-assignment command
substitution. The return code will be lost in favour of the surrounding
command's. Rewrite instances of this so that git commands are either run
on their own or in an assignment-only command substitution.

This patch fixes a real buggy test: in 'copy note with "git notes
copy"', `git notes` was mistyped as `git note`.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t3301-notes.sh | 230 +++++++++++++++++++++++++++++++++--------------
 1 file changed, 163 insertions(+), 67 deletions(-)

diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh
index d66a5f6faa..8f43303007 100755
--- a/t/t3301-notes.sh
+++ b/t/t3301-notes.sh
@@ -54,7 +54,9 @@ test_expect_success 'create notes' '
 	test_path_is_missing .git/NOTES_EDITMSG &&
 	git ls-tree -r refs/notes/commits >actual &&
 	test_line_count = 1 actual &&
-	test "b4" = "$(git notes show)" &&
+	echo b4 >expect &&
+	git notes show >actual &&
+	test_cmp expect actual &&
 	git show HEAD^ &&
 	test_must_fail git notes show HEAD^
 '
@@ -79,14 +81,21 @@ test_expect_success 'edit existing notes' '
 	test_path_is_missing .git/NOTES_EDITMSG &&
 	git ls-tree -r refs/notes/commits >actual &&
 	test_line_count = 1 actual &&
-	test "b3" = "$(git notes show)" &&
+	echo b3 >expect &&
+	git notes show >actual &&
+	test_cmp expect actual &&
 	git show HEAD^ &&
 	test_must_fail git notes show HEAD^
 '
 
 test_expect_success 'show notes from treeish' '
-	test "b3" = "$(git notes --ref commits^{tree} show)" &&
-	test "b4" = "$(git notes --ref commits@{1} show)"
+	echo b3 >expect &&
+	git notes --ref commits^{tree} show >actual &&
+	test_cmp expect actual &&
+
+	echo b4 >expect &&
+	git notes --ref commits@{1} show >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'cannot edit notes from non-ref' '
@@ -99,7 +108,9 @@ test_expect_success 'cannot "git notes add -m" where notes already exists' '
 	test_path_is_missing .git/NOTES_EDITMSG &&
 	git ls-tree -r refs/notes/commits >actual &&
 	test_line_count = 1 actual &&
-	test "b3" = "$(git notes show)" &&
+	echo b3 >expect &&
+	git notes show >actual &&
+	test_cmp expect actual &&
 	git show HEAD^ &&
 	test_must_fail git notes show HEAD^
 '
@@ -109,7 +120,9 @@ test_expect_success 'can overwrite existing note with "git notes add -f -m"' '
 	test_path_is_missing .git/NOTES_EDITMSG &&
 	git ls-tree -r refs/notes/commits >actual &&
 	test_line_count = 1 actual &&
-	test "b1" = "$(git notes show)" &&
+	echo b1 >expect &&
+	git notes show >actual &&
+	test_cmp expect actual &&
 	git show HEAD^ &&
 	test_must_fail git notes show HEAD^
 '
@@ -119,7 +132,9 @@ test_expect_success 'add w/no options on existing note morphs into edit' '
 	test_path_is_missing .git/NOTES_EDITMSG &&
 	git ls-tree -r refs/notes/commits >actual &&
 	test_line_count = 1 actual &&
-	test "b2" = "$(git notes show)" &&
+	echo b2 >expect &&
+	git notes show >actual &&
+	test_cmp expect actual &&
 	git show HEAD^ &&
 	test_must_fail git notes show HEAD^
 '
@@ -129,7 +144,9 @@ test_expect_success 'can overwrite existing note with "git notes add -f"' '
 	test_path_is_missing .git/NOTES_EDITMSG &&
 	git ls-tree -r refs/notes/commits >actual &&
 	test_line_count = 1 actual &&
-	test "b1" = "$(git notes show)" &&
+	echo b1 >expect &&
+	git notes show >actual &&
+	test_cmp expect actual &&
 	git show HEAD^ &&
 	test_must_fail git notes show HEAD^
 '
@@ -146,7 +163,8 @@ test_expect_success 'show notes' '
 		Notes:
 		${indent}b1
 	EOF
-	! (git cat-file commit HEAD | grep b1) &&
+	git cat-file commit HEAD >commits &&
+	! grep b1 commits &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -472,9 +490,11 @@ test_expect_success 'removing with --stdin --ignore-missing' '
 test_expect_success 'list notes with "git notes list"' '
 	commit_2=$(git rev-parse 2nd) &&
 	commit_3=$(git rev-parse 3rd) &&
+	note_2=$(git rev-parse refs/notes/commits:$commit_2) &&
+	note_3=$(git rev-parse refs/notes/commits:$commit_3) &&
 	sort -t" " -k2 >expect <<-EOF &&
-		$(git rev-parse refs/notes/commits:$commit_2) $commit_2
-		$(git rev-parse refs/notes/commits:$commit_3) $commit_3
+		$note_2 $commit_2
+		$note_3 $commit_3
 	EOF
 	git notes list >actual &&
 	test_cmp expect actual
@@ -486,9 +506,7 @@ test_expect_success 'list notes with "git notes"' '
 '
 
 test_expect_success 'list specific note with "git notes list <object>"' '
-	cat >expect <<-EOF &&
-		$(git rev-parse refs/notes/commits:$commit_3)
-	EOF
+	git rev-parse refs/notes/commits:$commit_3 >expect &&
 	git notes list HEAD^^ >actual &&
 	test_cmp expect actual
 '
@@ -512,10 +530,11 @@ test_expect_success 'append to existing note with "git notes append"' '
 
 test_expect_success '"git notes list" does not expand to "git notes list HEAD"' '
 	commit_5=$(git rev-parse 5th) &&
+	note_5=$(git rev-parse refs/notes/commits:$commit_5) &&
 	sort -t" " -k2 >expect_list <<-EOF &&
-		$(git rev-parse refs/notes/commits:$commit_2) $commit_2
-		$(git rev-parse refs/notes/commits:$commit_3) $commit_3
-		$(git rev-parse refs/notes/commits:$commit_5) $commit_5
+		$note_2 $commit_2
+		$note_3 $commit_3
+		$note_5 $commit_5
 	EOF
 	git notes list >actual &&
 	test_cmp expect_list actual
@@ -721,7 +740,8 @@ test_expect_success 'Allow notes on non-commits (trees, blobs, tags)' '
 	git notes show HEAD: >actual &&
 	test_cmp expect actual &&
 	echo "Note on a blob" >expect &&
-	filename=$(git ls-tree --name-only HEAD | head -n1) &&
+	git ls-tree --name-only HEAD >files &&
+	filename=$(head -n1 files) &&
 	git notes add -m "Note on a blob" HEAD:$filename &&
 	git notes show HEAD:$filename >actual &&
 	test_cmp expect actual &&
@@ -745,10 +765,13 @@ test_expect_success 'create note from other note with "git notes add -C"' '
 		Notes:
 		${indent}order test
 	EOF
-	git notes add -C $(git notes list HEAD^) &&
+	note=$(git notes list HEAD^) &&
+	git notes add -C $note &&
 	git log -1 >actual &&
 	test_cmp expect actual &&
-	test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
+	git notes list HEAD^ >expect &&
+	git notes list HEAD >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'create note from non-existing note with "git notes add -C" fails' '
@@ -777,11 +800,12 @@ test_expect_success 'create note from blob with "git notes add -C" reuses blob i
 		Notes:
 		${indent}This is a blob object
 	EOF
-	blob=$(echo "This is a blob object" | git hash-object -w --stdin) &&
-	git notes add -C $blob &&
+	echo "This is a blob object" | git hash-object -w --stdin >blob &&
+	git notes add -C $(cat blob) &&
 	git log -1 >actual &&
 	test_cmp expect actual &&
-	test "$(git notes list HEAD)" = "$blob"
+	git notes list HEAD >actual &&
+	test_cmp blob actual
 '
 
 test_expect_success 'create note from other note with "git notes add -c"' '
@@ -797,7 +821,8 @@ test_expect_success 'create note from other note with "git notes add -c"' '
 		Notes:
 		${indent}yet another note
 	EOF
-	MSG="yet another note" git notes add -c $(git notes list HEAD^^) &&
+	note=$(git notes list HEAD^^) &&
+	MSG="yet another note" git notes add -c $note &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -822,7 +847,8 @@ test_expect_success 'append to note from other note with "git notes append -C"'
 		${indent}
 		${indent}yet another note
 	EOF
-	git notes append -C $(git notes list HEAD^) HEAD^ &&
+	note=$(git notes list HEAD^) &&
+	git notes append -C $note HEAD^ &&
 	git log -1 HEAD^ >actual &&
 	test_cmp expect actual
 '
@@ -839,7 +865,8 @@ test_expect_success 'create note from other note with "git notes append -c"' '
 		Notes:
 		${indent}other note
 	EOF
-	MSG="other note" git notes append -c $(git notes list HEAD^) &&
+	note=$(git notes list HEAD^) &&
+	MSG="other note" git notes append -c $note &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -858,7 +885,8 @@ test_expect_success 'append to note from other note with "git notes append -c"'
 		${indent}
 		${indent}yet another note
 	EOF
-	MSG="yet another note" git notes append -c $(git notes list HEAD) &&
+	note=$(git notes list HEAD) &&
+	MSG="yet another note" git notes append -c $note &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -878,7 +906,9 @@ test_expect_success 'copy note with "git notes copy"' '
 	git notes copy 8th 4th &&
 	git log 3rd..4th >actual &&
 	test_cmp expect actual &&
-	test "$(git note list 4th)" = "$(git note list 8th)"
+	git notes list 4th >expect &&
+	git notes list 8th >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'copy note with "git notes copy" with default' '
@@ -899,14 +929,30 @@ test_expect_success 'copy note with "git notes copy" with default' '
 	git notes copy HEAD^ &&
 	git log -1 >actual &&
 	test_cmp expect actual &&
-	test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
+	git notes list HEAD^ >expect &&
+	git notes list HEAD >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'prevent overwrite with "git notes copy"' '
 	test_must_fail git notes copy HEAD~2 HEAD &&
+	cat >expect <<-EOF &&
+		commit $commit
+		Author: A U Thor <author@example.com>
+		Date:   Thu Apr 7 15:23:13 2005 -0700
+
+		${indent}11th
+
+		Notes:
+		${indent}other note
+		${indent}
+		${indent}yet another note
+	EOF
 	git log -1 >actual &&
 	test_cmp expect actual &&
-	test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
+	git notes list HEAD^ >expect &&
+	git notes list HEAD >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'allow overwrite with "git notes copy -f"' '
@@ -924,7 +970,9 @@ test_expect_success 'allow overwrite with "git notes copy -f"' '
 	git notes copy -f HEAD~3 HEAD &&
 	git log -1 >actual &&
 	test_cmp expect actual &&
-	test "$(git notes list HEAD)" = "$(git notes list HEAD~3)"
+	git notes list HEAD~3 >expect &&
+	git notes list HEAD >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'allow overwrite with "git notes copy -f" with default' '
@@ -944,7 +992,9 @@ test_expect_success 'allow overwrite with "git notes copy -f" with default' '
 	git notes copy -f HEAD~2 &&
 	git log -1 >actual &&
 	test_cmp expect actual &&
-	test "$(git notes list HEAD)" = "$(git notes list HEAD~2)"
+	git notes list HEAD~2 >expect &&
+	git notes list HEAD >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'cannot copy note from object without notes' '
@@ -979,13 +1029,21 @@ test_expect_success 'git notes copy --stdin' '
 		${indent}
 		${indent}yet another note
 	EOF
-	(echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^) &&
-	echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
-	git notes copy --stdin &&
+	from=$(git rev-parse HEAD~3) &&
+	to=$(git rev-parse HEAD^) &&
+	echo "$from" "$to" >copy &&
+	from=$(git rev-parse HEAD~2) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >>copy &&
+	git notes copy --stdin <copy &&
 	git log -2 >actual &&
 	test_cmp expect actual &&
-	test "$(git notes list HEAD)" = "$(git notes list HEAD~2)" &&
-	test "$(git notes list HEAD^)" = "$(git notes list HEAD~3)"
+	git notes list HEAD~2 >expect &&
+	git notes list HEAD >actual &&
+	test_cmp expect actual &&
+	git notes list HEAD~3 >expect &&
+	git notes list HEAD^ >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'git notes copy --for-rewrite (unconfigured)' '
@@ -1006,9 +1064,13 @@ test_expect_success 'git notes copy --for-rewrite (unconfigured)' '
 
 		${indent}14th
 	EOF
-	(echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^) &&
-	echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
-	git notes copy --for-rewrite=foo &&
+	from=$(git rev-parse HEAD~3) &&
+	to=$(git rev-parse HEAD^) &&
+	echo "$from" "$to" >copy &&
+	from=$(git rev-parse HEAD~2) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >>copy &&
+	git notes copy --for-rewrite=foo <copy &&
 	git log -2 >actual &&
 	test_cmp expect actual
 '
@@ -1041,17 +1103,23 @@ test_expect_success 'git notes copy --for-rewrite (enabled)' '
 	EOF
 	test_config notes.rewriteMode overwrite &&
 	test_config notes.rewriteRef "refs/notes/*" &&
-	(echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^) &&
-	echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
-	git notes copy --for-rewrite=foo &&
+	from=$(git rev-parse HEAD~3) &&
+	to=$(git rev-parse HEAD^) &&
+	echo "$from" "$to" >copy &&
+	from=$(git rev-parse HEAD~2) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >>copy &&
+	git notes copy --for-rewrite=foo <copy &&
 	git log -2 >actual &&
 	test_cmp expect actual
 '
 
 test_expect_success 'git notes copy --for-rewrite (disabled)' '
 	test_config notes.rewrite.bar false &&
-	echo $(git rev-parse HEAD~3) $(git rev-parse HEAD) |
-	git notes copy --for-rewrite=bar &&
+	from=$(git rev-parse HEAD~3) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
+	git notes copy --for-rewrite=bar <copy &&
 	git log -2 >actual &&
 	test_cmp expect actual
 '
@@ -1071,8 +1139,10 @@ test_expect_success 'git notes copy --for-rewrite (overwrite)' '
 	git notes add -f -m"a fresh note" HEAD^ &&
 	test_config notes.rewriteMode overwrite &&
 	test_config notes.rewriteRef "refs/notes/*" &&
-	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
-	git notes copy --for-rewrite=foo &&
+	from=$(git rev-parse HEAD^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
+	git notes copy --for-rewrite=foo <copy &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -1080,8 +1150,10 @@ test_expect_success 'git notes copy --for-rewrite (overwrite)' '
 test_expect_success 'git notes copy --for-rewrite (ignore)' '
 	test_config notes.rewriteMode ignore &&
 	test_config notes.rewriteRef "refs/notes/*" &&
-	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
-	git notes copy --for-rewrite=foo &&
+	from=$(git rev-parse HEAD^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
+	git notes copy --for-rewrite=foo <copy &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -1103,8 +1175,10 @@ test_expect_success 'git notes copy --for-rewrite (append)' '
 	git notes add -f -m"another fresh note" HEAD^ &&
 	test_config notes.rewriteMode concatenate &&
 	test_config notes.rewriteRef "refs/notes/*" &&
-	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
-	git notes copy --for-rewrite=foo &&
+	from=$(git rev-parse HEAD^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
+	git notes copy --for-rewrite=foo <copy &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -1131,9 +1205,13 @@ test_expect_success 'git notes copy --for-rewrite (append two to one)' '
 	git notes add -f -m"append 2" HEAD^^ &&
 	test_config notes.rewriteMode concatenate &&
 	test_config notes.rewriteRef "refs/notes/*" &&
-	(echo $(git rev-parse HEAD^) $(git rev-parse HEAD) &&
-	echo $(git rev-parse HEAD^^) $(git rev-parse HEAD)) |
-	git notes copy --for-rewrite=foo &&
+	from=$(git rev-parse HEAD^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
+	from=$(git rev-parse HEAD^^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >>copy &&
+	git notes copy --for-rewrite=foo <copy &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -1142,8 +1220,10 @@ test_expect_success 'git notes copy --for-rewrite (append empty)' '
 	git notes remove HEAD^ &&
 	test_config notes.rewriteMode concatenate &&
 	test_config notes.rewriteRef "refs/notes/*" &&
-	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
-	git notes copy --for-rewrite=foo &&
+	from=$(git rev-parse HEAD^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
+	git notes copy --for-rewrite=foo <copy &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -1163,8 +1243,10 @@ test_expect_success 'GIT_NOTES_REWRITE_MODE works' '
 	test_config notes.rewriteMode concatenate &&
 	test_config notes.rewriteRef "refs/notes/*" &&
 	git notes add -f -m"replacement note 1" HEAD^ &&
-	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
-	GIT_NOTES_REWRITE_MODE=overwrite git notes copy --for-rewrite=foo &&
+	from=$(git rev-parse HEAD^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
+	GIT_NOTES_REWRITE_MODE=overwrite git notes copy --for-rewrite=foo <copy &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -1184,9 +1266,11 @@ test_expect_success 'GIT_NOTES_REWRITE_REF works' '
 	git notes add -f -m"replacement note 2" HEAD^ &&
 	test_config notes.rewriteMode overwrite &&
 	test_unconfig notes.rewriteRef &&
-	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
+	from=$(git rev-parse HEAD^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
 	GIT_NOTES_REWRITE_REF=refs/notes/commits:refs/notes/other \
-		git notes copy --for-rewrite=foo &&
+		git notes copy --for-rewrite=foo <copy &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -1195,9 +1279,11 @@ test_expect_success 'GIT_NOTES_REWRITE_REF overrides config' '
 	git notes add -f -m"replacement note 3" HEAD^ &&
 	test_config notes.rewriteMode overwrite &&
 	test_config notes.rewriteRef refs/notes/other &&
-	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
+	from=$(git rev-parse HEAD^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
 	GIT_NOTES_REWRITE_REF=refs/notes/commits \
-		git notes copy --for-rewrite=foo &&
+		git notes copy --for-rewrite=foo <copy &&
 	git log -1 >actual &&
 	grep "replacement note 3" actual
 '
@@ -1212,26 +1298,36 @@ test_expect_success 'git notes copy diagnoses too many or too few parameters' '
 test_expect_success 'git notes get-ref expands refs/heads/master to refs/notes/refs/heads/master' '
 	test_unconfig core.notesRef &&
 	sane_unset GIT_NOTES_REF &&
-	test "$(git notes --ref=refs/heads/master get-ref)" = "refs/notes/refs/heads/master"
+	echo refs/notes/refs/heads/master >expect &&
+	git notes --ref=refs/heads/master get-ref >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'git notes get-ref (no overrides)' '
 	test_unconfig core.notesRef &&
 	sane_unset GIT_NOTES_REF &&
-	test "$(git notes get-ref)" = "refs/notes/commits"
+	echo refs/notes/commits >expect &&
+	git notes get-ref >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'git notes get-ref (core.notesRef)' '
 	test_config core.notesRef refs/notes/foo &&
-	test "$(git notes get-ref)" = "refs/notes/foo"
+	echo refs/notes/foo >expect &&
+	git notes get-ref >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'git notes get-ref (GIT_NOTES_REF)' '
-	test "$(GIT_NOTES_REF=refs/notes/bar git notes get-ref)" = "refs/notes/bar"
+	echo refs/notes/bar >expect &&
+	GIT_NOTES_REF=refs/notes/bar git notes get-ref >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'git notes get-ref (--ref)' '
-	test "$(GIT_NOTES_REF=refs/notes/bar git notes --ref=baz get-ref)" = "refs/notes/baz"
+	echo refs/notes/baz >expect &&
+	GIT_NOTES_REF=refs/notes/bar git notes --ref=baz get-ref >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'setup testing of empty notes' '
-- 
2.24.0.497.g17aadd8971


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v3 06/22] t3600: use test_line_count() where possible
  2019-11-22 18:59   ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                       ` (4 preceding siblings ...)
  2019-11-22 18:59     ` [PATCH v3 05/22] t3301: " Denton Liu
@ 2019-11-22 18:59     ` Denton Liu
  2019-11-22 18:59     ` [PATCH v3 07/22] t3600: stop losing return codes of git commands Denton Liu
                       ` (16 subsequent siblings)
  22 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-22 18:59 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Since we have a helper function that can test the number of lines in a
file that gives better debugging information on failure, use
test_line_count() to test the number of lines.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t3600-rm.sh | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh
index 8c8cca5bfb..f6e659b7e9 100755
--- a/t/t3600-rm.sh
+++ b/t/t3600-rm.sh
@@ -113,9 +113,10 @@ test_expect_success '"rm" command printed' '
 	echo frotz >test-file &&
 	git add test-file &&
 	git commit -m "add file for rm test" &&
-	git rm test-file >rm-output &&
-	test $(grep "^rm " rm-output | wc -l) = 1 &&
-	rm -f test-file rm-output &&
+	git rm test-file >rm-output.raw &&
+	grep "^rm " rm-output.raw >rm-output &&
+	test_line_count = 1 rm-output &&
+	rm -f test-file rm-output.raw rm-output &&
 	git commit -m "remove file from rm test"
 '
 
-- 
2.24.0.497.g17aadd8971


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v3 07/22] t3600: stop losing return codes of git commands
  2019-11-22 18:59   ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                       ` (5 preceding siblings ...)
  2019-11-22 18:59     ` [PATCH v3 06/22] t3600: use test_line_count() where possible Denton Liu
@ 2019-11-22 18:59     ` Denton Liu
  2019-11-22 19:00     ` [PATCH v3 08/22] t3600: comment on inducing SIGPIPE in `git rm` Denton Liu
                       ` (15 subsequent siblings)
  22 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-22 18:59 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

When a command is in a non-assignment command substitution, the return
code will be lost in favour of the surrounding command's. As a result,
if a git command fails, we won't know about it. Rewrite instances of
this so that git commands are either run in an assignment-only command
substitution so that their return codes aren't lost.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t3600-rm.sh | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh
index f6e659b7e9..0c3bf10edd 100755
--- a/t/t3600-rm.sh
+++ b/t/t3600-rm.sh
@@ -304,7 +304,8 @@ EOF
 
 test_expect_success 'rm removes empty submodules from work tree' '
 	mkdir submod &&
-	git update-index --add --cacheinfo 160000 $(git rev-parse HEAD) submod &&
+	hash=$(git rev-parse HEAD) &&
+	git update-index --add --cacheinfo 160000 "$hash" submod &&
 	git config -f .gitmodules submodule.sub.url ./. &&
 	git config -f .gitmodules submodule.sub.path submod &&
 	git submodule init &&
@@ -623,7 +624,8 @@ test_expect_success 'setup subsubmodule' '
 	git submodule update &&
 	(
 		cd submod &&
-		git update-index --add --cacheinfo 160000 $(git rev-parse HEAD) subsubmod &&
+		hash=$(git rev-parse HEAD) &&
+		git update-index --add --cacheinfo 160000 "$hash" subsubmod &&
 		git config -f .gitmodules submodule.sub.url ../. &&
 		git config -f .gitmodules submodule.sub.path subsubmod &&
 		git submodule init &&
-- 
2.24.0.497.g17aadd8971


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v3 08/22] t3600: comment on inducing SIGPIPE in `git rm`
  2019-11-22 18:59   ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                       ` (6 preceding siblings ...)
  2019-11-22 18:59     ` [PATCH v3 07/22] t3600: stop losing return codes of git commands Denton Liu
@ 2019-11-22 19:00     ` Denton Liu
  2019-11-22 19:00     ` [PATCH v3 09/22] t4015: stop losing return codes of git commands Denton Liu
                       ` (14 subsequent siblings)
  22 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-22 19:00 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Add a comment about intentionally inducing SIGPIPE since this is unusual
and future developers should be aware. Also, even though we are trying
to refactor git commands out of the upstream of pipes, we cannot do it
here since we rely on it being upstream to induce SIGPIPE. Comment on
that as well so that future developers do not try to change it.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t3600-rm.sh | 1 +
 1 file changed, 1 insertion(+)

diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh
index 0c3bf10edd..0ea858d652 100755
--- a/t/t3600-rm.sh
+++ b/t/t3600-rm.sh
@@ -251,6 +251,7 @@ test_expect_success 'choking "git rm" should not let it die with cruft' '
 		echo "100644 $hash 0	some-file-$i"
 		i=$(( $i + 1 ))
 	done | git update-index --index-info &&
+	# git command is intentionally placed upstream of pipe to induce SIGPIPE
 	git rm -n "some-file-*" | : &&
 	test_path_is_missing .git/index.lock
 '
-- 
2.24.0.497.g17aadd8971


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v3 09/22] t4015: stop losing return codes of git commands
  2019-11-22 18:59   ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                       ` (7 preceding siblings ...)
  2019-11-22 19:00     ` [PATCH v3 08/22] t3600: comment on inducing SIGPIPE in `git rm` Denton Liu
@ 2019-11-22 19:00     ` Denton Liu
  2019-11-22 19:00     ` [PATCH v3 10/22] t4015: use test_write_lines() Denton Liu
                       ` (13 subsequent siblings)
  22 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-22 19:00 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Currently, there are two ways where the return codes of git commands are
lost. The first way is when a command is in the upstream of a pipe. In a
pipe, only the return code of the last command is used. Thus, all other
commands will have their return codes masked. Rewrite pipes so that
there are no git commands upstream.

The other way is when a command is in a non-assignment command
substitution. The return code will be lost in favour of the surrounding
command's. Rewrite instances of this so that git commands are either run
on their own or in an assignment-only command substitution.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t4015-diff-whitespace.sh | 119 ++++++++++++++++++++++---------------
 1 file changed, 72 insertions(+), 47 deletions(-)

diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh
index eadaf57262..7fb83c8eff 100755
--- a/t/t4015-diff-whitespace.sh
+++ b/t/t4015-diff-whitespace.sh
@@ -16,7 +16,8 @@ test_expect_success "Ray Lehtiniemi's example" '
 	} while (0);
 	EOF
 	git update-index --add x &&
-	before=$(git rev-parse --short $(git hash-object x)) &&
+	old_hash_x=$(git hash-object x) &&
+	before=$(git rev-parse --short "$old_hash_x") &&
 
 	cat <<-\EOF >x &&
 	do
@@ -25,7 +26,8 @@ test_expect_success "Ray Lehtiniemi's example" '
 	}
 	while (0);
 	EOF
-	after=$(git rev-parse --short $(git hash-object x)) &&
+	new_hash_x=$(git hash-object x) &&
+	after=$(git rev-parse --short "$new_hash_x") &&
 
 	cat <<-EOF >expect &&
 	diff --git a/x b/x
@@ -63,7 +65,8 @@ test_expect_success 'another test, without options' '
 	EOF
 
 	git update-index x &&
-	before=$(git rev-parse --short $(git hash-object x)) &&
+	old_hash_x=$(git hash-object x) &&
+	before=$(git rev-parse --short "$old_hash_x") &&
 
 	tr "_" " " <<-\EOF >x &&
 	_	whitespace at beginning
@@ -73,7 +76,8 @@ test_expect_success 'another test, without options' '
 	unchanged line
 	CR at end
 	EOF
-	after=$(git rev-parse --short $(git hash-object x)) &&
+	new_hash_x=$(git hash-object x) &&
+	after=$(git rev-parse --short "$new_hash_x") &&
 
 	tr "Q_" "\015 " <<-EOF >expect &&
 	diff --git a/x b/x
@@ -526,13 +530,15 @@ test_expect_success 'ignore-blank-lines: mix changes and blank lines' '
 test_expect_success 'check mixed spaces and tabs in indent' '
 	# This is indented with SP HT SP.
 	echo " 	 foo();" >x &&
-	git diff --check | grep "space before tab in indent"
+	test_must_fail git diff --check >check &&
+	grep "space before tab in indent" check
 '
 
 test_expect_success 'check mixed tabs and spaces in indent' '
 	# This is indented with HT SP HT.
 	echo "	 	foo();" >x &&
-	git diff --check | grep "space before tab in indent"
+	test_must_fail git diff --check >check &&
+	grep "space before tab in indent" check
 '
 
 test_expect_success 'check with no whitespace errors' '
@@ -753,20 +759,23 @@ test_expect_success 'check tab-in-indent excluded from wildcard whitespace attri
 test_expect_success 'line numbers in --check output are correct' '
 	echo "" >x &&
 	echo "foo(); " >>x &&
-	git diff --check | grep "x:2:"
+	test_must_fail git diff --check >check &&
+	grep "x:2:" check
 '
 
 test_expect_success 'checkdiff detects new trailing blank lines (1)' '
 	echo "foo();" >x &&
 	echo "" >>x &&
-	git diff --check | grep "new blank line"
+	test_must_fail git diff --check >check &&
+	grep "new blank line" check
 '
 
 test_expect_success 'checkdiff detects new trailing blank lines (2)' '
 	{ echo a; echo b; echo; echo; } >x &&
 	git add x &&
 	{ echo a; echo; echo; echo; echo; } >x &&
-	git diff --check | grep "new blank line"
+	test_must_fail git diff --check >check &&
+	grep "new blank line" check
 '
 
 test_expect_success 'checkdiff allows new blank lines' '
@@ -794,14 +803,16 @@ test_expect_success 'whitespace-only changes reported across renames' '
 	git reset --hard &&
 	for i in 1 2 3 4 5 6 7 8 9; do echo "$i$i$i$i$i$i"; done >x &&
 	git add x &&
-	before=$(git rev-parse --short $(git hash-object x)) &&
+	hash_x=$(git hash-object x) &&
+	before=$(git rev-parse --short "$hash_x") &&
 	git commit -m "base" &&
 	sed -e "5s/^/ /" x >z &&
 	git rm x &&
 	git add z &&
-	after=$(git rev-parse --short $(git hash-object z)) &&
-	git diff -w -M --cached |
-	sed -e "/^similarity index /s/[0-9][0-9]*/NUM/" >actual &&
+	hash_z=$(git hash-object z) &&
+	after=$(git rev-parse --short "$hash_z") &&
+	git diff -w -M --cached >actual.raw &&
+	sed -e "/^similarity index /s/[0-9][0-9]*/NUM/" actual.raw >actual &&
 	cat <<-EOF >expect &&
 	diff --git a/x b/z
 	similarity index NUM%
@@ -840,7 +851,8 @@ test_expect_success 'combined diff with autocrlf conversion' '
 	git config core.autocrlf true &&
 	test_must_fail git merge master &&
 
-	git diff | sed -e "1,/^@@@/d" >actual &&
+	git diff >actual.raw &&
+	sed -e "1,/^@@@/d" actual.raw >actual &&
 	! grep "^-" actual
 
 '
@@ -864,11 +876,14 @@ test_expect_success 'diff that introduces a line with only tabs' '
 	git config core.whitespace blank-at-eol &&
 	git reset --hard &&
 	echo "test" >x &&
-	before=$(git rev-parse --short $(git hash-object x)) &&
+	old_hash_x=$(git hash-object x) &&
+	before=$(git rev-parse --short "$old_hash_x") &&
 	git commit -m "initial" x &&
 	echo "{NTN}" | tr "NT" "\n\t" >>x &&
-	after=$(git rev-parse --short $(git hash-object x)) &&
-	git diff --color | test_decode_color >current &&
+	new_hash_x=$(git hash-object x) &&
+	after=$(git rev-parse --short "$new_hash_x") &&
+	git diff --color >current.raw &&
+	test_decode_color <current.raw >current &&
 
 	cat >expected <<-EOF &&
 	<BOLD>diff --git a/x b/x<RESET>
@@ -891,17 +906,19 @@ test_expect_success 'diff that introduces and removes ws breakages' '
 		echo "0. blank-at-eol " &&
 		echo "1. blank-at-eol "
 	} >x &&
-	before=$(git rev-parse --short $(git hash-object x)) &&
+	old_hash_x=$(git hash-object x) &&
+	before=$(git rev-parse --short "$old_hash_x") &&
 	git commit -a --allow-empty -m preimage &&
 	{
 		echo "0. blank-at-eol " &&
 		echo "1. still-blank-at-eol " &&
 		echo "2. and a new line "
 	} >x &&
-	after=$(git rev-parse --short $(git hash-object x)) &&
+	new_hash_x=$(git hash-object x) &&
+	after=$(git rev-parse --short "$new_hash_x") &&
 
-	git diff --color |
-	test_decode_color >current &&
+	git diff --color >current.raw &&
+	test_decode_color <current.raw >current &&
 
 	cat >expected <<-EOF &&
 	<BOLD>diff --git a/x b/x<RESET>
@@ -925,14 +942,16 @@ test_expect_success 'ws-error-highlight test setup' '
 		echo "0. blank-at-eol " &&
 		echo "1. blank-at-eol "
 	} >x &&
-	before=$(git rev-parse --short $(git hash-object x)) &&
+	old_hash_x=$(git hash-object x) &&
+	before=$(git rev-parse --short "$old_hash_x") &&
 	git commit -a --allow-empty -m preimage &&
 	{
 		echo "0. blank-at-eol " &&
 		echo "1. still-blank-at-eol " &&
 		echo "2. and a new line "
 	} >x &&
-	after=$(git rev-parse --short $(git hash-object x)) &&
+	new_hash_x=$(git hash-object x) &&
+	after=$(git rev-parse --short "$new_hash_x") &&
 
 	cat >expect.default-old <<-EOF &&
 	<BOLD>diff --git a/x b/x<RESET>
@@ -974,32 +993,32 @@ test_expect_success 'ws-error-highlight test setup' '
 
 test_expect_success 'test --ws-error-highlight option' '
 
-	git diff --color --ws-error-highlight=default,old |
-	test_decode_color >current &&
+	git diff --color --ws-error-highlight=default,old >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.default-old current &&
 
-	git diff --color --ws-error-highlight=all |
-	test_decode_color >current &&
+	git diff --color --ws-error-highlight=all >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.all current &&
 
-	git diff --color --ws-error-highlight=none |
-	test_decode_color >current &&
+	git diff --color --ws-error-highlight=none >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.none current
 
 '
 
 test_expect_success 'test diff.wsErrorHighlight config' '
 
-	git -c diff.wsErrorHighlight=default,old diff --color |
-	test_decode_color >current &&
+	git -c diff.wsErrorHighlight=default,old diff --color >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.default-old current &&
 
-	git -c diff.wsErrorHighlight=all diff --color |
-	test_decode_color >current &&
+	git -c diff.wsErrorHighlight=all diff --color >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.all current &&
 
-	git -c diff.wsErrorHighlight=none diff --color |
-	test_decode_color >current &&
+	git -c diff.wsErrorHighlight=none diff --color >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.none current
 
 '
@@ -1007,18 +1026,18 @@ test_expect_success 'test diff.wsErrorHighlight config' '
 test_expect_success 'option overrides diff.wsErrorHighlight' '
 
 	git -c diff.wsErrorHighlight=none \
-		diff --color --ws-error-highlight=default,old |
-	test_decode_color >current &&
+		diff --color --ws-error-highlight=default,old >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.default-old current &&
 
 	git -c diff.wsErrorHighlight=default \
-		diff --color --ws-error-highlight=all |
-	test_decode_color >current &&
+		diff --color --ws-error-highlight=all >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.all current &&
 
 	git -c diff.wsErrorHighlight=all \
-		diff --color --ws-error-highlight=none |
-	test_decode_color >current &&
+		diff --color --ws-error-highlight=none >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.none current
 
 '
@@ -1038,7 +1057,8 @@ test_expect_success 'detect moved code, complete file' '
 	git mv test.c main.c &&
 	test_config color.diff.oldMoved "normal red" &&
 	test_config color.diff.newMoved "normal green" &&
-	git diff HEAD --color-moved=zebra --color --no-renames | test_decode_color >actual &&
+	git diff HEAD --color-moved=zebra --color --no-renames >actual.raw &&
+	test_decode_color <actual.raw >actual &&
 	cat >expected <<-EOF &&
 	<BOLD>diff --git a/main.c b/main.c<RESET>
 	<BOLD>new file mode 100644<RESET>
@@ -1141,9 +1161,12 @@ test_expect_success 'detect malicious moved code, inside file' '
 			bar();
 		}
 	EOF
-	after_main=$(git rev-parse --short $(git hash-object main.c)) &&
-	after_test=$(git rev-parse --short $(git hash-object test.c)) &&
-	git diff HEAD --no-renames --color-moved=zebra --color | test_decode_color >actual &&
+	hash_main=$(git hash-object main.c) &&
+	after_main=$(git rev-parse --short "$hash_main") &&
+	hash_test=$(git hash-object test.c) &&
+	after_test=$(git rev-parse --short "$hash_test") &&
+	git diff HEAD --no-renames --color-moved=zebra --color >actual.raw &&
+	test_decode_color <actual.raw >actual &&
 	cat <<-EOF >expected &&
 	<BOLD>diff --git a/main.c b/main.c<RESET>
 	<BOLD>index $before_main..$after_main 100644<RESET>
@@ -1192,7 +1215,8 @@ test_expect_success 'plain moved code, inside file' '
 	test_config color.diff.oldMovedAlternative "blue" &&
 	test_config color.diff.newMovedAlternative "yellow" &&
 	# needs previous test as setup
-	git diff HEAD --no-renames --color-moved=plain --color | test_decode_color >actual &&
+	git diff HEAD --no-renames --color-moved=plain --color >actual.raw &&
+	test_decode_color <actual.raw >actual &&
 	cat <<-EOF >expected &&
 	<BOLD>diff --git a/main.c b/main.c<RESET>
 	<BOLD>index $before_main..$after_main 100644<RESET>
@@ -1771,7 +1795,8 @@ test_expect_success 'move detection with submodules' '
 	! grep BRED decoded_actual &&
 
 	# nor did we mess with it another way
-	git diff --submodule=diff --color | test_decode_color >expect &&
+	git diff --submodule=diff --color >expect.raw &&
+	test_decode_color <expect.raw >expect &&
 	test_cmp expect decoded_actual &&
 	rm -rf bananas &&
 	git submodule deinit bananas
-- 
2.24.0.497.g17aadd8971


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v3 10/22] t4015: use test_write_lines()
  2019-11-22 18:59   ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                       ` (8 preceding siblings ...)
  2019-11-22 19:00     ` [PATCH v3 09/22] t4015: stop losing return codes of git commands Denton Liu
@ 2019-11-22 19:00     ` Denton Liu
  2019-11-22 19:00     ` [PATCH v3 11/22] t4138: stop losing return codes of git commands Denton Liu
                       ` (12 subsequent siblings)
  22 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-22 19:00 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Instead of rolling our own method to write out some lines into a file,
use the existing test_write_lines().

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t4015-diff-whitespace.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh
index 7fb83c8eff..4c540b1d70 100755
--- a/t/t4015-diff-whitespace.sh
+++ b/t/t4015-diff-whitespace.sh
@@ -771,9 +771,9 @@ test_expect_success 'checkdiff detects new trailing blank lines (1)' '
 '
 
 test_expect_success 'checkdiff detects new trailing blank lines (2)' '
-	{ echo a; echo b; echo; echo; } >x &&
+	test_write_lines a b "" "" >x &&
 	git add x &&
-	{ echo a; echo; echo; echo; echo; } >x &&
+	test_write_lines a "" "" "" "" >x &&
 	test_must_fail git diff --check >check &&
 	grep "new blank line" check
 '
-- 
2.24.0.497.g17aadd8971


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v3 11/22] t4138: stop losing return codes of git commands
  2019-11-22 18:59   ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                       ` (9 preceding siblings ...)
  2019-11-22 19:00     ` [PATCH v3 10/22] t4015: use test_write_lines() Denton Liu
@ 2019-11-22 19:00     ` Denton Liu
  2019-11-22 19:00     ` [PATCH v3 12/22] t5317: " Denton Liu
                       ` (11 subsequent siblings)
  22 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-22 19:00 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

In a pipe, only the return code of the last command is used. Thus, all
other commands will have their return codes masked. Rewrite pipes so
that there are no git commands upstream so that we will know if a
command fails.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t4138-apply-ws-expansion.sh | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/t/t4138-apply-ws-expansion.sh b/t/t4138-apply-ws-expansion.sh
index 3b636a63a3..b19faeb67a 100755
--- a/t/t4138-apply-ws-expansion.sh
+++ b/t/t4138-apply-ws-expansion.sh
@@ -17,8 +17,8 @@ test_expect_success setup '
 	printf "\t%s\n" 1 2 3 >after &&
 	printf "%64s\n" a b c >>after &&
 	printf "\t%s\n" 4 5 6 >>after &&
-	git diff --no-index before after |
-		sed -e "s/before/test-1/" -e "s/after/test-1/" >patch1.patch &&
+	test_expect_code 1 git diff --no-index before after >patch1.patch.raw &&
+	sed -e "s/before/test-1/" -e "s/after/test-1/" patch1.patch.raw >patch1.patch &&
 	printf "%64s\n" 1 2 3 4 5 6 >test-1 &&
 	printf "%64s\n" 1 2 3 a b c 4 5 6 >expect-1 &&
 
@@ -33,8 +33,8 @@ test_expect_success setup '
 		x=$(( $x + 1 ))
 	done &&
 	printf "\t%s\n" d e f >>after &&
-	git diff --no-index before after |
-		sed -e "s/before/test-2/" -e "s/after/test-2/" >patch2.patch &&
+	test_expect_code 1 git diff --no-index before after >patch2.patch.raw &&
+	sed -e "s/before/test-2/" -e "s/after/test-2/" patch2.patch.raw >patch2.patch &&
 	printf "%64s\n" a b c d e f >test-2 &&
 	printf "%64s\n" a b c >expect-2 &&
 	x=1 &&
@@ -56,8 +56,8 @@ test_expect_success setup '
 		x=$(( $x + 1 ))
 	done &&
 	printf "\t%s\n" d e f >>after &&
-	git diff --no-index before after |
-	sed -e "s/before/test-3/" -e "s/after/test-3/" >patch3.patch &&
+	test_expect_code 1 git diff --no-index before after >patch3.patch.raw &&
+	sed -e "s/before/test-3/" -e "s/after/test-3/" patch3.patch.raw >patch3.patch &&
 	printf "%64s\n" a b c d e f >test-3 &&
 	printf "%64s\n" a b c >expect-3 &&
 	x=0 &&
@@ -84,8 +84,8 @@ test_expect_success setup '
 		printf "\t%02d\n" $x >>after
 		x=$(( $x + 1 ))
 	done &&
-	git diff --no-index before after |
-	sed -e "s/before/test-4/" -e "s/after/test-4/" >patch4.patch &&
+	test_expect_code 1 git diff --no-index before after >patch4.patch.raw &&
+	sed -e "s/before/test-4/" -e "s/after/test-4/" patch4.patch.raw >patch4.patch &&
 	>test-4 &&
 	x=0 &&
 	while test $x -lt 50
-- 
2.24.0.497.g17aadd8971


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v3 12/22] t5317: stop losing return codes of git commands
  2019-11-22 18:59   ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                       ` (10 preceding siblings ...)
  2019-11-22 19:00     ` [PATCH v3 11/22] t4138: stop losing return codes of git commands Denton Liu
@ 2019-11-22 19:00     ` " Denton Liu
  2019-11-22 19:00     ` [PATCH v3 13/22] t5317: use ! grep to check for no matching lines Denton Liu
                       ` (10 subsequent siblings)
  22 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-22 19:00 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Currently, there are two ways where the return codes of git commands are
lost. The first way is when a command is in the upstream of a pipe. In a
pipe, only the return code of the last command is used. Thus, all other
commands will have their return codes masked. Rewrite pipes so that
there are no git commands upstream.

The other way is when a command is in a non-assignment command
substitution. The return code will be lost in favour of the surrounding
command's. Rewrite instances of this such that git commands output to a
file and surrounding commands only call command substitutions with
non-git commands.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5317-pack-objects-filter-objects.sh | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/t/t5317-pack-objects-filter-objects.sh b/t/t5317-pack-objects-filter-objects.sh
index 2d2f5d0229..a8bbad74e2 100755
--- a/t/t5317-pack-objects-filter-objects.sh
+++ b/t/t5317-pack-objects-filter-objects.sh
@@ -72,7 +72,8 @@ test_expect_success 'get an error for missing tree object' '
 	echo foo >r5/foo &&
 	git -C r5 add foo &&
 	git -C r5 commit -m "foo" &&
-	del=$(git -C r5 rev-parse HEAD^{tree} | sed "s|..|&/|") &&
+	git -C r5 rev-parse HEAD^{tree} >tree &&
+	del=$(sed "s|..|&/|" tree) &&
 	rm r5/.git/objects/$del &&
 	test_must_fail git -C r5 pack-objects --revs --stdout 2>bad_tree <<-EOF &&
 	HEAD
@@ -230,10 +231,9 @@ test_expect_success 'verify explicitly specifying oversized blob in input' '
 	awk -f print_2.awk ls_files_result |
 	sort >expected &&
 
-	git -C r2 pack-objects --revs --stdout --filter=blob:limit=1k >filter.pack <<-EOF &&
-	HEAD
-	$(git -C r2 rev-parse HEAD:large.10000)
-	EOF
+	echo HEAD >objects &&
+	git -C r2 rev-parse HEAD:large.10000 >>objects &&
+	git -C r2 pack-objects --revs --stdout --filter=blob:limit=1k <objects >filter.pack &&
 	git -C r2 index-pack ../filter.pack &&
 
 	git -C r2 verify-pack -v ../filter.pack >verify_result &&
@@ -377,7 +377,8 @@ test_expect_success 'verify sparse:oid=OID' '
 	awk -f print_2.awk ls_files_result |
 	sort >expected &&
 
-	oid=$(git -C r4 ls-files -s pattern | awk -f print_2.awk) &&
+	git -C r4 ls-files -s pattern >staged &&
+	oid=$(awk -f print_2.awk staged) &&
 	git -C r4 pack-objects --revs --stdout --filter=sparse:oid=$oid >filter.pack <<-EOF &&
 	HEAD
 	EOF
-- 
2.24.0.497.g17aadd8971


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v3 13/22] t5317: use ! grep to check for no matching lines
  2019-11-22 18:59   ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                       ` (11 preceding siblings ...)
  2019-11-22 19:00     ` [PATCH v3 12/22] t5317: " Denton Liu
@ 2019-11-22 19:00     ` Denton Liu
  2019-11-23  6:21       ` Eric Sunshine
  2019-11-22 19:00     ` [PATCH v3 14/22] t5703: simplify one-time-sed generation logic Denton Liu
                       ` (9 subsequent siblings)
  22 siblings, 1 reply; 169+ messages in thread
From: Denton Liu @ 2019-11-22 19:00 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Several times in t5317, we would use `wc -l` to ensure that a grep
result is empty. However, grep already has a way to do that... Its
return code! Use `! grep` in the cases where we are ensuring that there
are no matching lines.

While at it, drop unnecessary invocations of 'awk' and 'sort' in each
affected test since those commands do not influence the outcome. It's
not clear why that extra work was being done in the first place, and the
code's history doesn't shed any light on the matter since these tests
were simply born this way[1], doing all the unnecessary work for no
reason, probably due to copy/paste programming...

[1]: 9535ce7337 (pack-objects: add list-objects filtering, 2017-11-21)

Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5317-pack-objects-filter-objects.sh | 21 +++------------------
 1 file changed, 3 insertions(+), 18 deletions(-)

diff --git a/t/t5317-pack-objects-filter-objects.sh b/t/t5317-pack-objects-filter-objects.sh
index a8bbad74e2..dc0446574b 100755
--- a/t/t5317-pack-objects-filter-objects.sh
+++ b/t/t5317-pack-objects-filter-objects.sh
@@ -45,12 +45,7 @@ test_expect_success 'verify blob:none packfile has no blobs' '
 	git -C r1 index-pack ../filter.pack &&
 
 	git -C r1 verify-pack -v ../filter.pack >verify_result &&
-	grep blob verify_result |
-	awk -f print_1.awk |
-	sort >observed &&
-
-	nr=$(wc -l <observed) &&
-	test 0 -eq $nr
+	! grep blob verify_result
 '
 
 test_expect_success 'verify normal and blob:none packfiles have same commits/trees' '
@@ -149,12 +144,7 @@ test_expect_success 'verify blob:limit=500 omits all blobs' '
 	git -C r2 index-pack ../filter.pack &&
 
 	git -C r2 verify-pack -v ../filter.pack >verify_result &&
-	grep blob verify_result |
-	awk -f print_1.awk |
-	sort >observed &&
-
-	nr=$(wc -l <observed) &&
-	test 0 -eq $nr
+	! grep blob verify_result
 '
 
 test_expect_success 'verify blob:limit=1000' '
@@ -164,12 +154,7 @@ test_expect_success 'verify blob:limit=1000' '
 	git -C r2 index-pack ../filter.pack &&
 
 	git -C r2 verify-pack -v ../filter.pack >verify_result &&
-	grep blob verify_result |
-	awk -f print_1.awk |
-	sort >observed &&
-
-	nr=$(wc -l <observed) &&
-	test 0 -eq $nr
+	! grep blob verify_result
 '
 
 test_expect_success 'verify blob:limit=1001' '
-- 
2.24.0.497.g17aadd8971


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v3 14/22] t5703: simplify one-time-sed generation logic
  2019-11-22 18:59   ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                       ` (12 preceding siblings ...)
  2019-11-22 19:00     ` [PATCH v3 13/22] t5317: use ! grep to check for no matching lines Denton Liu
@ 2019-11-22 19:00     ` Denton Liu
  2019-11-22 19:00     ` [PATCH v3 15/22] t5703: stop losing return codes of git commands Denton Liu
                       ` (8 subsequent siblings)
  22 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-22 19:00 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

In inconsistency(), we had two `git rev-parse` invocations in the
upstream of a pipe within a command substitution. In case this
invocation ever failed, its exit code would be swallowed up and we would
not know about it.

Pull the command substitutions out into variable assignments so that
their return codes are not lost.

Drop the pipe into `tr` because the $(...) substitution already takes
care of stripping out newlines, so the `tr` invocations in the code are
superfluous.

Finally, given the way the tests actually employ "one-time-sed" via
$(cat one-time-sed) in t/lib-httpd/apply-one-time-sed.sh, convert the
`printf` into an `echo`. This makes it consistent with the final "server
loses a ref - ref in want" test, which does use `echo` rather than
`printf`.

Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5703-upload-pack-ref-in-want.sh | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/t/t5703-upload-pack-ref-in-want.sh b/t/t5703-upload-pack-ref-in-want.sh
index 3a2c143c6d..88338c4e09 100755
--- a/t/t5703-upload-pack-ref-in-want.sh
+++ b/t/t5703-upload-pack-ref-in-want.sh
@@ -312,10 +312,9 @@ inconsistency () {
 	# repository appears to change during negotiation, for example, when
 	# different servers in a load-balancing arrangement serve (stateless)
 	# RPCs during a single negotiation.
-	printf "s/%s/%s/" \
-	       $(git -C "$REPO" rev-parse $1 | tr -d "\n") \
-	       $(git -C "$REPO" rev-parse $2 | tr -d "\n") \
-	       >"$HTTPD_ROOT_PATH/one-time-sed"
+	oid1=$(git -C "$REPO" rev-parse $1) &&
+	oid2=$(git -C "$REPO" rev-parse $2) &&
+	echo "s/$oid1/$oid2/" >"$HTTPD_ROOT_PATH/one-time-sed"
 }
 
 test_expect_success 'server is initially ahead - no ref in want' '
-- 
2.24.0.497.g17aadd8971


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v3 15/22] t5703: stop losing return codes of git commands
  2019-11-22 18:59   ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                       ` (13 preceding siblings ...)
  2019-11-22 19:00     ` [PATCH v3 14/22] t5703: simplify one-time-sed generation logic Denton Liu
@ 2019-11-22 19:00     ` Denton Liu
  2019-11-22 19:00     ` [PATCH v3 16/22] t7501: remove spaces after redirect operators Denton Liu
                       ` (7 subsequent siblings)
  22 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-22 19:00 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Currently, there are two ways where the return codes of git commands are
lost. The first way is when a command is in the upstream of a pipe. In a
pipe, only the return code of the last command is used. Thus, all other
commands will have their return codes masked. Rewrite pipes so that
there are no git commands upstream.

The other way is when a command is in a non-assignment command
substitution. The return code will be lost in favour of the surrounding
command's. Rewrite instances of this such that git commands are in an
assignment-only command substitution.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5703-upload-pack-ref-in-want.sh | 46 +++++++++++++++++++-----------
 1 file changed, 29 insertions(+), 17 deletions(-)

diff --git a/t/t5703-upload-pack-ref-in-want.sh b/t/t5703-upload-pack-ref-in-want.sh
index 88338c4e09..1424fabd4a 100755
--- a/t/t5703-upload-pack-ref-in-want.sh
+++ b/t/t5703-upload-pack-ref-in-want.sh
@@ -18,14 +18,16 @@ get_actual_commits () {
 		p
 		}' <out | test-tool pkt-line unpack-sideband >o.pack &&
 	git index-pack o.pack &&
-	git verify-pack -v o.idx | grep commit | cut -c-40 | sort >actual_commits
+	git verify-pack -v o.idx >objs &&
+	grep commit objs | cut -c-40 | sort >actual_commits
 }
 
 check_output () {
 	get_actual_refs &&
 	test_cmp expected_refs actual_refs &&
 	get_actual_commits &&
-	test_cmp expected_commits actual_commits
+	sort expected_commits >sorted_commits &&
+	test_cmp sorted_commits actual_commits
 }
 
 # c(o/foo) d(o/bar)
@@ -75,17 +77,19 @@ test_expect_success 'invalid want-ref line' '
 '
 
 test_expect_success 'basic want-ref' '
+	oid=$(git rev-parse f) &&
 	cat >expected_refs <<-EOF &&
-	$(git rev-parse f) refs/heads/master
+	$oid refs/heads/master
 	EOF
-	git rev-parse f | sort >expected_commits &&
+	git rev-parse f >expected_commits &&
 
+	oid=$(git rev-parse a) &&
 	test-tool pkt-line pack >in <<-EOF &&
 	command=fetch
 	0001
 	no-progress
 	want-ref refs/heads/master
-	have $(git rev-parse a)
+	have $oid
 	done
 	0000
 	EOF
@@ -95,19 +99,22 @@ test_expect_success 'basic want-ref' '
 '
 
 test_expect_success 'multiple want-ref lines' '
+	oid_c=$(git rev-parse c) &&
+	oid_d=$(git rev-parse d) &&
 	cat >expected_refs <<-EOF &&
-	$(git rev-parse c) refs/heads/o/foo
-	$(git rev-parse d) refs/heads/o/bar
+	$oid_c refs/heads/o/foo
+	$oid_d refs/heads/o/bar
 	EOF
-	git rev-parse c d | sort >expected_commits &&
+	git rev-parse c d >expected_commits &&
 
+	oid=$(git rev-parse b) &&
 	test-tool pkt-line pack >in <<-EOF &&
 	command=fetch
 	0001
 	no-progress
 	want-ref refs/heads/o/foo
 	want-ref refs/heads/o/bar
-	have $(git rev-parse b)
+	have $oid
 	done
 	0000
 	EOF
@@ -117,10 +124,11 @@ test_expect_success 'multiple want-ref lines' '
 '
 
 test_expect_success 'mix want and want-ref' '
+	oid=$(git rev-parse f) &&
 	cat >expected_refs <<-EOF &&
-	$(git rev-parse f) refs/heads/master
+	$oid refs/heads/master
 	EOF
-	git rev-parse e f | sort >expected_commits &&
+	git rev-parse e f >expected_commits &&
 
 	test-tool pkt-line pack >in <<-EOF &&
 	command=fetch
@@ -138,17 +146,19 @@ test_expect_success 'mix want and want-ref' '
 '
 
 test_expect_success 'want-ref with ref we already have commit for' '
+	oid=$(git rev-parse c) &&
 	cat >expected_refs <<-EOF &&
-	$(git rev-parse c) refs/heads/o/foo
+	$oid refs/heads/o/foo
 	EOF
 	>expected_commits &&
 
+	oid=$(git rev-parse c) &&
 	test-tool pkt-line pack >in <<-EOF &&
 	command=fetch
 	0001
 	no-progress
 	want-ref refs/heads/o/foo
-	have $(git rev-parse c)
+	have $oid
 	done
 	0000
 	EOF
@@ -211,13 +221,14 @@ test_expect_success 'fetching with exact OID' '
 
 	rm -rf local &&
 	cp -r "$LOCAL_PRISTINE" local &&
+	oid=$(git -C "$REPO" rev-parse d) &&
 	GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin \
-		$(git -C "$REPO" rev-parse d):refs/heads/actual &&
+		"$oid":refs/heads/actual &&
 
 	git -C "$REPO" rev-parse "d" >expected &&
 	git -C local rev-parse refs/heads/actual >actual &&
 	test_cmp expected actual &&
-	grep "want $(git -C "$REPO" rev-parse d)" log
+	grep "want $oid" log
 '
 
 test_expect_success 'fetching multiple refs' '
@@ -239,13 +250,14 @@ test_expect_success 'fetching ref and exact OID' '
 
 	rm -rf local &&
 	cp -r "$LOCAL_PRISTINE" local &&
+	oid=$(git -C "$REPO" rev-parse b) &&
 	GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin \
-		master $(git -C "$REPO" rev-parse b):refs/heads/actual &&
+		master "$oid":refs/heads/actual &&
 
 	git -C "$REPO" rev-parse "master" "b" >expected &&
 	git -C local rev-parse refs/remotes/origin/master refs/heads/actual >actual &&
 	test_cmp expected actual &&
-	grep "want $(git -C "$REPO" rev-parse b)" log &&
+	grep "want $oid" log &&
 	grep "want-ref refs/heads/master" log
 '
 
-- 
2.24.0.497.g17aadd8971


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v3 16/22] t7501: remove spaces after redirect operators
  2019-11-22 18:59   ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                       ` (14 preceding siblings ...)
  2019-11-22 19:00     ` [PATCH v3 15/22] t5703: stop losing return codes of git commands Denton Liu
@ 2019-11-22 19:00     ` Denton Liu
  2019-11-22 19:00     ` [PATCH v3 17/22] t7501: stop losing return codes of git commands Denton Liu
                       ` (6 subsequent siblings)
  22 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-22 19:00 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

For shell scripts, the usual convention is for there to be no space
after redirection operators, (e.g. `>file`, not `> file`). Remove these
spaces wherever they appear.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7501-commit-basic-functionality.sh | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/t/t7501-commit-basic-functionality.sh b/t/t7501-commit-basic-functionality.sh
index f1349af56e..5765d33c53 100755
--- a/t/t7501-commit-basic-functionality.sh
+++ b/t/t7501-commit-basic-functionality.sh
@@ -150,7 +150,7 @@ test_expect_success 'setup: commit message from file' '
 test_expect_success 'amend commit' '
 	cat >editor <<-\EOF &&
 	#!/bin/sh
-	sed -e "s/a file/an amend commit/g" < "$1" > "$1-"
+	sed -e "s/a file/an amend commit/g" <"$1" >"$1-"
 	mv "$1-" "$1"
 	EOF
 	chmod 755 editor &&
@@ -263,7 +263,7 @@ test_expect_success 'using message from other commit' '
 test_expect_success 'editing message from other commit' '
 	cat >editor <<-\EOF &&
 	#!/bin/sh
-	sed -e "s/amend/older/g"  < "$1" > "$1-"
+	sed -e "s/amend/older/g"  <"$1" >"$1-"
 	mv "$1-" "$1"
 	EOF
 	chmod 755 editor &&
@@ -367,7 +367,7 @@ test_expect_success 'amend commit to fix author' '
 		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
 		expected &&
 	git commit --amend --author="$author" &&
-	git cat-file -p HEAD > current &&
+	git cat-file -p HEAD >current &&
 	test_cmp expected current
 
 '
@@ -382,7 +382,7 @@ test_expect_success 'amend commit to fix date' '
 		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
 		expected &&
 	git commit --amend --date="$newtick" &&
-	git cat-file -p HEAD > current &&
+	git cat-file -p HEAD >current &&
 	test_cmp expected current
 
 '
@@ -448,7 +448,7 @@ test_expect_success 'signoff gap' '
 	git commit -s -m "welcome
 
 $alt" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
+	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
 	(
 		echo welcome &&
 		echo &&
@@ -468,7 +468,7 @@ test_expect_success 'signoff gap 2' '
 
 We have now
 $alt" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
+	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
 	(
 		echo welcome &&
 		echo &&
@@ -489,7 +489,7 @@ test_expect_success 'signoff respects trailer config' '
 
 non-trailer line
 Myfooter: x" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
+	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
 	(
 		echo subject &&
 		echo &&
@@ -506,7 +506,7 @@ Myfooter: x" &&
 
 non-trailer line
 Myfooter: x" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
+	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
 	(
 		echo subject &&
 		echo &&
@@ -560,14 +560,14 @@ test_expect_success 'amend commit to fix author' '
 		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
 		expected &&
 	git commit --amend --author="$author" &&
-	git cat-file -p HEAD > current &&
+	git cat-file -p HEAD >current &&
 	test_cmp expected current
 
 '
 
 test_expect_success 'git commit <file> with dirty index' '
-	echo tacocat > elif &&
-	echo tehlulz > chz &&
+	echo tacocat >elif &&
+	echo tehlulz >chz &&
 	git add chz &&
 	git commit elif -m "tacocat is a palindrome" &&
 	git show --stat | grep elif &&
-- 
2.24.0.497.g17aadd8971


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v3 17/22] t7501: stop losing return codes of git commands
  2019-11-22 18:59   ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                       ` (15 preceding siblings ...)
  2019-11-22 19:00     ` [PATCH v3 16/22] t7501: remove spaces after redirect operators Denton Liu
@ 2019-11-22 19:00     ` Denton Liu
  2019-11-22 19:00     ` [PATCH v3 18/22] t7700: drop redirections to /dev/null Denton Liu
                       ` (5 subsequent siblings)
  22 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-22 19:00 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

In a pipe, only the return code of the last command is used. Thus, all
other commands will have their return codes masked. Rewrite pipes so
that there are no git commands upstream so that we will know if a
command fails.

In the 'interactive add' test case, we prepend a `test_must_fail` to
`git commit --interactive`. When there are no changes to commit,
`git commit` will exit with status code 1. Following along with the rest
of the file, we use `test_must_fail` to test for this case.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7501-commit-basic-functionality.sh | 69 +++++++++++++++------------
 1 file changed, 39 insertions(+), 30 deletions(-)

diff --git a/t/t7501-commit-basic-functionality.sh b/t/t7501-commit-basic-functionality.sh
index 5765d33c53..110b4bf459 100755
--- a/t/t7501-commit-basic-functionality.sh
+++ b/t/t7501-commit-basic-functionality.sh
@@ -285,9 +285,8 @@ test_expect_success 'overriding author from command line' '
 '
 
 test_expect_success PERL 'interactive add' '
-	echo 7 |
-	git commit --interactive |
-	grep "What now"
+	echo 7 | test_must_fail git commit --interactive >out &&
+	grep "What now" out
 '
 
 test_expect_success PERL "commit --interactive doesn't change index if editor aborts" '
@@ -362,10 +361,10 @@ test_expect_success 'amend commit to fix author' '
 	oldtick=$GIT_AUTHOR_DATE &&
 	test_tick &&
 	git reset --hard &&
-	git cat-file -p HEAD |
+	git cat-file -p HEAD >commit &&
 	sed -e "s/author.*/author $author $oldtick/" \
-		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
-		expected &&
+		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" \
+		commit >expected &&
 	git commit --amend --author="$author" &&
 	git cat-file -p HEAD >current &&
 	test_cmp expected current
@@ -377,10 +376,10 @@ test_expect_success 'amend commit to fix date' '
 	test_tick &&
 	newtick=$GIT_AUTHOR_DATE &&
 	git reset --hard &&
-	git cat-file -p HEAD |
+	git cat-file -p HEAD >commit &&
 	sed -e "s/author.*/author $author $newtick/" \
-		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
-		expected &&
+		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" \
+		commit >expected &&
 	git commit --amend --date="$newtick" &&
 	git cat-file -p HEAD >current &&
 	test_cmp expected current
@@ -409,12 +408,13 @@ test_expect_success 'sign off (1)' '
 	echo 1 >positive &&
 	git add positive &&
 	git commit -s -m "thank you" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
+	git cat-file commit HEAD >commit &&
+	sed -e "1,/^\$/d" commit >actual &&
 	(
 		echo thank you &&
 		echo &&
-		git var GIT_COMMITTER_IDENT |
-		sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
+		git var GIT_COMMITTER_IDENT >ident &&
+		sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" ident
 	) >expected &&
 	test_cmp expected actual
 
@@ -428,13 +428,14 @@ test_expect_success 'sign off (2)' '
 	git commit -s -m "thank you
 
 $existing" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
+	git cat-file commit HEAD >commit &&
+	sed -e "1,/^\$/d" commit >actual &&
 	(
 		echo thank you &&
 		echo &&
 		echo $existing &&
-		git var GIT_COMMITTER_IDENT |
-		sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
+		git var GIT_COMMITTER_IDENT >ident &&
+		sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" ident
 	) >expected &&
 	test_cmp expected actual
 
@@ -448,13 +449,14 @@ test_expect_success 'signoff gap' '
 	git commit -s -m "welcome
 
 $alt" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
+	git cat-file commit HEAD >commit &&
+	sed -e "1,/^\$/d" commit >actual &&
 	(
 		echo welcome &&
 		echo &&
 		echo $alt &&
-		git var GIT_COMMITTER_IDENT |
-		sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
+		git var GIT_COMMITTER_IDENT >ident &&
+		sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" ident
 	) >expected &&
 	test_cmp expected actual
 '
@@ -468,15 +470,16 @@ test_expect_success 'signoff gap 2' '
 
 We have now
 $alt" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
+	git cat-file commit HEAD >commit &&
+	sed -e "1,/^\$/d" commit >actual &&
 	(
 		echo welcome &&
 		echo &&
 		echo We have now &&
 		echo $alt &&
 		echo &&
-		git var GIT_COMMITTER_IDENT |
-		sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
+		git var GIT_COMMITTER_IDENT >ident &&
+		sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" ident
 	) >expected &&
 	test_cmp expected actual
 '
@@ -489,7 +492,8 @@ test_expect_success 'signoff respects trailer config' '
 
 non-trailer line
 Myfooter: x" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
+	git cat-file commit HEAD >commit &&
+	sed -e "1,/^\$/d" commit >actual &&
 	(
 		echo subject &&
 		echo &&
@@ -506,7 +510,8 @@ Myfooter: x" &&
 
 non-trailer line
 Myfooter: x" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
+	git cat-file commit HEAD >commit &&
+	sed -e "1,/^\$/d" commit >actual &&
 	(
 		echo subject &&
 		echo &&
@@ -538,7 +543,8 @@ test_expect_success 'multiple -m' '
 	>negative &&
 	git add negative &&
 	git commit -m "one" -m "two" -m "three" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
+	git cat-file commit HEAD >commit &&
+	sed -e "1,/^\$/d" commit >actual &&
 	(
 		echo one &&
 		echo &&
@@ -555,10 +561,10 @@ test_expect_success 'amend commit to fix author' '
 	oldtick=$GIT_AUTHOR_DATE &&
 	test_tick &&
 	git reset --hard &&
-	git cat-file -p HEAD |
+	git cat-file -p HEAD >commit &&
 	sed -e "s/author.*/author $author $oldtick/" \
-		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
-		expected &&
+		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" \
+		commit >expected &&
 	git commit --amend --author="$author" &&
 	git cat-file -p HEAD >current &&
 	test_cmp expected current
@@ -570,8 +576,10 @@ test_expect_success 'git commit <file> with dirty index' '
 	echo tehlulz >chz &&
 	git add chz &&
 	git commit elif -m "tacocat is a palindrome" &&
-	git show --stat | grep elif &&
-	git diff --cached | grep chz
+	git show --stat >stat &&
+	grep elif stat &&
+	git diff --cached >diff &&
+	grep chz diff
 '
 
 test_expect_success 'same tree (single parent)' '
@@ -584,7 +592,8 @@ test_expect_success 'same tree (single parent)' '
 test_expect_success 'same tree (single parent) --allow-empty' '
 
 	git commit --allow-empty -m "forced empty" &&
-	git cat-file commit HEAD | grep forced
+	git cat-file commit HEAD >commit &&
+	grep forced commit
 
 '
 
-- 
2.24.0.497.g17aadd8971


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v3 18/22] t7700: drop redirections to /dev/null
  2019-11-22 18:59   ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                       ` (16 preceding siblings ...)
  2019-11-22 19:00     ` [PATCH v3 17/22] t7501: stop losing return codes of git commands Denton Liu
@ 2019-11-22 19:00     ` Denton Liu
  2019-11-22 19:00     ` [PATCH v3 19/22] t7700: remove spaces after redirect operators Denton Liu
                       ` (4 subsequent siblings)
  22 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-22 19:00 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Since output is silenced when running without `-v` and debugging output
is useful with `-v`, remove redirections to /dev/null as it is not
useful.

In one case where the output of stdout is consumed, redirect the output
of test_commit to stderr.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7700-repack.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index 4e855bc21b..e1a689d6a9 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -5,7 +5,7 @@ test_description='git repack works correctly'
 . ./test-lib.sh
 
 commit_and_pack() {
-	test_commit "$@" >/dev/null &&
+	test_commit "$@" 1>&2 &&
 	SHA1=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) &&
 	echo pack-${SHA1}.pack
 }
@@ -19,7 +19,7 @@ test_expect_success 'objects in packs marked .keep are not repacked' '
 	# Create two packs
 	# The first pack will contain all of the objects except one
 	git rev-list --objects --all | grep -v file2 |
-		git pack-objects pack > /dev/null &&
+		git pack-objects pack &&
 	# The second pack will contain the excluded object
 	packsha1=$(git rev-list --objects --all | grep file2 |
 		git pack-objects pack) &&
@@ -235,7 +235,7 @@ test_expect_success 'incremental repack does not complain' '
 
 test_expect_success 'bitmaps can be disabled on bare repos' '
 	git -c repack.writeBitmaps=false -C bare.git repack -ad &&
-	bitmap=$(ls bare.git/objects/pack/*.bitmap 2>/dev/null || :) &&
+	bitmap=$(ls bare.git/objects/pack/*.bitmap || :) &&
 	test -z "$bitmap"
 '
 
-- 
2.24.0.497.g17aadd8971


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v3 19/22] t7700: remove spaces after redirect operators
  2019-11-22 18:59   ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                       ` (17 preceding siblings ...)
  2019-11-22 19:00     ` [PATCH v3 18/22] t7700: drop redirections to /dev/null Denton Liu
@ 2019-11-22 19:00     ` Denton Liu
  2019-11-22 19:00     ` [PATCH v3 20/22] t7700: move keywords onto their own line Denton Liu
                       ` (3 subsequent siblings)
  22 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-22 19:00 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

For shell scripts, the usual convention is for there to be no space
after redirection operators, (e.g. `>file`, not `> file`). Remove these
spaces wherever they appear.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7700-repack.sh | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index e1a689d6a9..8936928387 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -11,8 +11,8 @@ commit_and_pack() {
 }
 
 test_expect_success 'objects in packs marked .keep are not repacked' '
-	echo content1 > file1 &&
-	echo content2 > file2 &&
+	echo content1 >file1 &&
+	echo content2 >file2 &&
 	git add . &&
 	test_tick &&
 	git commit -m initial_commit &&
@@ -75,8 +75,8 @@ test_expect_success 'writing bitmaps via config can duplicate .keep objects' '
 
 test_expect_success 'loose objects in alternate ODB are not repacked' '
 	mkdir alt_objects &&
-	echo $(pwd)/alt_objects > .git/objects/info/alternates &&
-	echo content3 > file3 &&
+	echo $(pwd)/alt_objects >.git/objects/info/alternates &&
+	echo content3 >file3 &&
 	objsha1=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) &&
 	git add file3 &&
 	test_tick &&
@@ -111,7 +111,7 @@ test_expect_success 'packed obs in alt ODB are repacked even when local repo is
 
 test_expect_success 'packed obs in alt ODB are repacked when local repo has packs' '
 	rm -f .git/objects/pack/* &&
-	echo new_content >> file1 &&
+	echo new_content >>file1 &&
 	git add file1 &&
 	test_tick &&
 	git commit -m more_content &&
@@ -169,12 +169,12 @@ test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
 	mv pack-* .git/objects/pack/ &&
 	test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
 		egrep "^$csha1 " | sort | uniq | wc -l) &&
-	echo > .git/objects/info/alternates &&
+	echo >.git/objects/info/alternates &&
 	test_must_fail git show $csha1
 '
 
 test_expect_success 'local packed unreachable obs that exist in alternate ODB are not loosened' '
-	echo $(pwd)/alt_objects > .git/objects/info/alternates &&
+	echo $(pwd)/alt_objects >.git/objects/info/alternates &&
 	echo "$csha1" | git pack-objects --non-empty --all --reflog pack &&
 	rm -f .git/objects/pack/* &&
 	mv pack-* .git/objects/pack/ &&
@@ -186,7 +186,7 @@ test_expect_success 'local packed unreachable obs that exist in alternate ODB ar
 	mv pack-* .git/objects/pack/ &&
 	test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
 		egrep "^$csha1 " | sort | uniq | wc -l) &&
-	echo > .git/objects/info/alternates &&
+	echo >.git/objects/info/alternates &&
 	test_must_fail git show $csha1
 '
 
@@ -196,7 +196,7 @@ test_expect_success 'objects made unreachable by grafts only are kept' '
 	H0=$(git rev-parse HEAD) &&
 	H1=$(git rev-parse HEAD^) &&
 	H2=$(git rev-parse HEAD^^) &&
-	echo "$H0 $H2" > .git/info/grafts &&
+	echo "$H0 $H2" >.git/info/grafts &&
 	git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all &&
 	git repack -a -d &&
 	git cat-file -t $H1
-- 
2.24.0.497.g17aadd8971


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v3 20/22] t7700: move keywords onto their own line
  2019-11-22 18:59   ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                       ` (18 preceding siblings ...)
  2019-11-22 19:00     ` [PATCH v3 19/22] t7700: remove spaces after redirect operators Denton Liu
@ 2019-11-22 19:00     ` Denton Liu
  2019-11-22 19:00     ` [PATCH v3 21/22] t7700: s/test -f/test_path_is_file/ Denton Liu
                       ` (2 subsequent siblings)
  22 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-22 19:00 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

The code style for tests is to have statements on their own line if
possible. Move keywords onto their own line so that they conform with
the test style.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7700-repack.sh | 51 +++++++++++++++++++++++++++++++----------------
 1 file changed, 34 insertions(+), 17 deletions(-)

diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index 8936928387..a96e876c4e 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -29,10 +29,12 @@ test_expect_success 'objects in packs marked .keep are not repacked' '
 	mv pack-* .git/objects/pack/ &&
 	git repack -A -d -l &&
 	git prune-packed &&
-	for p in .git/objects/pack/*.idx; do
+	for p in .git/objects/pack/*.idx
+	do
 		idx=$(basename $p)
 		test "pack-$packsha1.idx" = "$idx" && continue
-		if git verify-pack -v $p | egrep "^$objsha1"; then
+		if git verify-pack -v $p | egrep "^$objsha1"
+		then
 			found_duplicate_object=1
 			echo "DUPLICATE OBJECT FOUND"
 			break
@@ -45,10 +47,12 @@ test_expect_success 'writing bitmaps via command-line can duplicate .keep object
 	# build on $objsha1, $packsha1, and .keep state from previous
 	git repack -Adbl &&
 	test_when_finished "found_duplicate_object=" &&
-	for p in .git/objects/pack/*.idx; do
+	for p in .git/objects/pack/*.idx
+	do
 		idx=$(basename $p)
 		test "pack-$packsha1.idx" = "$idx" && continue
-		if git verify-pack -v $p | egrep "^$objsha1"; then
+		if git verify-pack -v $p | egrep "^$objsha1"
+		then
 			found_duplicate_object=1
 			echo "DUPLICATE OBJECT FOUND"
 			break
@@ -61,10 +65,12 @@ test_expect_success 'writing bitmaps via config can duplicate .keep objects' '
 	# build on $objsha1, $packsha1, and .keep state from previous
 	git -c repack.writebitmaps=true repack -Adl &&
 	test_when_finished "found_duplicate_object=" &&
-	for p in .git/objects/pack/*.idx; do
+	for p in .git/objects/pack/*.idx
+	do
 		idx=$(basename $p)
 		test "pack-$packsha1.idx" = "$idx" && continue
-		if git verify-pack -v $p | egrep "^$objsha1"; then
+		if git verify-pack -v $p | egrep "^$objsha1"
+		then
 			found_duplicate_object=1
 			echo "DUPLICATE OBJECT FOUND"
 			break
@@ -83,8 +89,10 @@ test_expect_success 'loose objects in alternate ODB are not repacked' '
 	git commit -m commit_file3 &&
 	git repack -a -d -l &&
 	git prune-packed &&
-	for p in .git/objects/pack/*.idx; do
-		if git verify-pack -v $p | egrep "^$objsha1"; then
+	for p in .git/objects/pack/*.idx
+	do
+		if git verify-pack -v $p | egrep "^$objsha1"
+		then
 			found_duplicate_object=1
 			echo "DUPLICATE OBJECT FOUND"
 			break
@@ -99,10 +107,13 @@ test_expect_success 'packed obs in alt ODB are repacked even when local repo is
 	git repack -a &&
 	myidx=$(ls -1 .git/objects/pack/*.idx) &&
 	test -f "$myidx" &&
-	for p in alt_objects/pack/*.idx; do
+	for p in alt_objects/pack/*.idx
+	do
 		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
-	done | while read sha1 rest; do
-		if ! ( git verify-pack -v $myidx | grep "^$sha1" ); then
+	done | while read sha1 rest
+	do
+		if ! ( git verify-pack -v $myidx | grep "^$sha1" )
+		then
 			echo "Missing object in local pack: $sha1"
 			return 1
 		fi
@@ -119,10 +130,13 @@ test_expect_success 'packed obs in alt ODB are repacked when local repo has pack
 	git repack -a -d &&
 	myidx=$(ls -1 .git/objects/pack/*.idx) &&
 	test -f "$myidx" &&
-	for p in alt_objects/pack/*.idx; do
+	for p in alt_objects/pack/*.idx
+	do
 		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
-	done | while read sha1 rest; do
-		if ! ( git verify-pack -v $myidx | grep "^$sha1" ); then
+	done | while read sha1 rest
+	do
+		if ! ( git verify-pack -v $myidx | grep "^$sha1" )
+		then
 			echo "Missing object in local pack: $sha1"
 			return 1
 		fi
@@ -144,10 +158,13 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
 	git repack -a -d &&
 	myidx=$(ls -1 .git/objects/pack/*.idx) &&
 	test -f "$myidx" &&
-	for p in alt_objects/pack/*.idx; do
+	for p in alt_objects/pack/*.idx
+	do
 		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
-	done | while read sha1 rest; do
-		if ! ( git verify-pack -v $myidx | grep "^$sha1" ); then
+	done | while read sha1 rest
+	do
+		if ! ( git verify-pack -v $myidx | grep "^$sha1" )
+		then
 			echo "Missing object in local pack: $sha1"
 			return 1
 		fi
-- 
2.24.0.497.g17aadd8971


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v3 21/22] t7700: s/test -f/test_path_is_file/
  2019-11-22 18:59   ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                       ` (19 preceding siblings ...)
  2019-11-22 19:00     ` [PATCH v3 20/22] t7700: move keywords onto their own line Denton Liu
@ 2019-11-22 19:00     ` Denton Liu
  2019-11-22 19:00     ` [PATCH v3 22/22] t7700: stop losing return codes of git commands Denton Liu
  2019-11-26  1:17     ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
  22 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-22 19:00 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Since we have debugging-friendly alternatives to `test -f`, replace
instances of `test -f` with `test_path_is_file` so that if a command
ever fails, we get better debugging information.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7700-repack.sh | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index a96e876c4e..1d14ddcbdb 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -106,7 +106,7 @@ test_expect_success 'packed obs in alt ODB are repacked even when local repo is
 	mv .git/objects/pack/* alt_objects/pack &&
 	git repack -a &&
 	myidx=$(ls -1 .git/objects/pack/*.idx) &&
-	test -f "$myidx" &&
+	test_path_is_file "$myidx" &&
 	for p in alt_objects/pack/*.idx
 	do
 		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
@@ -129,7 +129,7 @@ test_expect_success 'packed obs in alt ODB are repacked when local repo has pack
 	git repack &&
 	git repack -a -d &&
 	myidx=$(ls -1 .git/objects/pack/*.idx) &&
-	test -f "$myidx" &&
+	test_path_is_file "$myidx" &&
 	for p in alt_objects/pack/*.idx
 	do
 		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
@@ -148,7 +148,7 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
 	for p in alt_objects/pack/*.pack
 	do
 		base_name=$(basename $p .pack) &&
-		if test -f alt_objects/pack/$base_name.keep
+		if test_path_is_file alt_objects/pack/$base_name.keep
 		then
 			rm alt_objects/pack/$base_name.keep
 		else
@@ -157,7 +157,7 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
 	done &&
 	git repack -a -d &&
 	myidx=$(ls -1 .git/objects/pack/*.idx) &&
-	test -f "$myidx" &&
+	test_path_is_file "$myidx" &&
 	for p in alt_objects/pack/*.idx
 	do
 		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
-- 
2.24.0.497.g17aadd8971


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v3 22/22] t7700: stop losing return codes of git commands
  2019-11-22 18:59   ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                       ` (20 preceding siblings ...)
  2019-11-22 19:00     ` [PATCH v3 21/22] t7700: s/test -f/test_path_is_file/ Denton Liu
@ 2019-11-22 19:00     ` Denton Liu
  2019-11-23  1:49       ` Junio C Hamano
  2019-11-26  1:17     ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
  22 siblings, 1 reply; 169+ messages in thread
From: Denton Liu @ 2019-11-22 19:00 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

In a pipe, only the return code of the last command is used. Thus, all
other commands will have their return codes masked. Rewrite pipes so
that there are no git commands upstream so that we will know if a
command fails.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7700-repack.sh | 64 ++++++++++++++++++++++++++++-------------------
 1 file changed, 38 insertions(+), 26 deletions(-)

diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index 1d14ddcbdb..ff50722e26 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -18,14 +18,13 @@ test_expect_success 'objects in packs marked .keep are not repacked' '
 	git commit -m initial_commit &&
 	# Create two packs
 	# The first pack will contain all of the objects except one
-	git rev-list --objects --all | grep -v file2 |
-		git pack-objects pack &&
+	git rev-list --objects --all >objs &&
+	grep -v file2 objs | git pack-objects pack &&
 	# The second pack will contain the excluded object
-	packsha1=$(git rev-list --objects --all | grep file2 |
-		git pack-objects pack) &&
+	packsha1=$(grep file2 objs | git pack-objects pack) &&
 	>pack-$packsha1.keep &&
-	objsha1=$(git verify-pack -v pack-$packsha1.idx | head -n 1 |
-		sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") &&
+	git verify-pack -v pack-$packsha1.idx >packlist &&
+	objsha1=$(head -n 1 packlist | sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") &&
 	mv pack-* .git/objects/pack/ &&
 	git repack -A -d -l &&
 	git prune-packed &&
@@ -33,7 +32,8 @@ test_expect_success 'objects in packs marked .keep are not repacked' '
 	do
 		idx=$(basename $p)
 		test "pack-$packsha1.idx" = "$idx" && continue
-		if git verify-pack -v $p | egrep "^$objsha1"
+		git verify-pack -v $p >packlist || return $?
+		if egrep "^$objsha1" packlist
 		then
 			found_duplicate_object=1
 			echo "DUPLICATE OBJECT FOUND"
@@ -51,7 +51,8 @@ test_expect_success 'writing bitmaps via command-line can duplicate .keep object
 	do
 		idx=$(basename $p)
 		test "pack-$packsha1.idx" = "$idx" && continue
-		if git verify-pack -v $p | egrep "^$objsha1"
+		git verify-pack -v $p >packlist || return $?
+		if egrep "^$objsha1" packlist
 		then
 			found_duplicate_object=1
 			echo "DUPLICATE OBJECT FOUND"
@@ -69,7 +70,8 @@ test_expect_success 'writing bitmaps via config can duplicate .keep objects' '
 	do
 		idx=$(basename $p)
 		test "pack-$packsha1.idx" = "$idx" && continue
-		if git verify-pack -v $p | egrep "^$objsha1"
+		git verify-pack -v $p >packlist || return $?
+		if egrep "^$objsha1" packlist
 		then
 			found_duplicate_object=1
 			echo "DUPLICATE OBJECT FOUND"
@@ -91,7 +93,8 @@ test_expect_success 'loose objects in alternate ODB are not repacked' '
 	git prune-packed &&
 	for p in .git/objects/pack/*.idx
 	do
-		if git verify-pack -v $p | egrep "^$objsha1"
+		git verify-pack -v $p >packlist || return $?
+		if egrep "^$objsha1" packlist
 		then
 			found_duplicate_object=1
 			echo "DUPLICATE OBJECT FOUND"
@@ -109,15 +112,18 @@ test_expect_success 'packed obs in alt ODB are repacked even when local repo is
 	test_path_is_file "$myidx" &&
 	for p in alt_objects/pack/*.idx
 	do
-		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
-	done | while read sha1 rest
+		git verify-pack -v $p >packlist || return $?
+		sed -n -e "/^[0-9a-f]\{40\}/p"
+	done >packs &&
+	git verify-pack -v $myidx >mypacklist &&
+	while read sha1 rest
 	do
-		if ! ( git verify-pack -v $myidx | grep "^$sha1" )
+		if ! grep "^$sha1" mypacklist
 		then
 			echo "Missing object in local pack: $sha1"
 			return 1
 		fi
-	done
+	done <packs
 '
 
 test_expect_success 'packed obs in alt ODB are repacked when local repo has packs' '
@@ -132,15 +138,18 @@ test_expect_success 'packed obs in alt ODB are repacked when local repo has pack
 	test_path_is_file "$myidx" &&
 	for p in alt_objects/pack/*.idx
 	do
-		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
-	done | while read sha1 rest
+		git verify-pack -v $p >packlist || return $?
+		sed -n -e "/^[0-9a-f]\{40\}/p" packlist
+	done >packs &&
+	git verify-pack -v $myidx >mypacklist &&
+	while read sha1 rest
 	do
-		if ! ( git verify-pack -v $myidx | grep "^$sha1" )
+		if ! grep "^$sha1" mypacklist
 		then
 			echo "Missing object in local pack: $sha1"
 			return 1
 		fi
-	done
+	done <packs
 '
 
 test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
@@ -160,15 +169,18 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
 	test_path_is_file "$myidx" &&
 	for p in alt_objects/pack/*.idx
 	do
-		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
-	done | while read sha1 rest
+		git verify-pack -v $p >packlist || return $?
+		sed -n -e "/^[0-9a-f]\{40\}/p" packlist
+	done >packs &&
+	git verify-pack -v $myidx >mypacklist &&
+	while read sha1 rest
 	do
-		if ! ( git verify-pack -v $myidx | grep "^$sha1" )
+		if ! grep "^$sha1" mypacklist
 		then
 			echo "Missing object in local pack: $sha1"
 			return 1
 		fi
-	done
+	done <packs
 '
 
 test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
@@ -184,8 +196,8 @@ test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
 	    --unpack-unreachable </dev/null pack &&
 	rm -f .git/objects/pack/* &&
 	mv pack-* .git/objects/pack/ &&
-	test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
-		egrep "^$csha1 " | sort | uniq | wc -l) &&
+	git verify-pack -v -- .git/objects/pack/*.idx >packlist &&
+	! egrep "^$csha1 " packlist &&
 	echo >.git/objects/info/alternates &&
 	test_must_fail git show $csha1
 '
@@ -201,8 +213,8 @@ test_expect_success 'local packed unreachable obs that exist in alternate ODB ar
 	    --unpack-unreachable </dev/null pack &&
 	rm -f .git/objects/pack/* &&
 	mv pack-* .git/objects/pack/ &&
-	test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
-		egrep "^$csha1 " | sort | uniq | wc -l) &&
+	git verify-pack -v -- .git/objects/pack/*.idx >packlist &&
+	! egrep "^$csha1 " &&
 	echo >.git/objects/info/alternates &&
 	test_must_fail git show $csha1
 '
-- 
2.24.0.497.g17aadd8971


^ permalink raw reply	[flat|nested] 169+ messages in thread

* Re: [PATCH v3 02/22] apply-one-time-sed.sh: modernize style
  2019-11-22 18:59     ` [PATCH v3 02/22] apply-one-time-sed.sh: modernize style Denton Liu
@ 2019-11-23  1:32       ` Junio C Hamano
  0 siblings, 0 replies; 169+ messages in thread
From: Junio C Hamano @ 2019-11-23  1:32 UTC (permalink / raw)
  To: Denton Liu; +Cc: Git Mailing List, Eric Sunshine, Jeff King

Denton Liu <liu.denton@gmail.com> writes:

> Convert `[ ... ]` to use `test`.
>
> Move the `then`s onto their own lines so that it conforms with the
> general test style.
>
> Instead of redirecting input into sed, allow it to open its own input.
>
> Signed-off-by: Denton Liu <liu.denton@gmail.com>
> ---
>  t/lib-httpd/apply-one-time-sed.sh | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)

This one is new in this round.  As a conversion to match the style
guidelines, it looks OK, but the original feels a bit substandard in
other ways, e.g. I would have said "if one-time-sed is a file",
instead of "if one-time-sed exists as any kind of filesystem
entity", and used "cmp -s out out_modified" instead of "diff", which
is an overkill if you want to merely learn if two things are equal.

Wait.  If we are to see if A and B are the same, and show A when
they are the same and otherwise show B, wouldn't it be much simpler
to do without comparison and always show B unconditionally instead?

What am I missing?

Ah, there is one extra command in the "else" clause that we cannot
see in the post-context.  So, sorry for the noise---don't wait ;-)

But all the other things before the "Wait" still stands.

Thanks.

> diff --git a/t/lib-httpd/apply-one-time-sed.sh b/t/lib-httpd/apply-one-time-sed.sh
> index fcef728925..3e9a615311 100644
> --- a/t/lib-httpd/apply-one-time-sed.sh
> +++ b/t/lib-httpd/apply-one-time-sed.sh
> @@ -7,11 +7,13 @@
>  #
>  # This can be used to simulate the effects of the repository changing in
>  # between HTTP request-response pairs.
> -if [ -e one-time-sed ]; then
> +if test -e one-time-sed
> +then
>  	"$GIT_EXEC_PATH/git-http-backend" >out
> -	sed "$(cat one-time-sed)" <out >out_modified
> +	sed "$(cat one-time-sed)" out >out_modified
>  
> -	if diff out out_modified >/dev/null; then
> +	if diff out out_modified >/dev/null
> +	then
>  		cat out
>  	else
>  		cat out_modified

^ permalink raw reply	[flat|nested] 169+ messages in thread

* Re: [PATCH v3 22/22] t7700: stop losing return codes of git commands
  2019-11-22 19:00     ` [PATCH v3 22/22] t7700: stop losing return codes of git commands Denton Liu
@ 2019-11-23  1:49       ` Junio C Hamano
  2019-11-25 23:57         ` Denton Liu
  0 siblings, 1 reply; 169+ messages in thread
From: Junio C Hamano @ 2019-11-23  1:49 UTC (permalink / raw)
  To: Denton Liu; +Cc: Git Mailing List, Eric Sunshine, Jeff King

Denton Liu <liu.denton@gmail.com> writes:

> -	objsha1=$(git verify-pack -v pack-$packsha1.idx | head -n 1 |
> -		sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") &&
> +	git verify-pack -v pack-$packsha1.idx >packlist &&
> +	objsha1=$(head -n 1 packlist | sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") &&

We probably should lose reference to SHA-1 and use $OID_REGEX; this
is obviously a #leftoverbits material that is outside the scope of
this series.

> @@ -91,7 +93,8 @@ test_expect_success 'loose objects in alternate ODB are not repacked' '
>  	git prune-packed &&
>  	for p in .git/objects/pack/*.idx
>  	do
> -		if git verify-pack -v $p | egrep "^$objsha1"
> +		git verify-pack -v $p >packlist || return $?
> +		if egrep "^$objsha1" packlist
>  		then
>  			found_duplicate_object=1
>  			echo "DUPLICATE OBJECT FOUND"

These egrep that try to match lines that begin with an object name
can be a simple grep instead (again, outside the scope of this
series).

> @@ -109,15 +112,18 @@ test_expect_success 'packed obs in alt ODB are repacked even when local repo is
>  	test_path_is_file "$myidx" &&
>  	for p in alt_objects/pack/*.idx
>  	do
> -		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
> -	done | while read sha1 rest
> +		git verify-pack -v $p >packlist || return $?
> +		sed -n -e "/^[0-9a-f]\{40\}/p"
> +	done >packs &&

A misleading filename?  The lines in this file are not pack files;
rather the file has a list of objects in various packs.

> +	git verify-pack -v $myidx >mypacklist &&
> +	while read sha1 rest
>  	do
> -		if ! ( git verify-pack -v $myidx | grep "^$sha1" )
> +		if ! grep "^$sha1" mypacklist
>  		then
>  			echo "Missing object in local pack: $sha1"
>  			return 1
>  		fi
> -	done
> +	done <packs
>  '

Again outside the scope of this series, but this looks O(n^2)
to me.

If I were writing this today, I would prepare a sorted list of all
object names (and nothing else on each line) in alt_objects/pack/ in
one file (call it 'orig'), and prepare another file with a sorted
list of all object names described in $myidx (call it 'dest'), and
then run "comm -23 orig dest" and see if there is anything that is
unique in the 'orig' file (i.e. something in 'orig' is missing from
'dest').

> @@ -132,15 +138,18 @@ test_expect_success 'packed obs in alt ODB are repacked when local repo has pack
>  	test_path_is_file "$myidx" &&
>  	for p in alt_objects/pack/*.idx
>  	do
> -		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
> -	done | while read sha1 rest
> +		git verify-pack -v $p >packlist || return $?
> +		sed -n -e "/^[0-9a-f]\{40\}/p" packlist
> +	done >packs &&
> +	git verify-pack -v $myidx >mypacklist &&
> +	while read sha1 rest
>  	do
> -		if ! ( git verify-pack -v $myidx | grep "^$sha1" )
> +		if ! grep "^$sha1" mypacklist
>  		then
>  			echo "Missing object in local pack: $sha1"
>  			return 1
>  		fi
> -	done
> +	done <packs
>  '

Likewise.

> @@ -160,15 +169,18 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
>  	test_path_is_file "$myidx" &&
>  	for p in alt_objects/pack/*.idx
>  	do
> -		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
> -	done | while read sha1 rest
> +		git verify-pack -v $p >packlist || return $?
> +		sed -n -e "/^[0-9a-f]\{40\}/p" packlist
> +	done >packs &&
> +	git verify-pack -v $myidx >mypacklist &&
> +	while read sha1 rest
>  	do
> -		if ! ( git verify-pack -v $myidx | grep "^$sha1" )
> +		if ! grep "^$sha1" mypacklist
>  		then
>  			echo "Missing object in local pack: $sha1"
>  			return 1
>  		fi
> -	done
> +	done <packs
>  '

Likewise.


^ permalink raw reply	[flat|nested] 169+ messages in thread

* Re: [PATCH v3 13/22] t5317: use ! grep to check for no matching lines
  2019-11-22 19:00     ` [PATCH v3 13/22] t5317: use ! grep to check for no matching lines Denton Liu
@ 2019-11-23  6:21       ` Eric Sunshine
  2019-11-25 21:43         ` Denton Liu
  0 siblings, 1 reply; 169+ messages in thread
From: Eric Sunshine @ 2019-11-23  6:21 UTC (permalink / raw)
  To: Denton Liu; +Cc: Git Mailing List, Junio C Hamano, Jeff King

On Fri, Nov 22, 2019 at 2:00 PM Denton Liu <liu.denton@gmail.com> wrote:
> [...]
> While at it, drop unnecessary invocations of 'awk' and 'sort' in each
> affected test since those commands do not influence the outcome. It's
> not clear why that extra work was being done in the first place, and the
> code's history doesn't shed any light on the matter since these tests
> were simply born this way[1], doing all the unnecessary work for no
> reason, probably due to copy/paste programming...

Taking this wording literally from my review comment[1] is (again)
fine, but I ended the fragment intentionally with "..." with the
expectation that you would fill in the remainder, not expecting you to
copy/paste the fragment blindly. Without the remainder -- the part
which is supposed to follow the "..." -- the reader if left hanging.

[1]: https://lore.kernel.org/git/CAPig+cQviTjwLSZ+QkC62B58mq6z3yDA-XhPVJQYRq0inEo9nA@mail.gmail.com/

^ permalink raw reply	[flat|nested] 169+ messages in thread

* Re: [PATCH v3 13/22] t5317: use ! grep to check for no matching lines
  2019-11-23  6:21       ` Eric Sunshine
@ 2019-11-25 21:43         ` Denton Liu
  0 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-25 21:43 UTC (permalink / raw)
  To: Eric Sunshine; +Cc: Git Mailing List, Junio C Hamano, Jeff King

Hi Eric,

On Sat, Nov 23, 2019 at 01:21:29AM -0500, Eric Sunshine wrote:
> On Fri, Nov 22, 2019 at 2:00 PM Denton Liu <liu.denton@gmail.com> wrote:
> > [...]
> > While at it, drop unnecessary invocations of 'awk' and 'sort' in each
> > affected test since those commands do not influence the outcome. It's
> > not clear why that extra work was being done in the first place, and the
> > code's history doesn't shed any light on the matter since these tests
> > were simply born this way[1], doing all the unnecessary work for no
> > reason, probably due to copy/paste programming...
> 
> Taking this wording literally from my review comment[1] is (again)
> fine, but I ended the fragment intentionally with "..." with the
> expectation that you would fill in the remainder, not expecting you to
> copy/paste the fragment blindly. Without the remainder -- the part
> which is supposed to follow the "..." -- the reader if left hanging.

My mistake, I interpreted the "..." as a stylistic writing choice as
opposed to an indication for me to fill it in. I'll fix it up for the
next round.

Thanks,

Denton

> 
> [1]: https://lore.kernel.org/git/CAPig+cQviTjwLSZ+QkC62B58mq6z3yDA-XhPVJQYRq0inEo9nA@mail.gmail.com/

^ permalink raw reply	[flat|nested] 169+ messages in thread

* Re: [PATCH v3 22/22] t7700: stop losing return codes of git commands
  2019-11-23  1:49       ` Junio C Hamano
@ 2019-11-25 23:57         ` Denton Liu
  2019-11-26  0:58           ` Eric Sunshine
  0 siblings, 1 reply; 169+ messages in thread
From: Denton Liu @ 2019-11-25 23:57 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git Mailing List, Eric Sunshine, Jeff King

Hi Junio,

On Sat, Nov 23, 2019 at 10:49:44AM +0900, Junio C Hamano wrote:
> Denton Liu <liu.denton@gmail.com> writes:
> 
> > -	objsha1=$(git verify-pack -v pack-$packsha1.idx | head -n 1 |
> > -		sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") &&
> > +	git verify-pack -v pack-$packsha1.idx >packlist &&
> > +	objsha1=$(head -n 1 packlist | sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") &&
> 
> We probably should lose reference to SHA-1 and use $OID_REGEX; this
> is obviously a #leftoverbits material that is outside the scope of
> this series.

Since the theme of this series is test cleanup, I believe that it's
probably appropriate to roll these changes (and the ones below that I
omitted) into the current series. Since it isn't too much work, I'll
send them out in my next reroll.

^ permalink raw reply	[flat|nested] 169+ messages in thread

* Re: [PATCH v3 22/22] t7700: stop losing return codes of git commands
  2019-11-25 23:57         ` Denton Liu
@ 2019-11-26  0:58           ` Eric Sunshine
  2019-11-26  1:34             ` Junio C Hamano
  0 siblings, 1 reply; 169+ messages in thread
From: Eric Sunshine @ 2019-11-26  0:58 UTC (permalink / raw)
  To: Denton Liu; +Cc: Junio C Hamano, Git Mailing List, Jeff King

On Mon, Nov 25, 2019 at 6:57 PM Denton Liu <liu.denton@gmail.com> wrote:
> On Sat, Nov 23, 2019 at 10:49:44AM +0900, Junio C Hamano wrote:
> > Denton Liu <liu.denton@gmail.com> writes:
> > > -   objsha1=$(git verify-pack -v pack-$packsha1.idx | head -n 1 |
> > > -           sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") &&
> > > +   git verify-pack -v pack-$packsha1.idx >packlist &&
> > > +   objsha1=$(head -n 1 packlist | sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") &&
> >
> > We probably should lose reference to SHA-1 and use $OID_REGEX; this
> > is obviously a #leftoverbits material that is outside the scope of
> > this series.
>
> Since the theme of this series is test cleanup, I believe that it's
> probably appropriate to roll these changes (and the ones below that I
> omitted) into the current series. Since it isn't too much work, I'll
> send them out in my next reroll.

It may not be too much work for you to keep adding more (unrelated)
changes to a series, but doing so increases the burden on reviewers
unnecessarily, especially for a long patch series such as this one.
Generally speaking, each iteration should help the series converge to
the point at which it can finally land (be merged to "next"). Thus,
ideally, each iteration should have fewer changes than the previous
one.

When you add entirely new changes which are not directly related to
the changes which begat the series, that iteration diverges (not
converges). It creates extra work for reviewers (who are trying to
help you land the series) and makes it less likely that people will
want to review each new iteration since a series which diverges with
each iteration makes the goal of landing the series a moving target
(thus, represents never-ending review work).

^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail
  2019-11-22 18:59   ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                       ` (21 preceding siblings ...)
  2019-11-22 19:00     ` [PATCH v3 22/22] t7700: stop losing return codes of git commands Denton Liu
@ 2019-11-26  1:17     ` Denton Liu
  2019-11-26  1:17       ` [PATCH v4 01/27] lib-bash.sh: move `then` onto its own line Denton Liu
                         ` (27 more replies)
  22 siblings, 28 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-26  1:17 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

These patches perform some general test cleanup to modernise the style.
They should be relatively uncontroversial. The reason these tests were
identified for cleanup was because they failed under `set -o pipefail`.

I've gotten rid of the RFC part that actually enables `set -o pipefail`
on supported platforms. As Peff pointed out, there are a lot of
opportunities for racy SIGPIPE failures so that part still needs a lot
of work to be ironed out.

Those changes shouldn't hold back the first part of the series, however.
Let's try to get this test cleanup merged in sooner than later so that
any new test cases done by copy-paste will have their changes
represented.

Changes since v3:

* More commit message update

* Clean up "apply-one-time-sed.sh: modernize style" more according to
  Junio's suggestions

* Clean up the t7700 leftover bits

Changes since v2:

* Update commit messages according to Eric's suggestions

* Add "apply-one-time-sed.sh: modernize style"

Changes since v1:

* Removed the `set -o pipefail` changes

* Addressed Junio and Eric's comments on the first part of the series

Denton Liu (27):
  lib-bash.sh: move `then` onto its own line
  apply-one-time-sed.sh: modernize style
  t0014: remove git command upstream of pipe
  t0090: stop losing return codes of git commands
  t3301: stop losing return codes of git commands
  t3600: use test_line_count() where possible
  t3600: stop losing return codes of git commands
  t3600: comment on inducing SIGPIPE in `git rm`
  t4015: stop losing return codes of git commands
  t4015: use test_write_lines()
  t4138: stop losing return codes of git commands
  t5317: stop losing return codes of git commands
  t5317: use ! grep to check for no matching lines
  t5703: simplify one-time-sed generation logic
  t5703: stop losing return codes of git commands
  t7501: remove spaces after redirect operators
  t7501: stop losing return codes of git commands
  t7700: drop redirections to /dev/null
  t7700: remove spaces after redirect operators
  t7700: move keywords onto their own line
  t7700: s/test -f/test_path_is_file/
  t7700: consolidate code into test_no_missing_in_packs()
  squash! t7700: consolidate code into test_no_missing_in_packs()
  t7700: consolidate code into test_has_duplicate_object()
  t7700: replace egrep with grep
  t7700: make references to SHA-1 generic
  t7700: stop losing return codes of git commands

 t/lib-bash.sh                          |   6 +-
 t/lib-httpd/apply-one-time-sed.sh      |   8 +-
 t/t0014-alias.sh                       |   4 +-
 t/t0090-cache-tree.sh                  |   5 +-
 t/t3301-notes.sh                       | 230 ++++++++++++++++++-------
 t/t3600-rm.sh                          |  14 +-
 t/t4015-diff-whitespace.sh             | 123 +++++++------
 t/t4138-apply-ws-expansion.sh          |  16 +-
 t/t5317-pack-objects-filter-objects.sh |  34 ++--
 t/t5703-upload-pack-ref-in-want.sh     |  53 +++---
 t/t7501-commit-basic-functionality.sh  |  83 +++++----
 t/t7700-repack.sh                      | 172 ++++++++----------
 12 files changed, 425 insertions(+), 323 deletions(-)

Range-diff against v3:
 1:  9085cc00af =  1:  9085cc00af lib-bash.sh: move `then` onto its own line
 2:  ac4164374d !  2:  86f625c65e apply-one-time-sed.sh: modernize style
    @@ Metadata
      ## Commit message ##
         apply-one-time-sed.sh: modernize style
     
    -    Convert `[ ... ]` to use `test`.
    +    Convert `[ ... ]` to use `test` and test for the existence of a regular
    +    file (`-f`) instead of any file (`-e`).
     
         Move the `then`s onto their own lines so that it conforms with the
         general test style.
     
         Instead of redirecting input into sed, allow it to open its own input.
     
    +    Use `cmp -s` instead of `diff` since we only care about whether the two
    +    files are equal and `diff` is overkill for this.
    +
      ## t/lib-httpd/apply-one-time-sed.sh ##
     @@
      #
      # This can be used to simulate the effects of the repository changing in
      # between HTTP request-response pairs.
     -if [ -e one-time-sed ]; then
    -+if test -e one-time-sed
    ++if test -f one-time-sed
     +then
      	"$GIT_EXEC_PATH/git-http-backend" >out
     -	sed "$(cat one-time-sed)" <out >out_modified
     +	sed "$(cat one-time-sed)" out >out_modified
      
     -	if diff out out_modified >/dev/null; then
    -+	if diff out out_modified >/dev/null
    ++	if cmp -s out out_modified
     +	then
      		cat out
      	else
 3:  b90d68829b =  3:  3844e00367 t0014: remove git command upstream of pipe
 4:  51eaffb283 =  4:  7d33586b21 t0090: stop losing return codes of git commands
 5:  3c6bb9b2f2 =  5:  df6b3393c4 t3301: stop losing return codes of git commands
 6:  7925fa3e43 =  6:  d541a8d4d4 t3600: use test_line_count() where possible
 7:  36be4d0ec1 =  7:  a8aeca6795 t3600: stop losing return codes of git commands
 8:  01fc8518bf =  8:  e3db06578d t3600: comment on inducing SIGPIPE in `git rm`
 9:  b6f6d47c00 =  9:  22ea5d736e t4015: stop losing return codes of git commands
10:  58a1ae76c0 = 10:  a44dd28b4d t4015: use test_write_lines()
11:  07822e3b4c = 11:  d512319be0 t4138: stop losing return codes of git commands
12:  d892a7b181 = 12:  1e08c2b68b t5317: stop losing return codes of git commands
13:  140de46f80 ! 13:  fa238be28b t5317: use ! grep to check for no matching lines
    @@ Commit message
         return code! Use `! grep` in the cases where we are ensuring that there
         are no matching lines.
     
    -    While at it, drop unnecessary invocations of 'awk' and 'sort' in each
    +    While at it, drop unnecessary invocations of `awk` and `sort` in each
         affected test since those commands do not influence the outcome. It's
         not clear why that extra work was being done in the first place, and the
         code's history doesn't shed any light on the matter since these tests
    -    were simply born this way[1], doing all the unnecessary work for no
    -    reason, probably due to copy/paste programming...
    +    were simply born this way[1], likely due to copy-paste programming. The
    +    unnecessary work wasn't noticed even when the code was later touched for
    +    various cleanups[2][3].
     
         [1]: 9535ce7337 (pack-objects: add list-objects filtering, 2017-11-21)
    +    [2]: bdbc17e86a (tests: standardize pipe placement, 2018-10-05)
    +    [3]: 61de0ff695 (tests: don't swallow Git errors upstream of pipes, 2018-10-05)
     
         Helped-by: Eric Sunshine <sunshine@sunshineco.com>
     
14:  6be0d0388d = 14:  291caf9bc1 t5703: simplify one-time-sed generation logic
15:  3844e7372c = 15:  edf7af76ae t5703: stop losing return codes of git commands
16:  d47bb4c9f6 = 16:  5eb7117fbe t7501: remove spaces after redirect operators
17:  9e5ede8eac = 17:  bad732adc8 t7501: stop losing return codes of git commands
18:  18031e67c7 = 18:  c50c192429 t7700: drop redirections to /dev/null
19:  40cd07a57a = 19:  58ae066d12 t7700: remove spaces after redirect operators
20:  049405b49d = 20:  82bf24d06a t7700: move keywords onto their own line
21:  133171522d = 21:  251de77677 t7700: s/test -f/test_path_is_file/
22:  d653869ead <  -:  ---------- t7700: stop losing return codes of git commands
 -:  ---------- > 22:  c98a2a1509 t7700: consolidate code into test_no_missing_in_packs()
 -:  ---------- > 23:  e4ba198483 squash! t7700: consolidate code into test_no_missing_in_packs()
 -:  ---------- > 24:  fa38d7e8f6 t7700: consolidate code into test_has_duplicate_object()
 -:  ---------- > 25:  4f02c00bd1 t7700: replace egrep with grep
 -:  ---------- > 26:  a747fbd08b t7700: make references to SHA-1 generic
 -:  ---------- > 27:  fb614f4385 t7700: stop losing return codes of git commands
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v4 01/27] lib-bash.sh: move `then` onto its own line
  2019-11-26  1:17     ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
@ 2019-11-26  1:17       ` Denton Liu
  2019-11-26  1:17       ` [PATCH v4 02/27] apply-one-time-sed.sh: modernize style Denton Liu
                         ` (26 subsequent siblings)
  27 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-26  1:17 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

The code style for tests is to have statements on their own line if
possible. Move the `then` onto its own line so that it conforms with the
test style.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/lib-bash.sh | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/t/lib-bash.sh b/t/lib-bash.sh
index 2be955fafb..b0b6060929 100644
--- a/t/lib-bash.sh
+++ b/t/lib-bash.sh
@@ -2,10 +2,12 @@
 # to run under Bash; primarily intended for tests of the completion
 # script.
 
-if test -n "$BASH" && test -z "$POSIXLY_CORRECT"; then
+if test -n "$BASH" && test -z "$POSIXLY_CORRECT"
+then
 	# we are in full-on bash mode
 	true
-elif type bash >/dev/null 2>&1; then
+elif type bash >/dev/null 2>&1
+then
 	# execute in full-on bash mode
 	unset POSIXLY_CORRECT
 	exec bash "$0" "$@"
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v4 02/27] apply-one-time-sed.sh: modernize style
  2019-11-26  1:17     ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
  2019-11-26  1:17       ` [PATCH v4 01/27] lib-bash.sh: move `then` onto its own line Denton Liu
@ 2019-11-26  1:17       ` Denton Liu
  2019-11-26  1:17       ` [PATCH v4 03/27] t0014: remove git command upstream of pipe Denton Liu
                         ` (25 subsequent siblings)
  27 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-26  1:17 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Convert `[ ... ]` to use `test` and test for the existence of a regular
file (`-f`) instead of any file (`-e`).

Move the `then`s onto their own lines so that it conforms with the
general test style.

Instead of redirecting input into sed, allow it to open its own input.

Use `cmp -s` instead of `diff` since we only care about whether the two
files are equal and `diff` is overkill for this.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/lib-httpd/apply-one-time-sed.sh | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/t/lib-httpd/apply-one-time-sed.sh b/t/lib-httpd/apply-one-time-sed.sh
index fcef728925..bf7689d020 100644
--- a/t/lib-httpd/apply-one-time-sed.sh
+++ b/t/lib-httpd/apply-one-time-sed.sh
@@ -7,11 +7,13 @@
 #
 # This can be used to simulate the effects of the repository changing in
 # between HTTP request-response pairs.
-if [ -e one-time-sed ]; then
+if test -f one-time-sed
+then
 	"$GIT_EXEC_PATH/git-http-backend" >out
-	sed "$(cat one-time-sed)" <out >out_modified
+	sed "$(cat one-time-sed)" out >out_modified
 
-	if diff out out_modified >/dev/null; then
+	if cmp -s out out_modified
+	then
 		cat out
 	else
 		cat out_modified
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v4 03/27] t0014: remove git command upstream of pipe
  2019-11-26  1:17     ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
  2019-11-26  1:17       ` [PATCH v4 01/27] lib-bash.sh: move `then` onto its own line Denton Liu
  2019-11-26  1:17       ` [PATCH v4 02/27] apply-one-time-sed.sh: modernize style Denton Liu
@ 2019-11-26  1:17       ` Denton Liu
  2019-11-26  1:17       ` [PATCH v4 04/27] t0090: stop losing return codes of git commands Denton Liu
                         ` (24 subsequent siblings)
  27 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-26  1:17 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Before, the `git frotz` command would fail but its return code was
hidden since it was in the upstream of a pipe. Break the pipeline into
two commands so that the return code is no longer lost. Also, mark
`git frotz` with test_must_fail since it's supposed to fail.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t0014-alias.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/t/t0014-alias.sh b/t/t0014-alias.sh
index 2694c81afd..8d3d9144c0 100755
--- a/t/t0014-alias.sh
+++ b/t/t0014-alias.sh
@@ -38,8 +38,8 @@ test_expect_success 'looping aliases - internal execution' '
 #'
 
 test_expect_success 'run-command formats empty args properly' '
-    GIT_TRACE=1 git frotz a "" b " " c 2>&1 |
-    sed -ne "/run_command:/s/.*trace: run_command: //p" >actual &&
+    test_must_fail env GIT_TRACE=1 git frotz a "" b " " c 2>actual.raw &&
+    sed -ne "/run_command:/s/.*trace: run_command: //p" actual.raw >actual &&
     echo "git-frotz a '\'''\'' b '\'' '\'' c" >expect &&
     test_cmp expect actual
 '
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v4 04/27] t0090: stop losing return codes of git commands
  2019-11-26  1:17     ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                         ` (2 preceding siblings ...)
  2019-11-26  1:17       ` [PATCH v4 03/27] t0014: remove git command upstream of pipe Denton Liu
@ 2019-11-26  1:17       ` Denton Liu
  2019-11-26  1:17       ` [PATCH v4 05/27] t3301: " Denton Liu
                         ` (23 subsequent siblings)
  27 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-26  1:17 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

In generate_expected_cache_tree_rec(), there are currently two instances
of `git ls-files` in the upstream of a pipe. In the case where the
upstream git command fails, its return code will be lost. Extract the
`git ls-files` into its own call so that if it ever fails, its return
code is not lost.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t0090-cache-tree.sh | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh
index ce9a4a5f32..5a633690bf 100755
--- a/t/t0090-cache-tree.sh
+++ b/t/t0090-cache-tree.sh
@@ -21,9 +21,10 @@ generate_expected_cache_tree_rec () {
 	parent="$2" &&
 	# ls-files might have foo/bar, foo/bar/baz, and foo/bar/quux
 	# We want to count only foo because it's the only direct child
-	subtrees=$(git ls-files|grep /|cut -d / -f 1|uniq) &&
+	git ls-files >files &&
+	subtrees=$(grep / files|cut -d / -f 1|uniq) &&
 	subtree_count=$(echo "$subtrees"|awk -v c=0 '$1 != "" {++c} END {print c}') &&
-	entries=$(git ls-files|wc -l) &&
+	entries=$(wc -l <files) &&
 	printf "SHA $dir (%d entries, %d subtrees)\n" "$entries" "$subtree_count" &&
 	for subtree in $subtrees
 	do
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v4 05/27] t3301: stop losing return codes of git commands
  2019-11-26  1:17     ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                         ` (3 preceding siblings ...)
  2019-11-26  1:17       ` [PATCH v4 04/27] t0090: stop losing return codes of git commands Denton Liu
@ 2019-11-26  1:17       ` " Denton Liu
  2019-11-26  1:17       ` [PATCH v4 06/27] t3600: use test_line_count() where possible Denton Liu
                         ` (22 subsequent siblings)
  27 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-26  1:17 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Currently, there are two ways where the return codes of git commands are
lost. The first way is when a command is in the upstream of a pipe. In a
pipe, only the return code of the last command is used. Thus, all other
commands will have their return codes masked. Rewrite pipes so that
there are no git commands upstream.

The other way is when a command is in a non-assignment command
substitution. The return code will be lost in favour of the surrounding
command's. Rewrite instances of this so that git commands are either run
on their own or in an assignment-only command substitution.

This patch fixes a real buggy test: in 'copy note with "git notes
copy"', `git notes` was mistyped as `git note`.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t3301-notes.sh | 230 +++++++++++++++++++++++++++++++++--------------
 1 file changed, 163 insertions(+), 67 deletions(-)

diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh
index d66a5f6faa..8f43303007 100755
--- a/t/t3301-notes.sh
+++ b/t/t3301-notes.sh
@@ -54,7 +54,9 @@ test_expect_success 'create notes' '
 	test_path_is_missing .git/NOTES_EDITMSG &&
 	git ls-tree -r refs/notes/commits >actual &&
 	test_line_count = 1 actual &&
-	test "b4" = "$(git notes show)" &&
+	echo b4 >expect &&
+	git notes show >actual &&
+	test_cmp expect actual &&
 	git show HEAD^ &&
 	test_must_fail git notes show HEAD^
 '
@@ -79,14 +81,21 @@ test_expect_success 'edit existing notes' '
 	test_path_is_missing .git/NOTES_EDITMSG &&
 	git ls-tree -r refs/notes/commits >actual &&
 	test_line_count = 1 actual &&
-	test "b3" = "$(git notes show)" &&
+	echo b3 >expect &&
+	git notes show >actual &&
+	test_cmp expect actual &&
 	git show HEAD^ &&
 	test_must_fail git notes show HEAD^
 '
 
 test_expect_success 'show notes from treeish' '
-	test "b3" = "$(git notes --ref commits^{tree} show)" &&
-	test "b4" = "$(git notes --ref commits@{1} show)"
+	echo b3 >expect &&
+	git notes --ref commits^{tree} show >actual &&
+	test_cmp expect actual &&
+
+	echo b4 >expect &&
+	git notes --ref commits@{1} show >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'cannot edit notes from non-ref' '
@@ -99,7 +108,9 @@ test_expect_success 'cannot "git notes add -m" where notes already exists' '
 	test_path_is_missing .git/NOTES_EDITMSG &&
 	git ls-tree -r refs/notes/commits >actual &&
 	test_line_count = 1 actual &&
-	test "b3" = "$(git notes show)" &&
+	echo b3 >expect &&
+	git notes show >actual &&
+	test_cmp expect actual &&
 	git show HEAD^ &&
 	test_must_fail git notes show HEAD^
 '
@@ -109,7 +120,9 @@ test_expect_success 'can overwrite existing note with "git notes add -f -m"' '
 	test_path_is_missing .git/NOTES_EDITMSG &&
 	git ls-tree -r refs/notes/commits >actual &&
 	test_line_count = 1 actual &&
-	test "b1" = "$(git notes show)" &&
+	echo b1 >expect &&
+	git notes show >actual &&
+	test_cmp expect actual &&
 	git show HEAD^ &&
 	test_must_fail git notes show HEAD^
 '
@@ -119,7 +132,9 @@ test_expect_success 'add w/no options on existing note morphs into edit' '
 	test_path_is_missing .git/NOTES_EDITMSG &&
 	git ls-tree -r refs/notes/commits >actual &&
 	test_line_count = 1 actual &&
-	test "b2" = "$(git notes show)" &&
+	echo b2 >expect &&
+	git notes show >actual &&
+	test_cmp expect actual &&
 	git show HEAD^ &&
 	test_must_fail git notes show HEAD^
 '
@@ -129,7 +144,9 @@ test_expect_success 'can overwrite existing note with "git notes add -f"' '
 	test_path_is_missing .git/NOTES_EDITMSG &&
 	git ls-tree -r refs/notes/commits >actual &&
 	test_line_count = 1 actual &&
-	test "b1" = "$(git notes show)" &&
+	echo b1 >expect &&
+	git notes show >actual &&
+	test_cmp expect actual &&
 	git show HEAD^ &&
 	test_must_fail git notes show HEAD^
 '
@@ -146,7 +163,8 @@ test_expect_success 'show notes' '
 		Notes:
 		${indent}b1
 	EOF
-	! (git cat-file commit HEAD | grep b1) &&
+	git cat-file commit HEAD >commits &&
+	! grep b1 commits &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -472,9 +490,11 @@ test_expect_success 'removing with --stdin --ignore-missing' '
 test_expect_success 'list notes with "git notes list"' '
 	commit_2=$(git rev-parse 2nd) &&
 	commit_3=$(git rev-parse 3rd) &&
+	note_2=$(git rev-parse refs/notes/commits:$commit_2) &&
+	note_3=$(git rev-parse refs/notes/commits:$commit_3) &&
 	sort -t" " -k2 >expect <<-EOF &&
-		$(git rev-parse refs/notes/commits:$commit_2) $commit_2
-		$(git rev-parse refs/notes/commits:$commit_3) $commit_3
+		$note_2 $commit_2
+		$note_3 $commit_3
 	EOF
 	git notes list >actual &&
 	test_cmp expect actual
@@ -486,9 +506,7 @@ test_expect_success 'list notes with "git notes"' '
 '
 
 test_expect_success 'list specific note with "git notes list <object>"' '
-	cat >expect <<-EOF &&
-		$(git rev-parse refs/notes/commits:$commit_3)
-	EOF
+	git rev-parse refs/notes/commits:$commit_3 >expect &&
 	git notes list HEAD^^ >actual &&
 	test_cmp expect actual
 '
@@ -512,10 +530,11 @@ test_expect_success 'append to existing note with "git notes append"' '
 
 test_expect_success '"git notes list" does not expand to "git notes list HEAD"' '
 	commit_5=$(git rev-parse 5th) &&
+	note_5=$(git rev-parse refs/notes/commits:$commit_5) &&
 	sort -t" " -k2 >expect_list <<-EOF &&
-		$(git rev-parse refs/notes/commits:$commit_2) $commit_2
-		$(git rev-parse refs/notes/commits:$commit_3) $commit_3
-		$(git rev-parse refs/notes/commits:$commit_5) $commit_5
+		$note_2 $commit_2
+		$note_3 $commit_3
+		$note_5 $commit_5
 	EOF
 	git notes list >actual &&
 	test_cmp expect_list actual
@@ -721,7 +740,8 @@ test_expect_success 'Allow notes on non-commits (trees, blobs, tags)' '
 	git notes show HEAD: >actual &&
 	test_cmp expect actual &&
 	echo "Note on a blob" >expect &&
-	filename=$(git ls-tree --name-only HEAD | head -n1) &&
+	git ls-tree --name-only HEAD >files &&
+	filename=$(head -n1 files) &&
 	git notes add -m "Note on a blob" HEAD:$filename &&
 	git notes show HEAD:$filename >actual &&
 	test_cmp expect actual &&
@@ -745,10 +765,13 @@ test_expect_success 'create note from other note with "git notes add -C"' '
 		Notes:
 		${indent}order test
 	EOF
-	git notes add -C $(git notes list HEAD^) &&
+	note=$(git notes list HEAD^) &&
+	git notes add -C $note &&
 	git log -1 >actual &&
 	test_cmp expect actual &&
-	test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
+	git notes list HEAD^ >expect &&
+	git notes list HEAD >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'create note from non-existing note with "git notes add -C" fails' '
@@ -777,11 +800,12 @@ test_expect_success 'create note from blob with "git notes add -C" reuses blob i
 		Notes:
 		${indent}This is a blob object
 	EOF
-	blob=$(echo "This is a blob object" | git hash-object -w --stdin) &&
-	git notes add -C $blob &&
+	echo "This is a blob object" | git hash-object -w --stdin >blob &&
+	git notes add -C $(cat blob) &&
 	git log -1 >actual &&
 	test_cmp expect actual &&
-	test "$(git notes list HEAD)" = "$blob"
+	git notes list HEAD >actual &&
+	test_cmp blob actual
 '
 
 test_expect_success 'create note from other note with "git notes add -c"' '
@@ -797,7 +821,8 @@ test_expect_success 'create note from other note with "git notes add -c"' '
 		Notes:
 		${indent}yet another note
 	EOF
-	MSG="yet another note" git notes add -c $(git notes list HEAD^^) &&
+	note=$(git notes list HEAD^^) &&
+	MSG="yet another note" git notes add -c $note &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -822,7 +847,8 @@ test_expect_success 'append to note from other note with "git notes append -C"'
 		${indent}
 		${indent}yet another note
 	EOF
-	git notes append -C $(git notes list HEAD^) HEAD^ &&
+	note=$(git notes list HEAD^) &&
+	git notes append -C $note HEAD^ &&
 	git log -1 HEAD^ >actual &&
 	test_cmp expect actual
 '
@@ -839,7 +865,8 @@ test_expect_success 'create note from other note with "git notes append -c"' '
 		Notes:
 		${indent}other note
 	EOF
-	MSG="other note" git notes append -c $(git notes list HEAD^) &&
+	note=$(git notes list HEAD^) &&
+	MSG="other note" git notes append -c $note &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -858,7 +885,8 @@ test_expect_success 'append to note from other note with "git notes append -c"'
 		${indent}
 		${indent}yet another note
 	EOF
-	MSG="yet another note" git notes append -c $(git notes list HEAD) &&
+	note=$(git notes list HEAD) &&
+	MSG="yet another note" git notes append -c $note &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -878,7 +906,9 @@ test_expect_success 'copy note with "git notes copy"' '
 	git notes copy 8th 4th &&
 	git log 3rd..4th >actual &&
 	test_cmp expect actual &&
-	test "$(git note list 4th)" = "$(git note list 8th)"
+	git notes list 4th >expect &&
+	git notes list 8th >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'copy note with "git notes copy" with default' '
@@ -899,14 +929,30 @@ test_expect_success 'copy note with "git notes copy" with default' '
 	git notes copy HEAD^ &&
 	git log -1 >actual &&
 	test_cmp expect actual &&
-	test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
+	git notes list HEAD^ >expect &&
+	git notes list HEAD >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'prevent overwrite with "git notes copy"' '
 	test_must_fail git notes copy HEAD~2 HEAD &&
+	cat >expect <<-EOF &&
+		commit $commit
+		Author: A U Thor <author@example.com>
+		Date:   Thu Apr 7 15:23:13 2005 -0700
+
+		${indent}11th
+
+		Notes:
+		${indent}other note
+		${indent}
+		${indent}yet another note
+	EOF
 	git log -1 >actual &&
 	test_cmp expect actual &&
-	test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
+	git notes list HEAD^ >expect &&
+	git notes list HEAD >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'allow overwrite with "git notes copy -f"' '
@@ -924,7 +970,9 @@ test_expect_success 'allow overwrite with "git notes copy -f"' '
 	git notes copy -f HEAD~3 HEAD &&
 	git log -1 >actual &&
 	test_cmp expect actual &&
-	test "$(git notes list HEAD)" = "$(git notes list HEAD~3)"
+	git notes list HEAD~3 >expect &&
+	git notes list HEAD >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'allow overwrite with "git notes copy -f" with default' '
@@ -944,7 +992,9 @@ test_expect_success 'allow overwrite with "git notes copy -f" with default' '
 	git notes copy -f HEAD~2 &&
 	git log -1 >actual &&
 	test_cmp expect actual &&
-	test "$(git notes list HEAD)" = "$(git notes list HEAD~2)"
+	git notes list HEAD~2 >expect &&
+	git notes list HEAD >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'cannot copy note from object without notes' '
@@ -979,13 +1029,21 @@ test_expect_success 'git notes copy --stdin' '
 		${indent}
 		${indent}yet another note
 	EOF
-	(echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^) &&
-	echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
-	git notes copy --stdin &&
+	from=$(git rev-parse HEAD~3) &&
+	to=$(git rev-parse HEAD^) &&
+	echo "$from" "$to" >copy &&
+	from=$(git rev-parse HEAD~2) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >>copy &&
+	git notes copy --stdin <copy &&
 	git log -2 >actual &&
 	test_cmp expect actual &&
-	test "$(git notes list HEAD)" = "$(git notes list HEAD~2)" &&
-	test "$(git notes list HEAD^)" = "$(git notes list HEAD~3)"
+	git notes list HEAD~2 >expect &&
+	git notes list HEAD >actual &&
+	test_cmp expect actual &&
+	git notes list HEAD~3 >expect &&
+	git notes list HEAD^ >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'git notes copy --for-rewrite (unconfigured)' '
@@ -1006,9 +1064,13 @@ test_expect_success 'git notes copy --for-rewrite (unconfigured)' '
 
 		${indent}14th
 	EOF
-	(echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^) &&
-	echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
-	git notes copy --for-rewrite=foo &&
+	from=$(git rev-parse HEAD~3) &&
+	to=$(git rev-parse HEAD^) &&
+	echo "$from" "$to" >copy &&
+	from=$(git rev-parse HEAD~2) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >>copy &&
+	git notes copy --for-rewrite=foo <copy &&
 	git log -2 >actual &&
 	test_cmp expect actual
 '
@@ -1041,17 +1103,23 @@ test_expect_success 'git notes copy --for-rewrite (enabled)' '
 	EOF
 	test_config notes.rewriteMode overwrite &&
 	test_config notes.rewriteRef "refs/notes/*" &&
-	(echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^) &&
-	echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
-	git notes copy --for-rewrite=foo &&
+	from=$(git rev-parse HEAD~3) &&
+	to=$(git rev-parse HEAD^) &&
+	echo "$from" "$to" >copy &&
+	from=$(git rev-parse HEAD~2) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >>copy &&
+	git notes copy --for-rewrite=foo <copy &&
 	git log -2 >actual &&
 	test_cmp expect actual
 '
 
 test_expect_success 'git notes copy --for-rewrite (disabled)' '
 	test_config notes.rewrite.bar false &&
-	echo $(git rev-parse HEAD~3) $(git rev-parse HEAD) |
-	git notes copy --for-rewrite=bar &&
+	from=$(git rev-parse HEAD~3) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
+	git notes copy --for-rewrite=bar <copy &&
 	git log -2 >actual &&
 	test_cmp expect actual
 '
@@ -1071,8 +1139,10 @@ test_expect_success 'git notes copy --for-rewrite (overwrite)' '
 	git notes add -f -m"a fresh note" HEAD^ &&
 	test_config notes.rewriteMode overwrite &&
 	test_config notes.rewriteRef "refs/notes/*" &&
-	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
-	git notes copy --for-rewrite=foo &&
+	from=$(git rev-parse HEAD^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
+	git notes copy --for-rewrite=foo <copy &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -1080,8 +1150,10 @@ test_expect_success 'git notes copy --for-rewrite (overwrite)' '
 test_expect_success 'git notes copy --for-rewrite (ignore)' '
 	test_config notes.rewriteMode ignore &&
 	test_config notes.rewriteRef "refs/notes/*" &&
-	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
-	git notes copy --for-rewrite=foo &&
+	from=$(git rev-parse HEAD^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
+	git notes copy --for-rewrite=foo <copy &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -1103,8 +1175,10 @@ test_expect_success 'git notes copy --for-rewrite (append)' '
 	git notes add -f -m"another fresh note" HEAD^ &&
 	test_config notes.rewriteMode concatenate &&
 	test_config notes.rewriteRef "refs/notes/*" &&
-	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
-	git notes copy --for-rewrite=foo &&
+	from=$(git rev-parse HEAD^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
+	git notes copy --for-rewrite=foo <copy &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -1131,9 +1205,13 @@ test_expect_success 'git notes copy --for-rewrite (append two to one)' '
 	git notes add -f -m"append 2" HEAD^^ &&
 	test_config notes.rewriteMode concatenate &&
 	test_config notes.rewriteRef "refs/notes/*" &&
-	(echo $(git rev-parse HEAD^) $(git rev-parse HEAD) &&
-	echo $(git rev-parse HEAD^^) $(git rev-parse HEAD)) |
-	git notes copy --for-rewrite=foo &&
+	from=$(git rev-parse HEAD^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
+	from=$(git rev-parse HEAD^^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >>copy &&
+	git notes copy --for-rewrite=foo <copy &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -1142,8 +1220,10 @@ test_expect_success 'git notes copy --for-rewrite (append empty)' '
 	git notes remove HEAD^ &&
 	test_config notes.rewriteMode concatenate &&
 	test_config notes.rewriteRef "refs/notes/*" &&
-	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
-	git notes copy --for-rewrite=foo &&
+	from=$(git rev-parse HEAD^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
+	git notes copy --for-rewrite=foo <copy &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -1163,8 +1243,10 @@ test_expect_success 'GIT_NOTES_REWRITE_MODE works' '
 	test_config notes.rewriteMode concatenate &&
 	test_config notes.rewriteRef "refs/notes/*" &&
 	git notes add -f -m"replacement note 1" HEAD^ &&
-	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
-	GIT_NOTES_REWRITE_MODE=overwrite git notes copy --for-rewrite=foo &&
+	from=$(git rev-parse HEAD^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
+	GIT_NOTES_REWRITE_MODE=overwrite git notes copy --for-rewrite=foo <copy &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -1184,9 +1266,11 @@ test_expect_success 'GIT_NOTES_REWRITE_REF works' '
 	git notes add -f -m"replacement note 2" HEAD^ &&
 	test_config notes.rewriteMode overwrite &&
 	test_unconfig notes.rewriteRef &&
-	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
+	from=$(git rev-parse HEAD^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
 	GIT_NOTES_REWRITE_REF=refs/notes/commits:refs/notes/other \
-		git notes copy --for-rewrite=foo &&
+		git notes copy --for-rewrite=foo <copy &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -1195,9 +1279,11 @@ test_expect_success 'GIT_NOTES_REWRITE_REF overrides config' '
 	git notes add -f -m"replacement note 3" HEAD^ &&
 	test_config notes.rewriteMode overwrite &&
 	test_config notes.rewriteRef refs/notes/other &&
-	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
+	from=$(git rev-parse HEAD^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
 	GIT_NOTES_REWRITE_REF=refs/notes/commits \
-		git notes copy --for-rewrite=foo &&
+		git notes copy --for-rewrite=foo <copy &&
 	git log -1 >actual &&
 	grep "replacement note 3" actual
 '
@@ -1212,26 +1298,36 @@ test_expect_success 'git notes copy diagnoses too many or too few parameters' '
 test_expect_success 'git notes get-ref expands refs/heads/master to refs/notes/refs/heads/master' '
 	test_unconfig core.notesRef &&
 	sane_unset GIT_NOTES_REF &&
-	test "$(git notes --ref=refs/heads/master get-ref)" = "refs/notes/refs/heads/master"
+	echo refs/notes/refs/heads/master >expect &&
+	git notes --ref=refs/heads/master get-ref >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'git notes get-ref (no overrides)' '
 	test_unconfig core.notesRef &&
 	sane_unset GIT_NOTES_REF &&
-	test "$(git notes get-ref)" = "refs/notes/commits"
+	echo refs/notes/commits >expect &&
+	git notes get-ref >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'git notes get-ref (core.notesRef)' '
 	test_config core.notesRef refs/notes/foo &&
-	test "$(git notes get-ref)" = "refs/notes/foo"
+	echo refs/notes/foo >expect &&
+	git notes get-ref >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'git notes get-ref (GIT_NOTES_REF)' '
-	test "$(GIT_NOTES_REF=refs/notes/bar git notes get-ref)" = "refs/notes/bar"
+	echo refs/notes/bar >expect &&
+	GIT_NOTES_REF=refs/notes/bar git notes get-ref >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'git notes get-ref (--ref)' '
-	test "$(GIT_NOTES_REF=refs/notes/bar git notes --ref=baz get-ref)" = "refs/notes/baz"
+	echo refs/notes/baz >expect &&
+	GIT_NOTES_REF=refs/notes/bar git notes --ref=baz get-ref >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'setup testing of empty notes' '
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v4 06/27] t3600: use test_line_count() where possible
  2019-11-26  1:17     ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                         ` (4 preceding siblings ...)
  2019-11-26  1:17       ` [PATCH v4 05/27] t3301: " Denton Liu
@ 2019-11-26  1:17       ` Denton Liu
  2019-11-26  1:18       ` [PATCH v4 07/27] t3600: stop losing return codes of git commands Denton Liu
                         ` (21 subsequent siblings)
  27 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-26  1:17 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Since we have a helper function that can test the number of lines in a
file that gives better debugging information on failure, use
test_line_count() to test the number of lines.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t3600-rm.sh | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh
index 8c8cca5bfb..f6e659b7e9 100755
--- a/t/t3600-rm.sh
+++ b/t/t3600-rm.sh
@@ -113,9 +113,10 @@ test_expect_success '"rm" command printed' '
 	echo frotz >test-file &&
 	git add test-file &&
 	git commit -m "add file for rm test" &&
-	git rm test-file >rm-output &&
-	test $(grep "^rm " rm-output | wc -l) = 1 &&
-	rm -f test-file rm-output &&
+	git rm test-file >rm-output.raw &&
+	grep "^rm " rm-output.raw >rm-output &&
+	test_line_count = 1 rm-output &&
+	rm -f test-file rm-output.raw rm-output &&
 	git commit -m "remove file from rm test"
 '
 
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v4 07/27] t3600: stop losing return codes of git commands
  2019-11-26  1:17     ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                         ` (5 preceding siblings ...)
  2019-11-26  1:17       ` [PATCH v4 06/27] t3600: use test_line_count() where possible Denton Liu
@ 2019-11-26  1:18       ` Denton Liu
  2019-11-26  1:18       ` [PATCH v4 08/27] t3600: comment on inducing SIGPIPE in `git rm` Denton Liu
                         ` (20 subsequent siblings)
  27 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-26  1:18 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

When a command is in a non-assignment command substitution, the return
code will be lost in favour of the surrounding command's. As a result,
if a git command fails, we won't know about it. Rewrite instances of
this so that git commands are either run in an assignment-only command
substitution so that their return codes aren't lost.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t3600-rm.sh | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh
index f6e659b7e9..0c3bf10edd 100755
--- a/t/t3600-rm.sh
+++ b/t/t3600-rm.sh
@@ -304,7 +304,8 @@ EOF
 
 test_expect_success 'rm removes empty submodules from work tree' '
 	mkdir submod &&
-	git update-index --add --cacheinfo 160000 $(git rev-parse HEAD) submod &&
+	hash=$(git rev-parse HEAD) &&
+	git update-index --add --cacheinfo 160000 "$hash" submod &&
 	git config -f .gitmodules submodule.sub.url ./. &&
 	git config -f .gitmodules submodule.sub.path submod &&
 	git submodule init &&
@@ -623,7 +624,8 @@ test_expect_success 'setup subsubmodule' '
 	git submodule update &&
 	(
 		cd submod &&
-		git update-index --add --cacheinfo 160000 $(git rev-parse HEAD) subsubmod &&
+		hash=$(git rev-parse HEAD) &&
+		git update-index --add --cacheinfo 160000 "$hash" subsubmod &&
 		git config -f .gitmodules submodule.sub.url ../. &&
 		git config -f .gitmodules submodule.sub.path subsubmod &&
 		git submodule init &&
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v4 08/27] t3600: comment on inducing SIGPIPE in `git rm`
  2019-11-26  1:17     ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                         ` (6 preceding siblings ...)
  2019-11-26  1:18       ` [PATCH v4 07/27] t3600: stop losing return codes of git commands Denton Liu
@ 2019-11-26  1:18       ` Denton Liu
  2019-11-26  1:18       ` [PATCH v4 09/27] t4015: stop losing return codes of git commands Denton Liu
                         ` (19 subsequent siblings)
  27 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-26  1:18 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Add a comment about intentionally inducing SIGPIPE since this is unusual
and future developers should be aware. Also, even though we are trying
to refactor git commands out of the upstream of pipes, we cannot do it
here since we rely on it being upstream to induce SIGPIPE. Comment on
that as well so that future developers do not try to change it.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t3600-rm.sh | 1 +
 1 file changed, 1 insertion(+)

diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh
index 0c3bf10edd..0ea858d652 100755
--- a/t/t3600-rm.sh
+++ b/t/t3600-rm.sh
@@ -251,6 +251,7 @@ test_expect_success 'choking "git rm" should not let it die with cruft' '
 		echo "100644 $hash 0	some-file-$i"
 		i=$(( $i + 1 ))
 	done | git update-index --index-info &&
+	# git command is intentionally placed upstream of pipe to induce SIGPIPE
 	git rm -n "some-file-*" | : &&
 	test_path_is_missing .git/index.lock
 '
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v4 09/27] t4015: stop losing return codes of git commands
  2019-11-26  1:17     ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                         ` (7 preceding siblings ...)
  2019-11-26  1:18       ` [PATCH v4 08/27] t3600: comment on inducing SIGPIPE in `git rm` Denton Liu
@ 2019-11-26  1:18       ` Denton Liu
  2019-11-26  1:18       ` [PATCH v4 10/27] t4015: use test_write_lines() Denton Liu
                         ` (18 subsequent siblings)
  27 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-26  1:18 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Currently, there are two ways where the return codes of git commands are
lost. The first way is when a command is in the upstream of a pipe. In a
pipe, only the return code of the last command is used. Thus, all other
commands will have their return codes masked. Rewrite pipes so that
there are no git commands upstream.

The other way is when a command is in a non-assignment command
substitution. The return code will be lost in favour of the surrounding
command's. Rewrite instances of this so that git commands are either run
on their own or in an assignment-only command substitution.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t4015-diff-whitespace.sh | 119 ++++++++++++++++++++++---------------
 1 file changed, 72 insertions(+), 47 deletions(-)

diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh
index eadaf57262..7fb83c8eff 100755
--- a/t/t4015-diff-whitespace.sh
+++ b/t/t4015-diff-whitespace.sh
@@ -16,7 +16,8 @@ test_expect_success "Ray Lehtiniemi's example" '
 	} while (0);
 	EOF
 	git update-index --add x &&
-	before=$(git rev-parse --short $(git hash-object x)) &&
+	old_hash_x=$(git hash-object x) &&
+	before=$(git rev-parse --short "$old_hash_x") &&
 
 	cat <<-\EOF >x &&
 	do
@@ -25,7 +26,8 @@ test_expect_success "Ray Lehtiniemi's example" '
 	}
 	while (0);
 	EOF
-	after=$(git rev-parse --short $(git hash-object x)) &&
+	new_hash_x=$(git hash-object x) &&
+	after=$(git rev-parse --short "$new_hash_x") &&
 
 	cat <<-EOF >expect &&
 	diff --git a/x b/x
@@ -63,7 +65,8 @@ test_expect_success 'another test, without options' '
 	EOF
 
 	git update-index x &&
-	before=$(git rev-parse --short $(git hash-object x)) &&
+	old_hash_x=$(git hash-object x) &&
+	before=$(git rev-parse --short "$old_hash_x") &&
 
 	tr "_" " " <<-\EOF >x &&
 	_	whitespace at beginning
@@ -73,7 +76,8 @@ test_expect_success 'another test, without options' '
 	unchanged line
 	CR at end
 	EOF
-	after=$(git rev-parse --short $(git hash-object x)) &&
+	new_hash_x=$(git hash-object x) &&
+	after=$(git rev-parse --short "$new_hash_x") &&
 
 	tr "Q_" "\015 " <<-EOF >expect &&
 	diff --git a/x b/x
@@ -526,13 +530,15 @@ test_expect_success 'ignore-blank-lines: mix changes and blank lines' '
 test_expect_success 'check mixed spaces and tabs in indent' '
 	# This is indented with SP HT SP.
 	echo " 	 foo();" >x &&
-	git diff --check | grep "space before tab in indent"
+	test_must_fail git diff --check >check &&
+	grep "space before tab in indent" check
 '
 
 test_expect_success 'check mixed tabs and spaces in indent' '
 	# This is indented with HT SP HT.
 	echo "	 	foo();" >x &&
-	git diff --check | grep "space before tab in indent"
+	test_must_fail git diff --check >check &&
+	grep "space before tab in indent" check
 '
 
 test_expect_success 'check with no whitespace errors' '
@@ -753,20 +759,23 @@ test_expect_success 'check tab-in-indent excluded from wildcard whitespace attri
 test_expect_success 'line numbers in --check output are correct' '
 	echo "" >x &&
 	echo "foo(); " >>x &&
-	git diff --check | grep "x:2:"
+	test_must_fail git diff --check >check &&
+	grep "x:2:" check
 '
 
 test_expect_success 'checkdiff detects new trailing blank lines (1)' '
 	echo "foo();" >x &&
 	echo "" >>x &&
-	git diff --check | grep "new blank line"
+	test_must_fail git diff --check >check &&
+	grep "new blank line" check
 '
 
 test_expect_success 'checkdiff detects new trailing blank lines (2)' '
 	{ echo a; echo b; echo; echo; } >x &&
 	git add x &&
 	{ echo a; echo; echo; echo; echo; } >x &&
-	git diff --check | grep "new blank line"
+	test_must_fail git diff --check >check &&
+	grep "new blank line" check
 '
 
 test_expect_success 'checkdiff allows new blank lines' '
@@ -794,14 +803,16 @@ test_expect_success 'whitespace-only changes reported across renames' '
 	git reset --hard &&
 	for i in 1 2 3 4 5 6 7 8 9; do echo "$i$i$i$i$i$i"; done >x &&
 	git add x &&
-	before=$(git rev-parse --short $(git hash-object x)) &&
+	hash_x=$(git hash-object x) &&
+	before=$(git rev-parse --short "$hash_x") &&
 	git commit -m "base" &&
 	sed -e "5s/^/ /" x >z &&
 	git rm x &&
 	git add z &&
-	after=$(git rev-parse --short $(git hash-object z)) &&
-	git diff -w -M --cached |
-	sed -e "/^similarity index /s/[0-9][0-9]*/NUM/" >actual &&
+	hash_z=$(git hash-object z) &&
+	after=$(git rev-parse --short "$hash_z") &&
+	git diff -w -M --cached >actual.raw &&
+	sed -e "/^similarity index /s/[0-9][0-9]*/NUM/" actual.raw >actual &&
 	cat <<-EOF >expect &&
 	diff --git a/x b/z
 	similarity index NUM%
@@ -840,7 +851,8 @@ test_expect_success 'combined diff with autocrlf conversion' '
 	git config core.autocrlf true &&
 	test_must_fail git merge master &&
 
-	git diff | sed -e "1,/^@@@/d" >actual &&
+	git diff >actual.raw &&
+	sed -e "1,/^@@@/d" actual.raw >actual &&
 	! grep "^-" actual
 
 '
@@ -864,11 +876,14 @@ test_expect_success 'diff that introduces a line with only tabs' '
 	git config core.whitespace blank-at-eol &&
 	git reset --hard &&
 	echo "test" >x &&
-	before=$(git rev-parse --short $(git hash-object x)) &&
+	old_hash_x=$(git hash-object x) &&
+	before=$(git rev-parse --short "$old_hash_x") &&
 	git commit -m "initial" x &&
 	echo "{NTN}" | tr "NT" "\n\t" >>x &&
-	after=$(git rev-parse --short $(git hash-object x)) &&
-	git diff --color | test_decode_color >current &&
+	new_hash_x=$(git hash-object x) &&
+	after=$(git rev-parse --short "$new_hash_x") &&
+	git diff --color >current.raw &&
+	test_decode_color <current.raw >current &&
 
 	cat >expected <<-EOF &&
 	<BOLD>diff --git a/x b/x<RESET>
@@ -891,17 +906,19 @@ test_expect_success 'diff that introduces and removes ws breakages' '
 		echo "0. blank-at-eol " &&
 		echo "1. blank-at-eol "
 	} >x &&
-	before=$(git rev-parse --short $(git hash-object x)) &&
+	old_hash_x=$(git hash-object x) &&
+	before=$(git rev-parse --short "$old_hash_x") &&
 	git commit -a --allow-empty -m preimage &&
 	{
 		echo "0. blank-at-eol " &&
 		echo "1. still-blank-at-eol " &&
 		echo "2. and a new line "
 	} >x &&
-	after=$(git rev-parse --short $(git hash-object x)) &&
+	new_hash_x=$(git hash-object x) &&
+	after=$(git rev-parse --short "$new_hash_x") &&
 
-	git diff --color |
-	test_decode_color >current &&
+	git diff --color >current.raw &&
+	test_decode_color <current.raw >current &&
 
 	cat >expected <<-EOF &&
 	<BOLD>diff --git a/x b/x<RESET>
@@ -925,14 +942,16 @@ test_expect_success 'ws-error-highlight test setup' '
 		echo "0. blank-at-eol " &&
 		echo "1. blank-at-eol "
 	} >x &&
-	before=$(git rev-parse --short $(git hash-object x)) &&
+	old_hash_x=$(git hash-object x) &&
+	before=$(git rev-parse --short "$old_hash_x") &&
 	git commit -a --allow-empty -m preimage &&
 	{
 		echo "0. blank-at-eol " &&
 		echo "1. still-blank-at-eol " &&
 		echo "2. and a new line "
 	} >x &&
-	after=$(git rev-parse --short $(git hash-object x)) &&
+	new_hash_x=$(git hash-object x) &&
+	after=$(git rev-parse --short "$new_hash_x") &&
 
 	cat >expect.default-old <<-EOF &&
 	<BOLD>diff --git a/x b/x<RESET>
@@ -974,32 +993,32 @@ test_expect_success 'ws-error-highlight test setup' '
 
 test_expect_success 'test --ws-error-highlight option' '
 
-	git diff --color --ws-error-highlight=default,old |
-	test_decode_color >current &&
+	git diff --color --ws-error-highlight=default,old >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.default-old current &&
 
-	git diff --color --ws-error-highlight=all |
-	test_decode_color >current &&
+	git diff --color --ws-error-highlight=all >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.all current &&
 
-	git diff --color --ws-error-highlight=none |
-	test_decode_color >current &&
+	git diff --color --ws-error-highlight=none >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.none current
 
 '
 
 test_expect_success 'test diff.wsErrorHighlight config' '
 
-	git -c diff.wsErrorHighlight=default,old diff --color |
-	test_decode_color >current &&
+	git -c diff.wsErrorHighlight=default,old diff --color >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.default-old current &&
 
-	git -c diff.wsErrorHighlight=all diff --color |
-	test_decode_color >current &&
+	git -c diff.wsErrorHighlight=all diff --color >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.all current &&
 
-	git -c diff.wsErrorHighlight=none diff --color |
-	test_decode_color >current &&
+	git -c diff.wsErrorHighlight=none diff --color >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.none current
 
 '
@@ -1007,18 +1026,18 @@ test_expect_success 'test diff.wsErrorHighlight config' '
 test_expect_success 'option overrides diff.wsErrorHighlight' '
 
 	git -c diff.wsErrorHighlight=none \
-		diff --color --ws-error-highlight=default,old |
-	test_decode_color >current &&
+		diff --color --ws-error-highlight=default,old >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.default-old current &&
 
 	git -c diff.wsErrorHighlight=default \
-		diff --color --ws-error-highlight=all |
-	test_decode_color >current &&
+		diff --color --ws-error-highlight=all >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.all current &&
 
 	git -c diff.wsErrorHighlight=all \
-		diff --color --ws-error-highlight=none |
-	test_decode_color >current &&
+		diff --color --ws-error-highlight=none >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.none current
 
 '
@@ -1038,7 +1057,8 @@ test_expect_success 'detect moved code, complete file' '
 	git mv test.c main.c &&
 	test_config color.diff.oldMoved "normal red" &&
 	test_config color.diff.newMoved "normal green" &&
-	git diff HEAD --color-moved=zebra --color --no-renames | test_decode_color >actual &&
+	git diff HEAD --color-moved=zebra --color --no-renames >actual.raw &&
+	test_decode_color <actual.raw >actual &&
 	cat >expected <<-EOF &&
 	<BOLD>diff --git a/main.c b/main.c<RESET>
 	<BOLD>new file mode 100644<RESET>
@@ -1141,9 +1161,12 @@ test_expect_success 'detect malicious moved code, inside file' '
 			bar();
 		}
 	EOF
-	after_main=$(git rev-parse --short $(git hash-object main.c)) &&
-	after_test=$(git rev-parse --short $(git hash-object test.c)) &&
-	git diff HEAD --no-renames --color-moved=zebra --color | test_decode_color >actual &&
+	hash_main=$(git hash-object main.c) &&
+	after_main=$(git rev-parse --short "$hash_main") &&
+	hash_test=$(git hash-object test.c) &&
+	after_test=$(git rev-parse --short "$hash_test") &&
+	git diff HEAD --no-renames --color-moved=zebra --color >actual.raw &&
+	test_decode_color <actual.raw >actual &&
 	cat <<-EOF >expected &&
 	<BOLD>diff --git a/main.c b/main.c<RESET>
 	<BOLD>index $before_main..$after_main 100644<RESET>
@@ -1192,7 +1215,8 @@ test_expect_success 'plain moved code, inside file' '
 	test_config color.diff.oldMovedAlternative "blue" &&
 	test_config color.diff.newMovedAlternative "yellow" &&
 	# needs previous test as setup
-	git diff HEAD --no-renames --color-moved=plain --color | test_decode_color >actual &&
+	git diff HEAD --no-renames --color-moved=plain --color >actual.raw &&
+	test_decode_color <actual.raw >actual &&
 	cat <<-EOF >expected &&
 	<BOLD>diff --git a/main.c b/main.c<RESET>
 	<BOLD>index $before_main..$after_main 100644<RESET>
@@ -1771,7 +1795,8 @@ test_expect_success 'move detection with submodules' '
 	! grep BRED decoded_actual &&
 
 	# nor did we mess with it another way
-	git diff --submodule=diff --color | test_decode_color >expect &&
+	git diff --submodule=diff --color >expect.raw &&
+	test_decode_color <expect.raw >expect &&
 	test_cmp expect decoded_actual &&
 	rm -rf bananas &&
 	git submodule deinit bananas
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v4 10/27] t4015: use test_write_lines()
  2019-11-26  1:17     ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                         ` (8 preceding siblings ...)
  2019-11-26  1:18       ` [PATCH v4 09/27] t4015: stop losing return codes of git commands Denton Liu
@ 2019-11-26  1:18       ` Denton Liu
  2019-11-26  1:18       ` [PATCH v4 11/27] t4138: stop losing return codes of git commands Denton Liu
                         ` (17 subsequent siblings)
  27 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-26  1:18 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Instead of rolling our own method to write out some lines into a file,
use the existing test_write_lines().

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t4015-diff-whitespace.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh
index 7fb83c8eff..4c540b1d70 100755
--- a/t/t4015-diff-whitespace.sh
+++ b/t/t4015-diff-whitespace.sh
@@ -771,9 +771,9 @@ test_expect_success 'checkdiff detects new trailing blank lines (1)' '
 '
 
 test_expect_success 'checkdiff detects new trailing blank lines (2)' '
-	{ echo a; echo b; echo; echo; } >x &&
+	test_write_lines a b "" "" >x &&
 	git add x &&
-	{ echo a; echo; echo; echo; echo; } >x &&
+	test_write_lines a "" "" "" "" >x &&
 	test_must_fail git diff --check >check &&
 	grep "new blank line" check
 '
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v4 11/27] t4138: stop losing return codes of git commands
  2019-11-26  1:17     ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                         ` (9 preceding siblings ...)
  2019-11-26  1:18       ` [PATCH v4 10/27] t4015: use test_write_lines() Denton Liu
@ 2019-11-26  1:18       ` Denton Liu
  2019-11-26  1:18       ` [PATCH v4 12/27] t5317: " Denton Liu
                         ` (16 subsequent siblings)
  27 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-26  1:18 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

In a pipe, only the return code of the last command is used. Thus, all
other commands will have their return codes masked. Rewrite pipes so
that there are no git commands upstream so that we will know if a
command fails.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t4138-apply-ws-expansion.sh | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/t/t4138-apply-ws-expansion.sh b/t/t4138-apply-ws-expansion.sh
index 3b636a63a3..b19faeb67a 100755
--- a/t/t4138-apply-ws-expansion.sh
+++ b/t/t4138-apply-ws-expansion.sh
@@ -17,8 +17,8 @@ test_expect_success setup '
 	printf "\t%s\n" 1 2 3 >after &&
 	printf "%64s\n" a b c >>after &&
 	printf "\t%s\n" 4 5 6 >>after &&
-	git diff --no-index before after |
-		sed -e "s/before/test-1/" -e "s/after/test-1/" >patch1.patch &&
+	test_expect_code 1 git diff --no-index before after >patch1.patch.raw &&
+	sed -e "s/before/test-1/" -e "s/after/test-1/" patch1.patch.raw >patch1.patch &&
 	printf "%64s\n" 1 2 3 4 5 6 >test-1 &&
 	printf "%64s\n" 1 2 3 a b c 4 5 6 >expect-1 &&
 
@@ -33,8 +33,8 @@ test_expect_success setup '
 		x=$(( $x + 1 ))
 	done &&
 	printf "\t%s\n" d e f >>after &&
-	git diff --no-index before after |
-		sed -e "s/before/test-2/" -e "s/after/test-2/" >patch2.patch &&
+	test_expect_code 1 git diff --no-index before after >patch2.patch.raw &&
+	sed -e "s/before/test-2/" -e "s/after/test-2/" patch2.patch.raw >patch2.patch &&
 	printf "%64s\n" a b c d e f >test-2 &&
 	printf "%64s\n" a b c >expect-2 &&
 	x=1 &&
@@ -56,8 +56,8 @@ test_expect_success setup '
 		x=$(( $x + 1 ))
 	done &&
 	printf "\t%s\n" d e f >>after &&
-	git diff --no-index before after |
-	sed -e "s/before/test-3/" -e "s/after/test-3/" >patch3.patch &&
+	test_expect_code 1 git diff --no-index before after >patch3.patch.raw &&
+	sed -e "s/before/test-3/" -e "s/after/test-3/" patch3.patch.raw >patch3.patch &&
 	printf "%64s\n" a b c d e f >test-3 &&
 	printf "%64s\n" a b c >expect-3 &&
 	x=0 &&
@@ -84,8 +84,8 @@ test_expect_success setup '
 		printf "\t%02d\n" $x >>after
 		x=$(( $x + 1 ))
 	done &&
-	git diff --no-index before after |
-	sed -e "s/before/test-4/" -e "s/after/test-4/" >patch4.patch &&
+	test_expect_code 1 git diff --no-index before after >patch4.patch.raw &&
+	sed -e "s/before/test-4/" -e "s/after/test-4/" patch4.patch.raw >patch4.patch &&
 	>test-4 &&
 	x=0 &&
 	while test $x -lt 50
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v4 12/27] t5317: stop losing return codes of git commands
  2019-11-26  1:17     ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                         ` (10 preceding siblings ...)
  2019-11-26  1:18       ` [PATCH v4 11/27] t4138: stop losing return codes of git commands Denton Liu
@ 2019-11-26  1:18       ` " Denton Liu
  2019-11-26  1:18       ` [PATCH v4 13/27] t5317: use ! grep to check for no matching lines Denton Liu
                         ` (15 subsequent siblings)
  27 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-26  1:18 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Currently, there are two ways where the return codes of git commands are
lost. The first way is when a command is in the upstream of a pipe. In a
pipe, only the return code of the last command is used. Thus, all other
commands will have their return codes masked. Rewrite pipes so that
there are no git commands upstream.

The other way is when a command is in a non-assignment command
substitution. The return code will be lost in favour of the surrounding
command's. Rewrite instances of this such that git commands output to a
file and surrounding commands only call command substitutions with
non-git commands.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5317-pack-objects-filter-objects.sh | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/t/t5317-pack-objects-filter-objects.sh b/t/t5317-pack-objects-filter-objects.sh
index 2d2f5d0229..a8bbad74e2 100755
--- a/t/t5317-pack-objects-filter-objects.sh
+++ b/t/t5317-pack-objects-filter-objects.sh
@@ -72,7 +72,8 @@ test_expect_success 'get an error for missing tree object' '
 	echo foo >r5/foo &&
 	git -C r5 add foo &&
 	git -C r5 commit -m "foo" &&
-	del=$(git -C r5 rev-parse HEAD^{tree} | sed "s|..|&/|") &&
+	git -C r5 rev-parse HEAD^{tree} >tree &&
+	del=$(sed "s|..|&/|" tree) &&
 	rm r5/.git/objects/$del &&
 	test_must_fail git -C r5 pack-objects --revs --stdout 2>bad_tree <<-EOF &&
 	HEAD
@@ -230,10 +231,9 @@ test_expect_success 'verify explicitly specifying oversized blob in input' '
 	awk -f print_2.awk ls_files_result |
 	sort >expected &&
 
-	git -C r2 pack-objects --revs --stdout --filter=blob:limit=1k >filter.pack <<-EOF &&
-	HEAD
-	$(git -C r2 rev-parse HEAD:large.10000)
-	EOF
+	echo HEAD >objects &&
+	git -C r2 rev-parse HEAD:large.10000 >>objects &&
+	git -C r2 pack-objects --revs --stdout --filter=blob:limit=1k <objects >filter.pack &&
 	git -C r2 index-pack ../filter.pack &&
 
 	git -C r2 verify-pack -v ../filter.pack >verify_result &&
@@ -377,7 +377,8 @@ test_expect_success 'verify sparse:oid=OID' '
 	awk -f print_2.awk ls_files_result |
 	sort >expected &&
 
-	oid=$(git -C r4 ls-files -s pattern | awk -f print_2.awk) &&
+	git -C r4 ls-files -s pattern >staged &&
+	oid=$(awk -f print_2.awk staged) &&
 	git -C r4 pack-objects --revs --stdout --filter=sparse:oid=$oid >filter.pack <<-EOF &&
 	HEAD
 	EOF
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v4 13/27] t5317: use ! grep to check for no matching lines
  2019-11-26  1:17     ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                         ` (11 preceding siblings ...)
  2019-11-26  1:18       ` [PATCH v4 12/27] t5317: " Denton Liu
@ 2019-11-26  1:18       ` Denton Liu
  2019-11-26  1:18       ` [PATCH v4 14/27] t5703: simplify one-time-sed generation logic Denton Liu
                         ` (14 subsequent siblings)
  27 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-26  1:18 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Several times in t5317, we would use `wc -l` to ensure that a grep
result is empty. However, grep already has a way to do that... Its
return code! Use `! grep` in the cases where we are ensuring that there
are no matching lines.

While at it, drop unnecessary invocations of `awk` and `sort` in each
affected test since those commands do not influence the outcome. It's
not clear why that extra work was being done in the first place, and the
code's history doesn't shed any light on the matter since these tests
were simply born this way[1], likely due to copy-paste programming. The
unnecessary work wasn't noticed even when the code was later touched for
various cleanups[2][3].

[1]: 9535ce7337 (pack-objects: add list-objects filtering, 2017-11-21)
[2]: bdbc17e86a (tests: standardize pipe placement, 2018-10-05)
[3]: 61de0ff695 (tests: don't swallow Git errors upstream of pipes, 2018-10-05)

Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5317-pack-objects-filter-objects.sh | 21 +++------------------
 1 file changed, 3 insertions(+), 18 deletions(-)

diff --git a/t/t5317-pack-objects-filter-objects.sh b/t/t5317-pack-objects-filter-objects.sh
index a8bbad74e2..dc0446574b 100755
--- a/t/t5317-pack-objects-filter-objects.sh
+++ b/t/t5317-pack-objects-filter-objects.sh
@@ -45,12 +45,7 @@ test_expect_success 'verify blob:none packfile has no blobs' '
 	git -C r1 index-pack ../filter.pack &&
 
 	git -C r1 verify-pack -v ../filter.pack >verify_result &&
-	grep blob verify_result |
-	awk -f print_1.awk |
-	sort >observed &&
-
-	nr=$(wc -l <observed) &&
-	test 0 -eq $nr
+	! grep blob verify_result
 '
 
 test_expect_success 'verify normal and blob:none packfiles have same commits/trees' '
@@ -149,12 +144,7 @@ test_expect_success 'verify blob:limit=500 omits all blobs' '
 	git -C r2 index-pack ../filter.pack &&
 
 	git -C r2 verify-pack -v ../filter.pack >verify_result &&
-	grep blob verify_result |
-	awk -f print_1.awk |
-	sort >observed &&
-
-	nr=$(wc -l <observed) &&
-	test 0 -eq $nr
+	! grep blob verify_result
 '
 
 test_expect_success 'verify blob:limit=1000' '
@@ -164,12 +154,7 @@ test_expect_success 'verify blob:limit=1000' '
 	git -C r2 index-pack ../filter.pack &&
 
 	git -C r2 verify-pack -v ../filter.pack >verify_result &&
-	grep blob verify_result |
-	awk -f print_1.awk |
-	sort >observed &&
-
-	nr=$(wc -l <observed) &&
-	test 0 -eq $nr
+	! grep blob verify_result
 '
 
 test_expect_success 'verify blob:limit=1001' '
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v4 14/27] t5703: simplify one-time-sed generation logic
  2019-11-26  1:17     ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                         ` (12 preceding siblings ...)
  2019-11-26  1:18       ` [PATCH v4 13/27] t5317: use ! grep to check for no matching lines Denton Liu
@ 2019-11-26  1:18       ` Denton Liu
  2019-11-26  1:18       ` [PATCH v4 15/27] t5703: stop losing return codes of git commands Denton Liu
                         ` (13 subsequent siblings)
  27 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-26  1:18 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

In inconsistency(), we had two `git rev-parse` invocations in the
upstream of a pipe within a command substitution. In case this
invocation ever failed, its exit code would be swallowed up and we would
not know about it.

Pull the command substitutions out into variable assignments so that
their return codes are not lost.

Drop the pipe into `tr` because the $(...) substitution already takes
care of stripping out newlines, so the `tr` invocations in the code are
superfluous.

Finally, given the way the tests actually employ "one-time-sed" via
$(cat one-time-sed) in t/lib-httpd/apply-one-time-sed.sh, convert the
`printf` into an `echo`. This makes it consistent with the final "server
loses a ref - ref in want" test, which does use `echo` rather than
`printf`.

Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5703-upload-pack-ref-in-want.sh | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/t/t5703-upload-pack-ref-in-want.sh b/t/t5703-upload-pack-ref-in-want.sh
index 3a2c143c6d..88338c4e09 100755
--- a/t/t5703-upload-pack-ref-in-want.sh
+++ b/t/t5703-upload-pack-ref-in-want.sh
@@ -312,10 +312,9 @@ inconsistency () {
 	# repository appears to change during negotiation, for example, when
 	# different servers in a load-balancing arrangement serve (stateless)
 	# RPCs during a single negotiation.
-	printf "s/%s/%s/" \
-	       $(git -C "$REPO" rev-parse $1 | tr -d "\n") \
-	       $(git -C "$REPO" rev-parse $2 | tr -d "\n") \
-	       >"$HTTPD_ROOT_PATH/one-time-sed"
+	oid1=$(git -C "$REPO" rev-parse $1) &&
+	oid2=$(git -C "$REPO" rev-parse $2) &&
+	echo "s/$oid1/$oid2/" >"$HTTPD_ROOT_PATH/one-time-sed"
 }
 
 test_expect_success 'server is initially ahead - no ref in want' '
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v4 15/27] t5703: stop losing return codes of git commands
  2019-11-26  1:17     ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                         ` (13 preceding siblings ...)
  2019-11-26  1:18       ` [PATCH v4 14/27] t5703: simplify one-time-sed generation logic Denton Liu
@ 2019-11-26  1:18       ` Denton Liu
  2019-11-26  1:18       ` [PATCH v4 16/27] t7501: remove spaces after redirect operators Denton Liu
                         ` (12 subsequent siblings)
  27 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-26  1:18 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Currently, there are two ways where the return codes of git commands are
lost. The first way is when a command is in the upstream of a pipe. In a
pipe, only the return code of the last command is used. Thus, all other
commands will have their return codes masked. Rewrite pipes so that
there are no git commands upstream.

The other way is when a command is in a non-assignment command
substitution. The return code will be lost in favour of the surrounding
command's. Rewrite instances of this such that git commands are in an
assignment-only command substitution.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5703-upload-pack-ref-in-want.sh | 46 +++++++++++++++++++-----------
 1 file changed, 29 insertions(+), 17 deletions(-)

diff --git a/t/t5703-upload-pack-ref-in-want.sh b/t/t5703-upload-pack-ref-in-want.sh
index 88338c4e09..1424fabd4a 100755
--- a/t/t5703-upload-pack-ref-in-want.sh
+++ b/t/t5703-upload-pack-ref-in-want.sh
@@ -18,14 +18,16 @@ get_actual_commits () {
 		p
 		}' <out | test-tool pkt-line unpack-sideband >o.pack &&
 	git index-pack o.pack &&
-	git verify-pack -v o.idx | grep commit | cut -c-40 | sort >actual_commits
+	git verify-pack -v o.idx >objs &&
+	grep commit objs | cut -c-40 | sort >actual_commits
 }
 
 check_output () {
 	get_actual_refs &&
 	test_cmp expected_refs actual_refs &&
 	get_actual_commits &&
-	test_cmp expected_commits actual_commits
+	sort expected_commits >sorted_commits &&
+	test_cmp sorted_commits actual_commits
 }
 
 # c(o/foo) d(o/bar)
@@ -75,17 +77,19 @@ test_expect_success 'invalid want-ref line' '
 '
 
 test_expect_success 'basic want-ref' '
+	oid=$(git rev-parse f) &&
 	cat >expected_refs <<-EOF &&
-	$(git rev-parse f) refs/heads/master
+	$oid refs/heads/master
 	EOF
-	git rev-parse f | sort >expected_commits &&
+	git rev-parse f >expected_commits &&
 
+	oid=$(git rev-parse a) &&
 	test-tool pkt-line pack >in <<-EOF &&
 	command=fetch
 	0001
 	no-progress
 	want-ref refs/heads/master
-	have $(git rev-parse a)
+	have $oid
 	done
 	0000
 	EOF
@@ -95,19 +99,22 @@ test_expect_success 'basic want-ref' '
 '
 
 test_expect_success 'multiple want-ref lines' '
+	oid_c=$(git rev-parse c) &&
+	oid_d=$(git rev-parse d) &&
 	cat >expected_refs <<-EOF &&
-	$(git rev-parse c) refs/heads/o/foo
-	$(git rev-parse d) refs/heads/o/bar
+	$oid_c refs/heads/o/foo
+	$oid_d refs/heads/o/bar
 	EOF
-	git rev-parse c d | sort >expected_commits &&
+	git rev-parse c d >expected_commits &&
 
+	oid=$(git rev-parse b) &&
 	test-tool pkt-line pack >in <<-EOF &&
 	command=fetch
 	0001
 	no-progress
 	want-ref refs/heads/o/foo
 	want-ref refs/heads/o/bar
-	have $(git rev-parse b)
+	have $oid
 	done
 	0000
 	EOF
@@ -117,10 +124,11 @@ test_expect_success 'multiple want-ref lines' '
 '
 
 test_expect_success 'mix want and want-ref' '
+	oid=$(git rev-parse f) &&
 	cat >expected_refs <<-EOF &&
-	$(git rev-parse f) refs/heads/master
+	$oid refs/heads/master
 	EOF
-	git rev-parse e f | sort >expected_commits &&
+	git rev-parse e f >expected_commits &&
 
 	test-tool pkt-line pack >in <<-EOF &&
 	command=fetch
@@ -138,17 +146,19 @@ test_expect_success 'mix want and want-ref' '
 '
 
 test_expect_success 'want-ref with ref we already have commit for' '
+	oid=$(git rev-parse c) &&
 	cat >expected_refs <<-EOF &&
-	$(git rev-parse c) refs/heads/o/foo
+	$oid refs/heads/o/foo
 	EOF
 	>expected_commits &&
 
+	oid=$(git rev-parse c) &&
 	test-tool pkt-line pack >in <<-EOF &&
 	command=fetch
 	0001
 	no-progress
 	want-ref refs/heads/o/foo
-	have $(git rev-parse c)
+	have $oid
 	done
 	0000
 	EOF
@@ -211,13 +221,14 @@ test_expect_success 'fetching with exact OID' '
 
 	rm -rf local &&
 	cp -r "$LOCAL_PRISTINE" local &&
+	oid=$(git -C "$REPO" rev-parse d) &&
 	GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin \
-		$(git -C "$REPO" rev-parse d):refs/heads/actual &&
+		"$oid":refs/heads/actual &&
 
 	git -C "$REPO" rev-parse "d" >expected &&
 	git -C local rev-parse refs/heads/actual >actual &&
 	test_cmp expected actual &&
-	grep "want $(git -C "$REPO" rev-parse d)" log
+	grep "want $oid" log
 '
 
 test_expect_success 'fetching multiple refs' '
@@ -239,13 +250,14 @@ test_expect_success 'fetching ref and exact OID' '
 
 	rm -rf local &&
 	cp -r "$LOCAL_PRISTINE" local &&
+	oid=$(git -C "$REPO" rev-parse b) &&
 	GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin \
-		master $(git -C "$REPO" rev-parse b):refs/heads/actual &&
+		master "$oid":refs/heads/actual &&
 
 	git -C "$REPO" rev-parse "master" "b" >expected &&
 	git -C local rev-parse refs/remotes/origin/master refs/heads/actual >actual &&
 	test_cmp expected actual &&
-	grep "want $(git -C "$REPO" rev-parse b)" log &&
+	grep "want $oid" log &&
 	grep "want-ref refs/heads/master" log
 '
 
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v4 16/27] t7501: remove spaces after redirect operators
  2019-11-26  1:17     ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                         ` (14 preceding siblings ...)
  2019-11-26  1:18       ` [PATCH v4 15/27] t5703: stop losing return codes of git commands Denton Liu
@ 2019-11-26  1:18       ` Denton Liu
  2019-11-26  1:18       ` [PATCH v4 17/27] t7501: stop losing return codes of git commands Denton Liu
                         ` (11 subsequent siblings)
  27 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-26  1:18 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

For shell scripts, the usual convention is for there to be no space
after redirection operators, (e.g. `>file`, not `> file`). Remove these
spaces wherever they appear.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7501-commit-basic-functionality.sh | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/t/t7501-commit-basic-functionality.sh b/t/t7501-commit-basic-functionality.sh
index f1349af56e..5765d33c53 100755
--- a/t/t7501-commit-basic-functionality.sh
+++ b/t/t7501-commit-basic-functionality.sh
@@ -150,7 +150,7 @@ test_expect_success 'setup: commit message from file' '
 test_expect_success 'amend commit' '
 	cat >editor <<-\EOF &&
 	#!/bin/sh
-	sed -e "s/a file/an amend commit/g" < "$1" > "$1-"
+	sed -e "s/a file/an amend commit/g" <"$1" >"$1-"
 	mv "$1-" "$1"
 	EOF
 	chmod 755 editor &&
@@ -263,7 +263,7 @@ test_expect_success 'using message from other commit' '
 test_expect_success 'editing message from other commit' '
 	cat >editor <<-\EOF &&
 	#!/bin/sh
-	sed -e "s/amend/older/g"  < "$1" > "$1-"
+	sed -e "s/amend/older/g"  <"$1" >"$1-"
 	mv "$1-" "$1"
 	EOF
 	chmod 755 editor &&
@@ -367,7 +367,7 @@ test_expect_success 'amend commit to fix author' '
 		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
 		expected &&
 	git commit --amend --author="$author" &&
-	git cat-file -p HEAD > current &&
+	git cat-file -p HEAD >current &&
 	test_cmp expected current
 
 '
@@ -382,7 +382,7 @@ test_expect_success 'amend commit to fix date' '
 		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
 		expected &&
 	git commit --amend --date="$newtick" &&
-	git cat-file -p HEAD > current &&
+	git cat-file -p HEAD >current &&
 	test_cmp expected current
 
 '
@@ -448,7 +448,7 @@ test_expect_success 'signoff gap' '
 	git commit -s -m "welcome
 
 $alt" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
+	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
 	(
 		echo welcome &&
 		echo &&
@@ -468,7 +468,7 @@ test_expect_success 'signoff gap 2' '
 
 We have now
 $alt" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
+	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
 	(
 		echo welcome &&
 		echo &&
@@ -489,7 +489,7 @@ test_expect_success 'signoff respects trailer config' '
 
 non-trailer line
 Myfooter: x" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
+	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
 	(
 		echo subject &&
 		echo &&
@@ -506,7 +506,7 @@ Myfooter: x" &&
 
 non-trailer line
 Myfooter: x" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
+	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
 	(
 		echo subject &&
 		echo &&
@@ -560,14 +560,14 @@ test_expect_success 'amend commit to fix author' '
 		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
 		expected &&
 	git commit --amend --author="$author" &&
-	git cat-file -p HEAD > current &&
+	git cat-file -p HEAD >current &&
 	test_cmp expected current
 
 '
 
 test_expect_success 'git commit <file> with dirty index' '
-	echo tacocat > elif &&
-	echo tehlulz > chz &&
+	echo tacocat >elif &&
+	echo tehlulz >chz &&
 	git add chz &&
 	git commit elif -m "tacocat is a palindrome" &&
 	git show --stat | grep elif &&
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v4 17/27] t7501: stop losing return codes of git commands
  2019-11-26  1:17     ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                         ` (15 preceding siblings ...)
  2019-11-26  1:18       ` [PATCH v4 16/27] t7501: remove spaces after redirect operators Denton Liu
@ 2019-11-26  1:18       ` Denton Liu
  2019-11-26  1:18       ` [PATCH v4 18/27] t7700: drop redirections to /dev/null Denton Liu
                         ` (10 subsequent siblings)
  27 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-26  1:18 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

In a pipe, only the return code of the last command is used. Thus, all
other commands will have their return codes masked. Rewrite pipes so
that there are no git commands upstream so that we will know if a
command fails.

In the 'interactive add' test case, we prepend a `test_must_fail` to
`git commit --interactive`. When there are no changes to commit,
`git commit` will exit with status code 1. Following along with the rest
of the file, we use `test_must_fail` to test for this case.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7501-commit-basic-functionality.sh | 69 +++++++++++++++------------
 1 file changed, 39 insertions(+), 30 deletions(-)

diff --git a/t/t7501-commit-basic-functionality.sh b/t/t7501-commit-basic-functionality.sh
index 5765d33c53..110b4bf459 100755
--- a/t/t7501-commit-basic-functionality.sh
+++ b/t/t7501-commit-basic-functionality.sh
@@ -285,9 +285,8 @@ test_expect_success 'overriding author from command line' '
 '
 
 test_expect_success PERL 'interactive add' '
-	echo 7 |
-	git commit --interactive |
-	grep "What now"
+	echo 7 | test_must_fail git commit --interactive >out &&
+	grep "What now" out
 '
 
 test_expect_success PERL "commit --interactive doesn't change index if editor aborts" '
@@ -362,10 +361,10 @@ test_expect_success 'amend commit to fix author' '
 	oldtick=$GIT_AUTHOR_DATE &&
 	test_tick &&
 	git reset --hard &&
-	git cat-file -p HEAD |
+	git cat-file -p HEAD >commit &&
 	sed -e "s/author.*/author $author $oldtick/" \
-		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
-		expected &&
+		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" \
+		commit >expected &&
 	git commit --amend --author="$author" &&
 	git cat-file -p HEAD >current &&
 	test_cmp expected current
@@ -377,10 +376,10 @@ test_expect_success 'amend commit to fix date' '
 	test_tick &&
 	newtick=$GIT_AUTHOR_DATE &&
 	git reset --hard &&
-	git cat-file -p HEAD |
+	git cat-file -p HEAD >commit &&
 	sed -e "s/author.*/author $author $newtick/" \
-		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
-		expected &&
+		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" \
+		commit >expected &&
 	git commit --amend --date="$newtick" &&
 	git cat-file -p HEAD >current &&
 	test_cmp expected current
@@ -409,12 +408,13 @@ test_expect_success 'sign off (1)' '
 	echo 1 >positive &&
 	git add positive &&
 	git commit -s -m "thank you" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
+	git cat-file commit HEAD >commit &&
+	sed -e "1,/^\$/d" commit >actual &&
 	(
 		echo thank you &&
 		echo &&
-		git var GIT_COMMITTER_IDENT |
-		sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
+		git var GIT_COMMITTER_IDENT >ident &&
+		sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" ident
 	) >expected &&
 	test_cmp expected actual
 
@@ -428,13 +428,14 @@ test_expect_success 'sign off (2)' '
 	git commit -s -m "thank you
 
 $existing" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
+	git cat-file commit HEAD >commit &&
+	sed -e "1,/^\$/d" commit >actual &&
 	(
 		echo thank you &&
 		echo &&
 		echo $existing &&
-		git var GIT_COMMITTER_IDENT |
-		sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
+		git var GIT_COMMITTER_IDENT >ident &&
+		sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" ident
 	) >expected &&
 	test_cmp expected actual
 
@@ -448,13 +449,14 @@ test_expect_success 'signoff gap' '
 	git commit -s -m "welcome
 
 $alt" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
+	git cat-file commit HEAD >commit &&
+	sed -e "1,/^\$/d" commit >actual &&
 	(
 		echo welcome &&
 		echo &&
 		echo $alt &&
-		git var GIT_COMMITTER_IDENT |
-		sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
+		git var GIT_COMMITTER_IDENT >ident &&
+		sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" ident
 	) >expected &&
 	test_cmp expected actual
 '
@@ -468,15 +470,16 @@ test_expect_success 'signoff gap 2' '
 
 We have now
 $alt" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
+	git cat-file commit HEAD >commit &&
+	sed -e "1,/^\$/d" commit >actual &&
 	(
 		echo welcome &&
 		echo &&
 		echo We have now &&
 		echo $alt &&
 		echo &&
-		git var GIT_COMMITTER_IDENT |
-		sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
+		git var GIT_COMMITTER_IDENT >ident &&
+		sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" ident
 	) >expected &&
 	test_cmp expected actual
 '
@@ -489,7 +492,8 @@ test_expect_success 'signoff respects trailer config' '
 
 non-trailer line
 Myfooter: x" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
+	git cat-file commit HEAD >commit &&
+	sed -e "1,/^\$/d" commit >actual &&
 	(
 		echo subject &&
 		echo &&
@@ -506,7 +510,8 @@ Myfooter: x" &&
 
 non-trailer line
 Myfooter: x" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
+	git cat-file commit HEAD >commit &&
+	sed -e "1,/^\$/d" commit >actual &&
 	(
 		echo subject &&
 		echo &&
@@ -538,7 +543,8 @@ test_expect_success 'multiple -m' '
 	>negative &&
 	git add negative &&
 	git commit -m "one" -m "two" -m "three" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
+	git cat-file commit HEAD >commit &&
+	sed -e "1,/^\$/d" commit >actual &&
 	(
 		echo one &&
 		echo &&
@@ -555,10 +561,10 @@ test_expect_success 'amend commit to fix author' '
 	oldtick=$GIT_AUTHOR_DATE &&
 	test_tick &&
 	git reset --hard &&
-	git cat-file -p HEAD |
+	git cat-file -p HEAD >commit &&
 	sed -e "s/author.*/author $author $oldtick/" \
-		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
-		expected &&
+		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" \
+		commit >expected &&
 	git commit --amend --author="$author" &&
 	git cat-file -p HEAD >current &&
 	test_cmp expected current
@@ -570,8 +576,10 @@ test_expect_success 'git commit <file> with dirty index' '
 	echo tehlulz >chz &&
 	git add chz &&
 	git commit elif -m "tacocat is a palindrome" &&
-	git show --stat | grep elif &&
-	git diff --cached | grep chz
+	git show --stat >stat &&
+	grep elif stat &&
+	git diff --cached >diff &&
+	grep chz diff
 '
 
 test_expect_success 'same tree (single parent)' '
@@ -584,7 +592,8 @@ test_expect_success 'same tree (single parent)' '
 test_expect_success 'same tree (single parent) --allow-empty' '
 
 	git commit --allow-empty -m "forced empty" &&
-	git cat-file commit HEAD | grep forced
+	git cat-file commit HEAD >commit &&
+	grep forced commit
 
 '
 
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v4 18/27] t7700: drop redirections to /dev/null
  2019-11-26  1:17     ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                         ` (16 preceding siblings ...)
  2019-11-26  1:18       ` [PATCH v4 17/27] t7501: stop losing return codes of git commands Denton Liu
@ 2019-11-26  1:18       ` Denton Liu
  2019-11-26  1:18       ` [PATCH v4 19/27] t7700: remove spaces after redirect operators Denton Liu
                         ` (9 subsequent siblings)
  27 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-26  1:18 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Since output is silenced when running without `-v` and debugging output
is useful with `-v`, remove redirections to /dev/null as it is not
useful.

In one case where the output of stdout is consumed, redirect the output
of test_commit to stderr.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7700-repack.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index 4e855bc21b..e1a689d6a9 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -5,7 +5,7 @@ test_description='git repack works correctly'
 . ./test-lib.sh
 
 commit_and_pack() {
-	test_commit "$@" >/dev/null &&
+	test_commit "$@" 1>&2 &&
 	SHA1=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) &&
 	echo pack-${SHA1}.pack
 }
@@ -19,7 +19,7 @@ test_expect_success 'objects in packs marked .keep are not repacked' '
 	# Create two packs
 	# The first pack will contain all of the objects except one
 	git rev-list --objects --all | grep -v file2 |
-		git pack-objects pack > /dev/null &&
+		git pack-objects pack &&
 	# The second pack will contain the excluded object
 	packsha1=$(git rev-list --objects --all | grep file2 |
 		git pack-objects pack) &&
@@ -235,7 +235,7 @@ test_expect_success 'incremental repack does not complain' '
 
 test_expect_success 'bitmaps can be disabled on bare repos' '
 	git -c repack.writeBitmaps=false -C bare.git repack -ad &&
-	bitmap=$(ls bare.git/objects/pack/*.bitmap 2>/dev/null || :) &&
+	bitmap=$(ls bare.git/objects/pack/*.bitmap || :) &&
 	test -z "$bitmap"
 '
 
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v4 19/27] t7700: remove spaces after redirect operators
  2019-11-26  1:17     ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                         ` (17 preceding siblings ...)
  2019-11-26  1:18       ` [PATCH v4 18/27] t7700: drop redirections to /dev/null Denton Liu
@ 2019-11-26  1:18       ` Denton Liu
  2019-11-26  1:18       ` [PATCH v4 20/27] t7700: move keywords onto their own line Denton Liu
                         ` (8 subsequent siblings)
  27 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-26  1:18 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

For shell scripts, the usual convention is for there to be no space
after redirection operators, (e.g. `>file`, not `> file`). Remove these
spaces wherever they appear.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7700-repack.sh | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index e1a689d6a9..8936928387 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -11,8 +11,8 @@ commit_and_pack() {
 }
 
 test_expect_success 'objects in packs marked .keep are not repacked' '
-	echo content1 > file1 &&
-	echo content2 > file2 &&
+	echo content1 >file1 &&
+	echo content2 >file2 &&
 	git add . &&
 	test_tick &&
 	git commit -m initial_commit &&
@@ -75,8 +75,8 @@ test_expect_success 'writing bitmaps via config can duplicate .keep objects' '
 
 test_expect_success 'loose objects in alternate ODB are not repacked' '
 	mkdir alt_objects &&
-	echo $(pwd)/alt_objects > .git/objects/info/alternates &&
-	echo content3 > file3 &&
+	echo $(pwd)/alt_objects >.git/objects/info/alternates &&
+	echo content3 >file3 &&
 	objsha1=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) &&
 	git add file3 &&
 	test_tick &&
@@ -111,7 +111,7 @@ test_expect_success 'packed obs in alt ODB are repacked even when local repo is
 
 test_expect_success 'packed obs in alt ODB are repacked when local repo has packs' '
 	rm -f .git/objects/pack/* &&
-	echo new_content >> file1 &&
+	echo new_content >>file1 &&
 	git add file1 &&
 	test_tick &&
 	git commit -m more_content &&
@@ -169,12 +169,12 @@ test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
 	mv pack-* .git/objects/pack/ &&
 	test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
 		egrep "^$csha1 " | sort | uniq | wc -l) &&
-	echo > .git/objects/info/alternates &&
+	echo >.git/objects/info/alternates &&
 	test_must_fail git show $csha1
 '
 
 test_expect_success 'local packed unreachable obs that exist in alternate ODB are not loosened' '
-	echo $(pwd)/alt_objects > .git/objects/info/alternates &&
+	echo $(pwd)/alt_objects >.git/objects/info/alternates &&
 	echo "$csha1" | git pack-objects --non-empty --all --reflog pack &&
 	rm -f .git/objects/pack/* &&
 	mv pack-* .git/objects/pack/ &&
@@ -186,7 +186,7 @@ test_expect_success 'local packed unreachable obs that exist in alternate ODB ar
 	mv pack-* .git/objects/pack/ &&
 	test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
 		egrep "^$csha1 " | sort | uniq | wc -l) &&
-	echo > .git/objects/info/alternates &&
+	echo >.git/objects/info/alternates &&
 	test_must_fail git show $csha1
 '
 
@@ -196,7 +196,7 @@ test_expect_success 'objects made unreachable by grafts only are kept' '
 	H0=$(git rev-parse HEAD) &&
 	H1=$(git rev-parse HEAD^) &&
 	H2=$(git rev-parse HEAD^^) &&
-	echo "$H0 $H2" > .git/info/grafts &&
+	echo "$H0 $H2" >.git/info/grafts &&
 	git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all &&
 	git repack -a -d &&
 	git cat-file -t $H1
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v4 20/27] t7700: move keywords onto their own line
  2019-11-26  1:17     ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                         ` (18 preceding siblings ...)
  2019-11-26  1:18       ` [PATCH v4 19/27] t7700: remove spaces after redirect operators Denton Liu
@ 2019-11-26  1:18       ` Denton Liu
  2019-11-26  1:18       ` [PATCH v4 21/27] t7700: s/test -f/test_path_is_file/ Denton Liu
                         ` (7 subsequent siblings)
  27 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-26  1:18 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

The code style for tests is to have statements on their own line if
possible. Move keywords onto their own line so that they conform with
the test style.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7700-repack.sh | 51 +++++++++++++++++++++++++++++++----------------
 1 file changed, 34 insertions(+), 17 deletions(-)

diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index 8936928387..a96e876c4e 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -29,10 +29,12 @@ test_expect_success 'objects in packs marked .keep are not repacked' '
 	mv pack-* .git/objects/pack/ &&
 	git repack -A -d -l &&
 	git prune-packed &&
-	for p in .git/objects/pack/*.idx; do
+	for p in .git/objects/pack/*.idx
+	do
 		idx=$(basename $p)
 		test "pack-$packsha1.idx" = "$idx" && continue
-		if git verify-pack -v $p | egrep "^$objsha1"; then
+		if git verify-pack -v $p | egrep "^$objsha1"
+		then
 			found_duplicate_object=1
 			echo "DUPLICATE OBJECT FOUND"
 			break
@@ -45,10 +47,12 @@ test_expect_success 'writing bitmaps via command-line can duplicate .keep object
 	# build on $objsha1, $packsha1, and .keep state from previous
 	git repack -Adbl &&
 	test_when_finished "found_duplicate_object=" &&
-	for p in .git/objects/pack/*.idx; do
+	for p in .git/objects/pack/*.idx
+	do
 		idx=$(basename $p)
 		test "pack-$packsha1.idx" = "$idx" && continue
-		if git verify-pack -v $p | egrep "^$objsha1"; then
+		if git verify-pack -v $p | egrep "^$objsha1"
+		then
 			found_duplicate_object=1
 			echo "DUPLICATE OBJECT FOUND"
 			break
@@ -61,10 +65,12 @@ test_expect_success 'writing bitmaps via config can duplicate .keep objects' '
 	# build on $objsha1, $packsha1, and .keep state from previous
 	git -c repack.writebitmaps=true repack -Adl &&
 	test_when_finished "found_duplicate_object=" &&
-	for p in .git/objects/pack/*.idx; do
+	for p in .git/objects/pack/*.idx
+	do
 		idx=$(basename $p)
 		test "pack-$packsha1.idx" = "$idx" && continue
-		if git verify-pack -v $p | egrep "^$objsha1"; then
+		if git verify-pack -v $p | egrep "^$objsha1"
+		then
 			found_duplicate_object=1
 			echo "DUPLICATE OBJECT FOUND"
 			break
@@ -83,8 +89,10 @@ test_expect_success 'loose objects in alternate ODB are not repacked' '
 	git commit -m commit_file3 &&
 	git repack -a -d -l &&
 	git prune-packed &&
-	for p in .git/objects/pack/*.idx; do
-		if git verify-pack -v $p | egrep "^$objsha1"; then
+	for p in .git/objects/pack/*.idx
+	do
+		if git verify-pack -v $p | egrep "^$objsha1"
+		then
 			found_duplicate_object=1
 			echo "DUPLICATE OBJECT FOUND"
 			break
@@ -99,10 +107,13 @@ test_expect_success 'packed obs in alt ODB are repacked even when local repo is
 	git repack -a &&
 	myidx=$(ls -1 .git/objects/pack/*.idx) &&
 	test -f "$myidx" &&
-	for p in alt_objects/pack/*.idx; do
+	for p in alt_objects/pack/*.idx
+	do
 		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
-	done | while read sha1 rest; do
-		if ! ( git verify-pack -v $myidx | grep "^$sha1" ); then
+	done | while read sha1 rest
+	do
+		if ! ( git verify-pack -v $myidx | grep "^$sha1" )
+		then
 			echo "Missing object in local pack: $sha1"
 			return 1
 		fi
@@ -119,10 +130,13 @@ test_expect_success 'packed obs in alt ODB are repacked when local repo has pack
 	git repack -a -d &&
 	myidx=$(ls -1 .git/objects/pack/*.idx) &&
 	test -f "$myidx" &&
-	for p in alt_objects/pack/*.idx; do
+	for p in alt_objects/pack/*.idx
+	do
 		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
-	done | while read sha1 rest; do
-		if ! ( git verify-pack -v $myidx | grep "^$sha1" ); then
+	done | while read sha1 rest
+	do
+		if ! ( git verify-pack -v $myidx | grep "^$sha1" )
+		then
 			echo "Missing object in local pack: $sha1"
 			return 1
 		fi
@@ -144,10 +158,13 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
 	git repack -a -d &&
 	myidx=$(ls -1 .git/objects/pack/*.idx) &&
 	test -f "$myidx" &&
-	for p in alt_objects/pack/*.idx; do
+	for p in alt_objects/pack/*.idx
+	do
 		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
-	done | while read sha1 rest; do
-		if ! ( git verify-pack -v $myidx | grep "^$sha1" ); then
+	done | while read sha1 rest
+	do
+		if ! ( git verify-pack -v $myidx | grep "^$sha1" )
+		then
 			echo "Missing object in local pack: $sha1"
 			return 1
 		fi
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v4 21/27] t7700: s/test -f/test_path_is_file/
  2019-11-26  1:17     ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                         ` (19 preceding siblings ...)
  2019-11-26  1:18       ` [PATCH v4 20/27] t7700: move keywords onto their own line Denton Liu
@ 2019-11-26  1:18       ` Denton Liu
  2019-11-26  1:18       ` [PATCH v4 22/27] t7700: consolidate code into test_no_missing_in_packs() Denton Liu
                         ` (6 subsequent siblings)
  27 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-26  1:18 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Since we have debugging-friendly alternatives to `test -f`, replace
instances of `test -f` with `test_path_is_file` so that if a command
ever fails, we get better debugging information.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7700-repack.sh | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index a96e876c4e..1d14ddcbdb 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -106,7 +106,7 @@ test_expect_success 'packed obs in alt ODB are repacked even when local repo is
 	mv .git/objects/pack/* alt_objects/pack &&
 	git repack -a &&
 	myidx=$(ls -1 .git/objects/pack/*.idx) &&
-	test -f "$myidx" &&
+	test_path_is_file "$myidx" &&
 	for p in alt_objects/pack/*.idx
 	do
 		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
@@ -129,7 +129,7 @@ test_expect_success 'packed obs in alt ODB are repacked when local repo has pack
 	git repack &&
 	git repack -a -d &&
 	myidx=$(ls -1 .git/objects/pack/*.idx) &&
-	test -f "$myidx" &&
+	test_path_is_file "$myidx" &&
 	for p in alt_objects/pack/*.idx
 	do
 		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
@@ -148,7 +148,7 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
 	for p in alt_objects/pack/*.pack
 	do
 		base_name=$(basename $p .pack) &&
-		if test -f alt_objects/pack/$base_name.keep
+		if test_path_is_file alt_objects/pack/$base_name.keep
 		then
 			rm alt_objects/pack/$base_name.keep
 		else
@@ -157,7 +157,7 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
 	done &&
 	git repack -a -d &&
 	myidx=$(ls -1 .git/objects/pack/*.idx) &&
-	test -f "$myidx" &&
+	test_path_is_file "$myidx" &&
 	for p in alt_objects/pack/*.idx
 	do
 		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v4 22/27] t7700: consolidate code into test_no_missing_in_packs()
  2019-11-26  1:17     ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                         ` (20 preceding siblings ...)
  2019-11-26  1:18       ` [PATCH v4 21/27] t7700: s/test -f/test_path_is_file/ Denton Liu
@ 2019-11-26  1:18       ` Denton Liu
  2019-11-26  2:35         ` Eric Sunshine
  2019-11-26  1:18       ` [PATCH v4 23/27] squash! " Denton Liu
                         ` (5 subsequent siblings)
  27 siblings, 1 reply; 169+ messages in thread
From: Denton Liu @ 2019-11-26  1:18 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

The code to test that objects were not missing from the packfile was
duplicated many times. Extract the duplicated code into
test_no_missing_in_packs() and use that instead.

Refactor the resulting extraction so that if any git commands fail,
their return codes are not silently lost.

We were using sed to filter lines. Although not incorrect, this is
exactly what grep is built for. Replace this invocation of sed with grep
so that we use the correct tool for the job.

The original testing construct was O(n^2): it used a grep in a loop to
test whether any objects were missing in the packfile. Rewrite this to
use sort the files then use `comm -23` so that finding missing lines
from the original file is done more efficiently.

While we're at it, add a space to `commit_and_pack ()` for style.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7700-repack.sh | 59 +++++++++++++++--------------------------------
 1 file changed, 19 insertions(+), 40 deletions(-)

diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index 1d14ddcbdb..a6c3d34277 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -4,12 +4,27 @@ test_description='git repack works correctly'
 
 . ./test-lib.sh
 
-commit_and_pack() {
+commit_and_pack () {
 	test_commit "$@" 1>&2 &&
 	SHA1=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) &&
 	echo pack-${SHA1}.pack
 }
 
+test_no_missing_in_packs () {
+	myidx=$(ls -1 .git/objects/pack/*.idx) &&
+	test_path_is_file "$myidx" &&
+	for p in alt_objects/pack/*.idx
+	do
+		git verify-pack -v $p >packlist || return $?
+		grep "^[0-9a-f]\{40\}" packlist
+	done >orig.raw &&
+	cut -d" " -f1 orig.raw | sort >orig &&
+	git verify-pack -v $myidx >dest.raw &&
+	cut -d" " -f1 dest.raw | sort >dest &&
+	comm -23 orig dest >missing &&
+	test_must_be_empty missing
+}
+
 test_expect_success 'objects in packs marked .keep are not repacked' '
 	echo content1 >file1 &&
 	echo content2 >file2 &&
@@ -105,19 +120,7 @@ test_expect_success 'packed obs in alt ODB are repacked even when local repo is
 	mkdir alt_objects/pack &&
 	mv .git/objects/pack/* alt_objects/pack &&
 	git repack -a &&
-	myidx=$(ls -1 .git/objects/pack/*.idx) &&
-	test_path_is_file "$myidx" &&
-	for p in alt_objects/pack/*.idx
-	do
-		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
-	done | while read sha1 rest
-	do
-		if ! ( git verify-pack -v $myidx | grep "^$sha1" )
-		then
-			echo "Missing object in local pack: $sha1"
-			return 1
-		fi
-	done
+	test_no_missing_in_packs
 '
 
 test_expect_success 'packed obs in alt ODB are repacked when local repo has packs' '
@@ -128,19 +131,7 @@ test_expect_success 'packed obs in alt ODB are repacked when local repo has pack
 	git commit -m more_content &&
 	git repack &&
 	git repack -a -d &&
-	myidx=$(ls -1 .git/objects/pack/*.idx) &&
-	test_path_is_file "$myidx" &&
-	for p in alt_objects/pack/*.idx
-	do
-		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
-	done | while read sha1 rest
-	do
-		if ! ( git verify-pack -v $myidx | grep "^$sha1" )
-		then
-			echo "Missing object in local pack: $sha1"
-			return 1
-		fi
-	done
+	test_no_missing_in_packs
 '
 
 test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
@@ -156,19 +147,7 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
 		fi
 	done &&
 	git repack -a -d &&
-	myidx=$(ls -1 .git/objects/pack/*.idx) &&
-	test_path_is_file "$myidx" &&
-	for p in alt_objects/pack/*.idx
-	do
-		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
-	done | while read sha1 rest
-	do
-		if ! ( git verify-pack -v $myidx | grep "^$sha1" )
-		then
-			echo "Missing object in local pack: $sha1"
-			return 1
-		fi
-	done
+	test_no_missing_in_packs
 '
 
 test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v4 23/27] squash! t7700: consolidate code into test_no_missing_in_packs()
  2019-11-26  1:17     ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                         ` (21 preceding siblings ...)
  2019-11-26  1:18       ` [PATCH v4 22/27] t7700: consolidate code into test_no_missing_in_packs() Denton Liu
@ 2019-11-26  1:18       ` " Denton Liu
  2019-11-26  1:18       ` [PATCH v4 24/27] t7700: consolidate code into test_has_duplicate_object() Denton Liu
                         ` (4 subsequent siblings)
  27 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-26  1:18 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Instead of verifying each file of `alt_objects/pack/*.idx` individually
in a for-loop, batch them together into one verification step.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---

Notes:
    We should probably squash this in but before we do this, I'd like some
    confirmation that doing this doesn't have any negative impacts.

 t/t7700-repack.sh | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index a6c3d34277..4bcd9fcc80 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -13,12 +13,8 @@ commit_and_pack () {
 test_no_missing_in_packs () {
 	myidx=$(ls -1 .git/objects/pack/*.idx) &&
 	test_path_is_file "$myidx" &&
-	for p in alt_objects/pack/*.idx
-	do
-		git verify-pack -v $p >packlist || return $?
-		grep "^[0-9a-f]\{40\}" packlist
-	done >orig.raw &&
-	cut -d" " -f1 orig.raw | sort >orig &&
+	git verify-pack -v alt_objects/pack/*.idx >orig.raw &&
+	grep "^[0-9a-f]\{40\}" orig.raw | cut -d" " -f1 | sort >orig &&
 	git verify-pack -v $myidx >dest.raw &&
 	cut -d" " -f1 dest.raw | sort >dest &&
 	comm -23 orig dest >missing &&
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v4 24/27] t7700: consolidate code into test_has_duplicate_object()
  2019-11-26  1:17     ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                         ` (22 preceding siblings ...)
  2019-11-26  1:18       ` [PATCH v4 23/27] squash! " Denton Liu
@ 2019-11-26  1:18       ` Denton Liu
  2019-11-26  1:18       ` [PATCH v4 25/27] t7700: replace egrep with grep Denton Liu
                         ` (3 subsequent siblings)
  27 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-26  1:18 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

The code to test that objects were not duplicated from the packfile was
duplicated many times. Extract the duplicated code into
test_has_duplicate_object() and use that instead.

Refactor the resulting extraction so that if the git command fails,
the return code is not silently lost.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7700-repack.sh | 71 +++++++++++++++--------------------------------
 1 file changed, 23 insertions(+), 48 deletions(-)

diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index 4bcd9fcc80..5bbed02fe5 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -21,6 +21,25 @@ test_no_missing_in_packs () {
 	test_must_be_empty missing
 }
 
+# we expect $packsha1 and $objsha1 to be defined
+test_has_duplicate_object () {
+	want_duplicate_object="$1"
+	found_duplicate_object=false
+	for p in .git/objects/pack/*.idx
+	do
+		idx=$(basename $p)
+		test "pack-$packsha1.idx" = "$idx" && continue
+		git verify-pack -v $p >packlist || return $?
+		if egrep "^$objsha1" packlist
+		then
+			found_duplicate_object=true
+			echo "DUPLICATE OBJECT FOUND"
+			break
+		fi
+	done &&
+	test "$want_duplicate_object" = "$found_duplicate_object"
+}
+
 test_expect_success 'objects in packs marked .keep are not repacked' '
 	echo content1 >file1 &&
 	echo content2 >file2 &&
@@ -40,54 +59,19 @@ test_expect_success 'objects in packs marked .keep are not repacked' '
 	mv pack-* .git/objects/pack/ &&
 	git repack -A -d -l &&
 	git prune-packed &&
-	for p in .git/objects/pack/*.idx
-	do
-		idx=$(basename $p)
-		test "pack-$packsha1.idx" = "$idx" && continue
-		if git verify-pack -v $p | egrep "^$objsha1"
-		then
-			found_duplicate_object=1
-			echo "DUPLICATE OBJECT FOUND"
-			break
-		fi
-	done &&
-	test -z "$found_duplicate_object"
+	test_has_duplicate_object false
 '
 
 test_expect_success 'writing bitmaps via command-line can duplicate .keep objects' '
 	# build on $objsha1, $packsha1, and .keep state from previous
 	git repack -Adbl &&
-	test_when_finished "found_duplicate_object=" &&
-	for p in .git/objects/pack/*.idx
-	do
-		idx=$(basename $p)
-		test "pack-$packsha1.idx" = "$idx" && continue
-		if git verify-pack -v $p | egrep "^$objsha1"
-		then
-			found_duplicate_object=1
-			echo "DUPLICATE OBJECT FOUND"
-			break
-		fi
-	done &&
-	test "$found_duplicate_object" = 1
+	test_has_duplicate_object true
 '
 
 test_expect_success 'writing bitmaps via config can duplicate .keep objects' '
 	# build on $objsha1, $packsha1, and .keep state from previous
 	git -c repack.writebitmaps=true repack -Adl &&
-	test_when_finished "found_duplicate_object=" &&
-	for p in .git/objects/pack/*.idx
-	do
-		idx=$(basename $p)
-		test "pack-$packsha1.idx" = "$idx" && continue
-		if git verify-pack -v $p | egrep "^$objsha1"
-		then
-			found_duplicate_object=1
-			echo "DUPLICATE OBJECT FOUND"
-			break
-		fi
-	done &&
-	test "$found_duplicate_object" = 1
+	test_has_duplicate_object true
 '
 
 test_expect_success 'loose objects in alternate ODB are not repacked' '
@@ -100,16 +84,7 @@ test_expect_success 'loose objects in alternate ODB are not repacked' '
 	git commit -m commit_file3 &&
 	git repack -a -d -l &&
 	git prune-packed &&
-	for p in .git/objects/pack/*.idx
-	do
-		if git verify-pack -v $p | egrep "^$objsha1"
-		then
-			found_duplicate_object=1
-			echo "DUPLICATE OBJECT FOUND"
-			break
-		fi
-	done &&
-	test -z "$found_duplicate_object"
+	test_has_duplicate_object false
 '
 
 test_expect_success 'packed obs in alt ODB are repacked even when local repo is packless' '
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v4 25/27] t7700: replace egrep with grep
  2019-11-26  1:17     ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                         ` (23 preceding siblings ...)
  2019-11-26  1:18       ` [PATCH v4 24/27] t7700: consolidate code into test_has_duplicate_object() Denton Liu
@ 2019-11-26  1:18       ` Denton Liu
  2019-11-26  1:18       ` [PATCH v4 26/27] t7700: make references to SHA-1 generic Denton Liu
                         ` (2 subsequent siblings)
  27 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-26  1:18 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

The egrep expressions in this test suite were of the form `^$variable`.
Although egrep works just fine, it's overkill since we're not using any
extended regex. Replace egrep invocations with grep so that we aren't
swatting flies with a sledgehammer.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7700-repack.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index 5bbed02fe5..2493cc4e9b 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -30,7 +30,7 @@ test_has_duplicate_object () {
 		idx=$(basename $p)
 		test "pack-$packsha1.idx" = "$idx" && continue
 		git verify-pack -v $p >packlist || return $?
-		if egrep "^$objsha1" packlist
+		if grep "^$objsha1" packlist
 		then
 			found_duplicate_object=true
 			echo "DUPLICATE OBJECT FOUND"
@@ -135,7 +135,7 @@ test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
 	rm -f .git/objects/pack/* &&
 	mv pack-* .git/objects/pack/ &&
 	test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
-		egrep "^$csha1 " | sort | uniq | wc -l) &&
+		grep "^$csha1 " | sort | uniq | wc -l) &&
 	echo >.git/objects/info/alternates &&
 	test_must_fail git show $csha1
 '
@@ -152,7 +152,7 @@ test_expect_success 'local packed unreachable obs that exist in alternate ODB ar
 	rm -f .git/objects/pack/* &&
 	mv pack-* .git/objects/pack/ &&
 	test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
-		egrep "^$csha1 " | sort | uniq | wc -l) &&
+		grep "^$csha1 " | sort | uniq | wc -l) &&
 	echo >.git/objects/info/alternates &&
 	test_must_fail git show $csha1
 '
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v4 26/27] t7700: make references to SHA-1 generic
  2019-11-26  1:17     ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                         ` (24 preceding siblings ...)
  2019-11-26  1:18       ` [PATCH v4 25/27] t7700: replace egrep with grep Denton Liu
@ 2019-11-26  1:18       ` Denton Liu
  2019-11-26  3:15         ` Eric Sunshine
  2019-11-26  1:18       ` [PATCH v4 27/27] t7700: stop losing return codes of git commands Denton Liu
  2019-11-27 19:53       ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
  27 siblings, 1 reply; 169+ messages in thread
From: Denton Liu @ 2019-11-26  1:18 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Make the test more hash-agnostic by renaming variables from "sha1" to
"oid" (case-insensitively). Also, replace the regex, `[0-9a-f]\{40\}`
with `$OID_REGEX`.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7700-repack.sh | 38 +++++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index 2493cc4e9b..d96b1a5949 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -6,31 +6,31 @@ test_description='git repack works correctly'
 
 commit_and_pack () {
 	test_commit "$@" 1>&2 &&
-	SHA1=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) &&
-	echo pack-${SHA1}.pack
+	OID=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) &&
+	echo pack-${OID}.pack
 }
 
 test_no_missing_in_packs () {
 	myidx=$(ls -1 .git/objects/pack/*.idx) &&
 	test_path_is_file "$myidx" &&
 	git verify-pack -v alt_objects/pack/*.idx >orig.raw &&
-	grep "^[0-9a-f]\{40\}" orig.raw | cut -d" " -f1 | sort >orig &&
+	grep "^$OID_REGEX" orig.raw | cut -d" " -f1 | sort >orig &&
 	git verify-pack -v $myidx >dest.raw &&
 	cut -d" " -f1 dest.raw | sort >dest &&
 	comm -23 orig dest >missing &&
 	test_must_be_empty missing
 }
 
-# we expect $packsha1 and $objsha1 to be defined
+# we expect $packoid and $objoid to be defined
 test_has_duplicate_object () {
 	want_duplicate_object="$1"
 	found_duplicate_object=false
 	for p in .git/objects/pack/*.idx
 	do
 		idx=$(basename $p)
-		test "pack-$packsha1.idx" = "$idx" && continue
+		test "pack-$packoid.idx" = "$idx" && continue
 		git verify-pack -v $p >packlist || return $?
-		if grep "^$objsha1" packlist
+		if grep "^$objoid" packlist
 		then
 			found_duplicate_object=true
 			echo "DUPLICATE OBJECT FOUND"
@@ -51,11 +51,11 @@ test_expect_success 'objects in packs marked .keep are not repacked' '
 	git rev-list --objects --all | grep -v file2 |
 		git pack-objects pack &&
 	# The second pack will contain the excluded object
-	packsha1=$(git rev-list --objects --all | grep file2 |
+	packoid=$(git rev-list --objects --all | grep file2 |
 		git pack-objects pack) &&
-	>pack-$packsha1.keep &&
-	objsha1=$(git verify-pack -v pack-$packsha1.idx | head -n 1 |
-		sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") &&
+	>pack-$packoid.keep &&
+	objoid=$(git verify-pack -v pack-$packoid.idx | head -n 1 |
+		sed -e "s/^\($OID_REGEX\).*/\1/") &&
 	mv pack-* .git/objects/pack/ &&
 	git repack -A -d -l &&
 	git prune-packed &&
@@ -63,13 +63,13 @@ test_expect_success 'objects in packs marked .keep are not repacked' '
 '
 
 test_expect_success 'writing bitmaps via command-line can duplicate .keep objects' '
-	# build on $objsha1, $packsha1, and .keep state from previous
+	# build on $objoid, $packoid, and .keep state from previous
 	git repack -Adbl &&
 	test_has_duplicate_object true
 '
 
 test_expect_success 'writing bitmaps via config can duplicate .keep objects' '
-	# build on $objsha1, $packsha1, and .keep state from previous
+	# build on $objoid, $packoid, and .keep state from previous
 	git -c repack.writebitmaps=true repack -Adl &&
 	test_has_duplicate_object true
 '
@@ -78,7 +78,7 @@ test_expect_success 'loose objects in alternate ODB are not repacked' '
 	mkdir alt_objects &&
 	echo $(pwd)/alt_objects >.git/objects/info/alternates &&
 	echo content3 >file3 &&
-	objsha1=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) &&
+	objoid=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) &&
 	git add file3 &&
 	test_tick &&
 	git commit -m commit_file3 &&
@@ -124,7 +124,7 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
 test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
 	rm -f alt_objects/pack/*.keep &&
 	mv .git/objects/pack/* alt_objects/pack/ &&
-	csha1=$(git rev-parse HEAD^{commit}) &&
+	coid=$(git rev-parse HEAD^{commit}) &&
 	git reset --hard HEAD^ &&
 	test_tick &&
 	git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all &&
@@ -135,14 +135,14 @@ test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
 	rm -f .git/objects/pack/* &&
 	mv pack-* .git/objects/pack/ &&
 	test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
-		grep "^$csha1 " | sort | uniq | wc -l) &&
+		grep "^$coid " | sort | uniq | wc -l) &&
 	echo >.git/objects/info/alternates &&
-	test_must_fail git show $csha1
+	test_must_fail git show $coid
 '
 
 test_expect_success 'local packed unreachable obs that exist in alternate ODB are not loosened' '
 	echo $(pwd)/alt_objects >.git/objects/info/alternates &&
-	echo "$csha1" | git pack-objects --non-empty --all --reflog pack &&
+	echo "$coid" | git pack-objects --non-empty --all --reflog pack &&
 	rm -f .git/objects/pack/* &&
 	mv pack-* .git/objects/pack/ &&
 	# The pack-objects call on the next line is equivalent to
@@ -152,9 +152,9 @@ test_expect_success 'local packed unreachable obs that exist in alternate ODB ar
 	rm -f .git/objects/pack/* &&
 	mv pack-* .git/objects/pack/ &&
 	test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
-		grep "^$csha1 " | sort | uniq | wc -l) &&
+		grep "^$coid " | sort | uniq | wc -l) &&
 	echo >.git/objects/info/alternates &&
-	test_must_fail git show $csha1
+	test_must_fail git show $coid
 '
 
 test_expect_success 'objects made unreachable by grafts only are kept' '
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v4 27/27] t7700: stop losing return codes of git commands
  2019-11-26  1:17     ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                         ` (25 preceding siblings ...)
  2019-11-26  1:18       ` [PATCH v4 26/27] t7700: make references to SHA-1 generic Denton Liu
@ 2019-11-26  1:18       ` Denton Liu
  2019-11-27 19:53       ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
  27 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-26  1:18 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

In a pipe, only the return code of the last command is used. Thus, all
other commands will have their return codes masked. Rewrite pipes so
that there are no git commands upstream so that we will know if a
command fails.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7700-repack.sh | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index d96b1a5949..93b20bb7a8 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -48,14 +48,13 @@ test_expect_success 'objects in packs marked .keep are not repacked' '
 	git commit -m initial_commit &&
 	# Create two packs
 	# The first pack will contain all of the objects except one
-	git rev-list --objects --all | grep -v file2 |
-		git pack-objects pack &&
+	git rev-list --objects --all >objs &&
+	grep -v file2 objs | git pack-objects pack &&
 	# The second pack will contain the excluded object
-	packoid=$(git rev-list --objects --all | grep file2 |
-		git pack-objects pack) &&
+	packoid=$(grep file2 objs | git pack-objects pack) &&
 	>pack-$packoid.keep &&
-	objoid=$(git verify-pack -v pack-$packoid.idx | head -n 1 |
-		sed -e "s/^\($OID_REGEX\).*/\1/") &&
+	git verify-pack -v pack-$packoid.idx >packlist &&
+	objoid=$(head -n 1 packlist | sed -e "s/^\($OID_REGEX\).*/\1/") &&
 	mv pack-* .git/objects/pack/ &&
 	git repack -A -d -l &&
 	git prune-packed &&
@@ -134,8 +133,8 @@ test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
 	    --unpack-unreachable </dev/null pack &&
 	rm -f .git/objects/pack/* &&
 	mv pack-* .git/objects/pack/ &&
-	test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
-		grep "^$coid " | sort | uniq | wc -l) &&
+	git verify-pack -v -- .git/objects/pack/*.idx >packlist &&
+	! grep "^$coid " packlist &&
 	echo >.git/objects/info/alternates &&
 	test_must_fail git show $coid
 '
@@ -151,8 +150,8 @@ test_expect_success 'local packed unreachable obs that exist in alternate ODB ar
 	    --unpack-unreachable </dev/null pack &&
 	rm -f .git/objects/pack/* &&
 	mv pack-* .git/objects/pack/ &&
-	test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
-		grep "^$coid " | sort | uniq | wc -l) &&
+	git verify-pack -v -- .git/objects/pack/*.idx >packlist &&
+	! grep "^$coid " &&
 	echo >.git/objects/info/alternates &&
 	test_must_fail git show $coid
 '
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* Re: [PATCH v3 22/22] t7700: stop losing return codes of git commands
  2019-11-26  0:58           ` Eric Sunshine
@ 2019-11-26  1:34             ` Junio C Hamano
  2019-11-26  4:47               ` Denton Liu
  0 siblings, 1 reply; 169+ messages in thread
From: Junio C Hamano @ 2019-11-26  1:34 UTC (permalink / raw)
  To: Eric Sunshine; +Cc: Denton Liu, Git Mailing List, Jeff King

Eric Sunshine <sunshine@sunshineco.com> writes:

> It may not be too much work for you to keep adding more (unrelated)
> changes to a series, but doing so increases the burden on reviewers
> unnecessarily, especially for a long patch series such as this one.
> Generally speaking, each iteration should help the series converge to
> the point at which it can finally land (be merged to "next"). Thus,
> ideally, each iteration should have fewer changes than the previous
> one.

Yup.  It is too easy to paint an ongoing series with a brush that is
broader than necessary and say "this is to clean up", and fall into
a never-ending run of scope expansion, as there always is yet
another thing to clean up.  The focus of the series has been to
ensure that we catch error exit from "git" and that script conforms
to the style guidelines, and does not include hash migration.  

Let's resist the urge to expand the scope.

Thanks.



^ permalink raw reply	[flat|nested] 169+ messages in thread

* Re: [PATCH v4 22/27] t7700: consolidate code into test_no_missing_in_packs()
  2019-11-26  1:18       ` [PATCH v4 22/27] t7700: consolidate code into test_no_missing_in_packs() Denton Liu
@ 2019-11-26  2:35         ` Eric Sunshine
  0 siblings, 0 replies; 169+ messages in thread
From: Eric Sunshine @ 2019-11-26  2:35 UTC (permalink / raw)
  To: Denton Liu; +Cc: Git Mailing List, Junio C Hamano, Jeff King

On Mon, Nov 25, 2019 at 8:21 PM Denton Liu <liu.denton@gmail.com> wrote:
> The code to test that objects were not missing from the packfile was
> duplicated many times. Extract the duplicated code into
> test_no_missing_in_packs() and use that instead.
>
> Refactor the resulting extraction so that if any git commands fail,
> their return codes are not silently lost.
>
> We were using sed to filter lines. Although not incorrect, this is
> exactly what grep is built for. Replace this invocation of sed with grep
> so that we use the correct tool for the job.
>
> The original testing construct was O(n^2): it used a grep in a loop to
> test whether any objects were missing in the packfile. Rewrite this to
> use sort the files then use `comm -23` so that finding missing lines

s/use sort/sort/

> from the original file is done more efficiently.
>
> While we're at it, add a space to `commit_and_pack ()` for style.
>
> Signed-off-by: Denton Liu <liu.denton@gmail.com>

^ permalink raw reply	[flat|nested] 169+ messages in thread

* Re: [PATCH v4 26/27] t7700: make references to SHA-1 generic
  2019-11-26  1:18       ` [PATCH v4 26/27] t7700: make references to SHA-1 generic Denton Liu
@ 2019-11-26  3:15         ` Eric Sunshine
  0 siblings, 0 replies; 169+ messages in thread
From: Eric Sunshine @ 2019-11-26  3:15 UTC (permalink / raw)
  To: Denton Liu; +Cc: Git Mailing List, Junio C Hamano, Jeff King

On Mon, Nov 25, 2019 at 8:22 PM Denton Liu <liu.denton@gmail.com> wrote:
> Make the test more hash-agnostic by renaming variables from "sha1" to
> "oid" (case-insensitively). Also, replace the regex, `[0-9a-f]\{40\}`
> with `$OID_REGEX`.
>
> Signed-off-by: Denton Liu <liu.denton@gmail.com>
> ---
> diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
> @@ -6,31 +6,31 @@ test_description='git repack works correctly'
>  commit_and_pack () {
>         test_commit "$@" 1>&2 &&
> -       SHA1=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) &&
> -       echo pack-${SHA1}.pack
> +       OID=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) &&
> +       echo pack-${OID}.pack
>  }

Meh. OID stands for "object ID". However, in this context, SHA1 is a
computed hash value -- a checksum -- not the ID of an object. So,
calling this an OID is confusing (IMHO). By the way, the uppercase
"SHA1" gives the impression that this value is global to the script,
but it is, in fact, used only in this function, so it would be clearer
to downcase the entire name, implying by convention that it is a local
variable. Taking both observations into consideration, a better name
might be "packid".

> -# we expect $packsha1 and $objsha1 to be defined
> +# we expect $packoid and $objoid to be defined

Likewise. By using "oid" in these names, you're calling these values
"pack object ID" and "object object ID", respectively, which doesn't
make much sense. Perhaps "packid" and simply "oid" would be better
names.

Same comment applies to remaining changes in this patch.

> @@ -124,7 +124,7 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
>  test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
>         rm -f alt_objects/pack/*.keep &&
>         mv .git/objects/pack/* alt_objects/pack/ &&
> -       csha1=$(git rev-parse HEAD^{commit}) &&
> +       coid=$(git rev-parse HEAD^{commit}) &&

This is indeed an object ID, so replacing literal "sha1" with "oid" makes sense.

^ permalink raw reply	[flat|nested] 169+ messages in thread

* Re: [PATCH v3 22/22] t7700: stop losing return codes of git commands
  2019-11-26  1:34             ` Junio C Hamano
@ 2019-11-26  4:47               ` Denton Liu
  0 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-26  4:47 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Eric Sunshine, Git Mailing List, Jeff King

Hi Junio and Eric,

On Tue, Nov 26, 2019 at 10:34:48AM +0900, Junio C Hamano wrote:
> Eric Sunshine <sunshine@sunshineco.com> writes:
> 
> > It may not be too much work for you to keep adding more (unrelated)
> > changes to a series, but doing so increases the burden on reviewers
> > unnecessarily, especially for a long patch series such as this one.
> > Generally speaking, each iteration should help the series converge to
> > the point at which it can finally land (be merged to "next"). Thus,
> > ideally, each iteration should have fewer changes than the previous
> > one.

Sorry for expanding the burden I've been putting on you. I really
appreciate the effort both of you have been putting in reviewing my work
and I'll make sure to not make it any harder than necessary for any
reviewers in the future.

> 
> Yup.  It is too easy to paint an ongoing series with a brush that is
> broader than necessary and say "this is to clean up", and fall into
> a never-ending run of scope expansion, as there always is yet
> another thing to clean up.  The focus of the series has been to
> ensure that we catch error exit from "git" and that script conforms
> to the style guidelines, and does not include hash migration.  
> 
> Let's resist the urge to expand the scope.

I see that Eric's already reviewed the changes from this round (thanks,
Eric) so I don't want his work to go to waste. But I won't change the
scope from this point forward.

Sorry again for the extra burden,

Denton

> 
> Thanks.
> 
> 

^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail
  2019-11-26  1:17     ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                         ` (26 preceding siblings ...)
  2019-11-26  1:18       ` [PATCH v4 27/27] t7700: stop losing return codes of git commands Denton Liu
@ 2019-11-27 19:53       ` Denton Liu
  2019-11-27 19:53         ` [PATCH v5 01/26] lib-bash.sh: move `then` onto its own line Denton Liu
                           ` (25 more replies)
  27 siblings, 26 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

These patches perform some general test cleanup to modernise the style.
They should be relatively uncontroversial. The reason these tests were
identified for cleanup was because they failed under `set -o pipefail`.

I've gotten rid of the RFC part that actually enables `set -o pipefail`
on supported platforms. As Peff pointed out, there are a lot of
opportunities for racy SIGPIPE failures so that part still needs a lot
of work to be ironed out.

Those changes shouldn't hold back the first part of the series, however.
Let's try to get this test cleanup merged in sooner than later so that
any new test cases done by copy-paste will have their changes
represented.

Changes since v4:

* Squash in "squash! t7700: consolidate code into test_no_missing_in_packs()"

* Fix typo in "t7700: consolidate code into test_no_missing_in_packs()"

* Use "oid" and "packid" instead of "objoid" and "packoid" in "t7700:
  make references to SHA-1 generic"

Changes since v3:

* More commit message update

* Clean up "apply-one-time-sed.sh: modernize style" more according to
  Junio's suggestions

* Clean up the t7700 leftover bits

Changes since v2:

* Update commit messages according to Eric's suggestions

* Add "apply-one-time-sed.sh: modernize style"

Changes since v1:

* Removed the `set -o pipefail` changes

* Addressed Junio and Eric's comments on the first part of the series

Denton Liu (26):
  lib-bash.sh: move `then` onto its own line
  apply-one-time-sed.sh: modernize style
  t0014: remove git command upstream of pipe
  t0090: stop losing return codes of git commands
  t3301: stop losing return codes of git commands
  t3600: use test_line_count() where possible
  t3600: stop losing return codes of git commands
  t3600: comment on inducing SIGPIPE in `git rm`
  t4015: stop losing return codes of git commands
  t4015: use test_write_lines()
  t4138: stop losing return codes of git commands
  t5317: stop losing return codes of git commands
  t5317: use ! grep to check for no matching lines
  t5703: simplify one-time-sed generation logic
  t5703: stop losing return codes of git commands
  t7501: remove spaces after redirect operators
  t7501: stop losing return codes of git commands
  t7700: drop redirections to /dev/null
  t7700: remove spaces after redirect operators
  t7700: move keywords onto their own line
  t7700: s/test -f/test_path_is_file/
  t7700: consolidate code into test_no_missing_in_packs()
  t7700: consolidate code into test_has_duplicate_object()
  t7700: replace egrep with grep
  t7700: make references to SHA-1 generic
  t7700: stop losing return codes of git commands

 t/lib-bash.sh                          |   6 +-
 t/lib-httpd/apply-one-time-sed.sh      |   8 +-
 t/t0014-alias.sh                       |   4 +-
 t/t0090-cache-tree.sh                  |   5 +-
 t/t3301-notes.sh                       | 230 ++++++++++++++++++-------
 t/t3600-rm.sh                          |  14 +-
 t/t4015-diff-whitespace.sh             | 123 +++++++------
 t/t4138-apply-ws-expansion.sh          |  16 +-
 t/t5317-pack-objects-filter-objects.sh |  34 ++--
 t/t5703-upload-pack-ref-in-want.sh     |  53 +++---
 t/t7501-commit-basic-functionality.sh  |  83 +++++----
 t/t7700-repack.sh                      | 172 ++++++++----------
 12 files changed, 425 insertions(+), 323 deletions(-)

Range-diff against v4:
 1:  d5e769af39 =  1:  9085cc00af lib-bash.sh: move `then` onto its own line
 2:  31434dfb4b =  2:  86f625c65e apply-one-time-sed.sh: modernize style
 3:  e4443a6358 =  3:  3844e00367 t0014: remove git command upstream of pipe
 4:  712354f90c =  4:  7d33586b21 t0090: stop losing return codes of git commands
 5:  adef902872 =  5:  df6b3393c4 t3301: stop losing return codes of git commands
 6:  a79cfe261a =  6:  d541a8d4d4 t3600: use test_line_count() where possible
 7:  bfbb8bde3a =  7:  a8aeca6795 t3600: stop losing return codes of git commands
 8:  714da9e618 =  8:  e3db06578d t3600: comment on inducing SIGPIPE in `git rm`
 9:  4d5f40f3b0 =  9:  22ea5d736e t4015: stop losing return codes of git commands
10:  68ed9ba7b6 = 10:  a44dd28b4d t4015: use test_write_lines()
11:  c1ce767a98 = 11:  d512319be0 t4138: stop losing return codes of git commands
12:  b5fa2ddb87 = 12:  1e08c2b68b t5317: stop losing return codes of git commands
13:  000126915e = 13:  fa238be28b t5317: use ! grep to check for no matching lines
14:  e18ab06152 = 14:  291caf9bc1 t5703: simplify one-time-sed generation logic
15:  42b63b4735 = 15:  edf7af76ae t5703: stop losing return codes of git commands
16:  e816d6e18d = 16:  5eb7117fbe t7501: remove spaces after redirect operators
17:  6147ec6e8f = 17:  bad732adc8 t7501: stop losing return codes of git commands
18:  7013c3a3c7 = 18:  c50c192429 t7700: drop redirections to /dev/null
19:  f421b35adb = 19:  58ae066d12 t7700: remove spaces after redirect operators
20:  7b8d5767fb = 20:  82bf24d06a t7700: move keywords onto their own line
21:  dafc8da2d2 = 21:  251de77677 t7700: s/test -f/test_path_is_file/
22:  1e8f239080 ! 22:  a99a45cb6f t7700: consolidate code into test_no_missing_in_packs()
    @@ Commit message
         exactly what grep is built for. Replace this invocation of sed with grep
         so that we use the correct tool for the job.
     
    +    Instead of verifying each file of `alt_objects/pack/*.idx` individually
    +    in a for-loop, batch them together into one verification step.
    +
         The original testing construct was O(n^2): it used a grep in a loop to
         test whether any objects were missing in the packfile. Rewrite this to
    -    use sort the files then use `comm -23` so that finding missing lines
    -    from the original file is done more efficiently.
    +    sort the files then use `comm -23` so that finding missing lines from
    +    the original file is done more efficiently.
     
         While we're at it, add a space to `commit_and_pack ()` for style.
     
    @@ t/t7700-repack.sh: test_description='git repack works correctly'
     +test_no_missing_in_packs () {
     +	myidx=$(ls -1 .git/objects/pack/*.idx) &&
     +	test_path_is_file "$myidx" &&
    -+	for p in alt_objects/pack/*.idx
    -+	do
    -+		git verify-pack -v $p >packlist || return $?
    -+		grep "^[0-9a-f]\{40\}" packlist
    -+	done >orig.raw &&
    -+	cut -d" " -f1 orig.raw | sort >orig &&
    ++	git verify-pack -v alt_objects/pack/*.idx >orig.raw &&
    ++	grep "^[0-9a-f]\{40\}" orig.raw | cut -d" " -f1 | sort >orig &&
     +	git verify-pack -v $myidx >dest.raw &&
     +	cut -d" " -f1 dest.raw | sort >dest &&
     +	comm -23 orig dest >missing &&
23:  4b70b92e1d <  -:  ---------- squash! t7700: consolidate code into test_no_missing_in_packs()
24:  b0e58908d9 = 23:  f79240e937 t7700: consolidate code into test_has_duplicate_object()
25:  6bd266035f = 24:  632a62f6e9 t7700: replace egrep with grep
26:  8193fee859 ! 25:  bf70cc5a0d t7700: make references to SHA-1 generic
    @@ Commit message
         t7700: make references to SHA-1 generic
     
         Make the test more hash-agnostic by renaming variables from "sha1" to
    -    "oid" (case-insensitively). Also, replace the regex, `[0-9a-f]\{40\}`
    -    with `$OID_REGEX`.
    +    some variation of "oid" or "packid". Also, replace the regex,
    +    `[0-9a-f]\{40\}` with `$OID_REGEX`.
    +
    +    A better name for "incrpackid" (incremental pack-id) might have been
    +    just "packid". However, later in the test suite, we have other uses of
    +    "packid". Although the scopes of these variables don't conflict, a
    +    future developer may think that commit_and_pack() and
    +    test_has_duplicate_object() are semantically related somehow since they
    +    share the same variable name. Give them distinct names so that it's
    +    clear these uses are unrelated.
     
      ## t/t7700-repack.sh ##
     @@ t/t7700-repack.sh: test_description='git repack works correctly'
    @@ t/t7700-repack.sh: test_description='git repack works correctly'
      	test_commit "$@" 1>&2 &&
     -	SHA1=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) &&
     -	echo pack-${SHA1}.pack
    -+	OID=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) &&
    -+	echo pack-${OID}.pack
    ++	incrpackid=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) &&
    ++	echo pack-${incrpackid}.pack
      }
      
      test_no_missing_in_packs () {
    @@ t/t7700-repack.sh: test_description='git repack works correctly'
      }
      
     -# we expect $packsha1 and $objsha1 to be defined
    -+# we expect $packoid and $objoid to be defined
    ++# we expect $packid and $oid to be defined
      test_has_duplicate_object () {
      	want_duplicate_object="$1"
      	found_duplicate_object=false
    @@ t/t7700-repack.sh: test_description='git repack works correctly'
      	do
      		idx=$(basename $p)
     -		test "pack-$packsha1.idx" = "$idx" && continue
    -+		test "pack-$packoid.idx" = "$idx" && continue
    ++		test "pack-$packid.idx" = "$idx" && continue
      		git verify-pack -v $p >packlist || return $?
     -		if grep "^$objsha1" packlist
    -+		if grep "^$objoid" packlist
    ++		if grep "^$oid" packlist
      		then
      			found_duplicate_object=true
      			echo "DUPLICATE OBJECT FOUND"
    @@ t/t7700-repack.sh: test_expect_success 'objects in packs marked .keep are not re
      		git pack-objects pack &&
      	# The second pack will contain the excluded object
     -	packsha1=$(git rev-list --objects --all | grep file2 |
    -+	packoid=$(git rev-list --objects --all | grep file2 |
    ++	packid=$(git rev-list --objects --all | grep file2 |
      		git pack-objects pack) &&
     -	>pack-$packsha1.keep &&
     -	objsha1=$(git verify-pack -v pack-$packsha1.idx | head -n 1 |
     -		sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") &&
    -+	>pack-$packoid.keep &&
    -+	objoid=$(git verify-pack -v pack-$packoid.idx | head -n 1 |
    ++	>pack-$packid.keep &&
    ++	oid=$(git verify-pack -v pack-$packid.idx | head -n 1 |
     +		sed -e "s/^\($OID_REGEX\).*/\1/") &&
      	mv pack-* .git/objects/pack/ &&
      	git repack -A -d -l &&
    @@ t/t7700-repack.sh: test_expect_success 'objects in packs marked .keep are not re
      
      test_expect_success 'writing bitmaps via command-line can duplicate .keep objects' '
     -	# build on $objsha1, $packsha1, and .keep state from previous
    -+	# build on $objoid, $packoid, and .keep state from previous
    ++	# build on $oid, $packid, and .keep state from previous
      	git repack -Adbl &&
      	test_has_duplicate_object true
      '
      
      test_expect_success 'writing bitmaps via config can duplicate .keep objects' '
     -	# build on $objsha1, $packsha1, and .keep state from previous
    -+	# build on $objoid, $packoid, and .keep state from previous
    ++	# build on $oid, $packid, and .keep state from previous
      	git -c repack.writebitmaps=true repack -Adl &&
      	test_has_duplicate_object true
      '
    @@ t/t7700-repack.sh: test_expect_success 'loose objects in alternate ODB are not r
      	echo $(pwd)/alt_objects >.git/objects/info/alternates &&
      	echo content3 >file3 &&
     -	objsha1=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) &&
    -+	objoid=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) &&
    ++	oid=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) &&
      	git add file3 &&
      	test_tick &&
      	git commit -m commit_file3 &&
27:  456aeaa506 ! 26:  1f6d9a80ad t7700: stop losing return codes of git commands
    @@ t/t7700-repack.sh: test_expect_success 'objects in packs marked .keep are not re
     +	git rev-list --objects --all >objs &&
     +	grep -v file2 objs | git pack-objects pack &&
      	# The second pack will contain the excluded object
    --	packoid=$(git rev-list --objects --all | grep file2 |
    +-	packid=$(git rev-list --objects --all | grep file2 |
     -		git pack-objects pack) &&
    -+	packoid=$(grep file2 objs | git pack-objects pack) &&
    - 	>pack-$packoid.keep &&
    --	objoid=$(git verify-pack -v pack-$packoid.idx | head -n 1 |
    ++	packid=$(grep file2 objs | git pack-objects pack) &&
    + 	>pack-$packid.keep &&
    +-	oid=$(git verify-pack -v pack-$packid.idx | head -n 1 |
     -		sed -e "s/^\($OID_REGEX\).*/\1/") &&
    -+	git verify-pack -v pack-$packoid.idx >packlist &&
    -+	objoid=$(head -n 1 packlist | sed -e "s/^\($OID_REGEX\).*/\1/") &&
    ++	git verify-pack -v pack-$packid.idx >packlist &&
    ++	oid=$(head -n 1 packlist | sed -e "s/^\($OID_REGEX\).*/\1/") &&
      	mv pack-* .git/objects/pack/ &&
      	git repack -A -d -l &&
      	git prune-packed &&
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v5 01/26] lib-bash.sh: move `then` onto its own line
  2019-11-27 19:53       ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
@ 2019-11-27 19:53         ` Denton Liu
  2019-11-27 19:53         ` [PATCH v5 02/26] apply-one-time-sed.sh: modernize style Denton Liu
                           ` (24 subsequent siblings)
  25 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

The code style for tests is to have statements on their own line if
possible. Move the `then` onto its own line so that it conforms with the
test style.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/lib-bash.sh | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/t/lib-bash.sh b/t/lib-bash.sh
index 2be955fafb..b0b6060929 100644
--- a/t/lib-bash.sh
+++ b/t/lib-bash.sh
@@ -2,10 +2,12 @@
 # to run under Bash; primarily intended for tests of the completion
 # script.
 
-if test -n "$BASH" && test -z "$POSIXLY_CORRECT"; then
+if test -n "$BASH" && test -z "$POSIXLY_CORRECT"
+then
 	# we are in full-on bash mode
 	true
-elif type bash >/dev/null 2>&1; then
+elif type bash >/dev/null 2>&1
+then
 	# execute in full-on bash mode
 	unset POSIXLY_CORRECT
 	exec bash "$0" "$@"
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v5 02/26] apply-one-time-sed.sh: modernize style
  2019-11-27 19:53       ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
  2019-11-27 19:53         ` [PATCH v5 01/26] lib-bash.sh: move `then` onto its own line Denton Liu
@ 2019-11-27 19:53         ` Denton Liu
  2019-11-27 19:53         ` [PATCH v5 03/26] t0014: remove git command upstream of pipe Denton Liu
                           ` (23 subsequent siblings)
  25 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Convert `[ ... ]` to use `test` and test for the existence of a regular
file (`-f`) instead of any file (`-e`).

Move the `then`s onto their own lines so that it conforms with the
general test style.

Instead of redirecting input into sed, allow it to open its own input.

Use `cmp -s` instead of `diff` since we only care about whether the two
files are equal and `diff` is overkill for this.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/lib-httpd/apply-one-time-sed.sh | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/t/lib-httpd/apply-one-time-sed.sh b/t/lib-httpd/apply-one-time-sed.sh
index fcef728925..bf7689d020 100644
--- a/t/lib-httpd/apply-one-time-sed.sh
+++ b/t/lib-httpd/apply-one-time-sed.sh
@@ -7,11 +7,13 @@
 #
 # This can be used to simulate the effects of the repository changing in
 # between HTTP request-response pairs.
-if [ -e one-time-sed ]; then
+if test -f one-time-sed
+then
 	"$GIT_EXEC_PATH/git-http-backend" >out
-	sed "$(cat one-time-sed)" <out >out_modified
+	sed "$(cat one-time-sed)" out >out_modified
 
-	if diff out out_modified >/dev/null; then
+	if cmp -s out out_modified
+	then
 		cat out
 	else
 		cat out_modified
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v5 03/26] t0014: remove git command upstream of pipe
  2019-11-27 19:53       ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
  2019-11-27 19:53         ` [PATCH v5 01/26] lib-bash.sh: move `then` onto its own line Denton Liu
  2019-11-27 19:53         ` [PATCH v5 02/26] apply-one-time-sed.sh: modernize style Denton Liu
@ 2019-11-27 19:53         ` Denton Liu
  2019-11-27 19:53         ` [PATCH v5 04/26] t0090: stop losing return codes of git commands Denton Liu
                           ` (22 subsequent siblings)
  25 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Before, the `git frotz` command would fail but its return code was
hidden since it was in the upstream of a pipe. Break the pipeline into
two commands so that the return code is no longer lost. Also, mark
`git frotz` with test_must_fail since it's supposed to fail.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t0014-alias.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/t/t0014-alias.sh b/t/t0014-alias.sh
index 2694c81afd..8d3d9144c0 100755
--- a/t/t0014-alias.sh
+++ b/t/t0014-alias.sh
@@ -38,8 +38,8 @@ test_expect_success 'looping aliases - internal execution' '
 #'
 
 test_expect_success 'run-command formats empty args properly' '
-    GIT_TRACE=1 git frotz a "" b " " c 2>&1 |
-    sed -ne "/run_command:/s/.*trace: run_command: //p" >actual &&
+    test_must_fail env GIT_TRACE=1 git frotz a "" b " " c 2>actual.raw &&
+    sed -ne "/run_command:/s/.*trace: run_command: //p" actual.raw >actual &&
     echo "git-frotz a '\'''\'' b '\'' '\'' c" >expect &&
     test_cmp expect actual
 '
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v5 04/26] t0090: stop losing return codes of git commands
  2019-11-27 19:53       ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                           ` (2 preceding siblings ...)
  2019-11-27 19:53         ` [PATCH v5 03/26] t0014: remove git command upstream of pipe Denton Liu
@ 2019-11-27 19:53         ` Denton Liu
  2019-11-27 19:53         ` [PATCH v5 05/26] t3301: " Denton Liu
                           ` (21 subsequent siblings)
  25 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

In generate_expected_cache_tree_rec(), there are currently two instances
of `git ls-files` in the upstream of a pipe. In the case where the
upstream git command fails, its return code will be lost. Extract the
`git ls-files` into its own call so that if it ever fails, its return
code is not lost.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t0090-cache-tree.sh | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh
index ce9a4a5f32..5a633690bf 100755
--- a/t/t0090-cache-tree.sh
+++ b/t/t0090-cache-tree.sh
@@ -21,9 +21,10 @@ generate_expected_cache_tree_rec () {
 	parent="$2" &&
 	# ls-files might have foo/bar, foo/bar/baz, and foo/bar/quux
 	# We want to count only foo because it's the only direct child
-	subtrees=$(git ls-files|grep /|cut -d / -f 1|uniq) &&
+	git ls-files >files &&
+	subtrees=$(grep / files|cut -d / -f 1|uniq) &&
 	subtree_count=$(echo "$subtrees"|awk -v c=0 '$1 != "" {++c} END {print c}') &&
-	entries=$(git ls-files|wc -l) &&
+	entries=$(wc -l <files) &&
 	printf "SHA $dir (%d entries, %d subtrees)\n" "$entries" "$subtree_count" &&
 	for subtree in $subtrees
 	do
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v5 05/26] t3301: stop losing return codes of git commands
  2019-11-27 19:53       ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                           ` (3 preceding siblings ...)
  2019-11-27 19:53         ` [PATCH v5 04/26] t0090: stop losing return codes of git commands Denton Liu
@ 2019-11-27 19:53         ` " Denton Liu
  2019-11-27 19:53         ` [PATCH v5 06/26] t3600: use test_line_count() where possible Denton Liu
                           ` (20 subsequent siblings)
  25 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Currently, there are two ways where the return codes of git commands are
lost. The first way is when a command is in the upstream of a pipe. In a
pipe, only the return code of the last command is used. Thus, all other
commands will have their return codes masked. Rewrite pipes so that
there are no git commands upstream.

The other way is when a command is in a non-assignment command
substitution. The return code will be lost in favour of the surrounding
command's. Rewrite instances of this so that git commands are either run
on their own or in an assignment-only command substitution.

This patch fixes a real buggy test: in 'copy note with "git notes
copy"', `git notes` was mistyped as `git note`.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t3301-notes.sh | 230 +++++++++++++++++++++++++++++++++--------------
 1 file changed, 163 insertions(+), 67 deletions(-)

diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh
index d66a5f6faa..8f43303007 100755
--- a/t/t3301-notes.sh
+++ b/t/t3301-notes.sh
@@ -54,7 +54,9 @@ test_expect_success 'create notes' '
 	test_path_is_missing .git/NOTES_EDITMSG &&
 	git ls-tree -r refs/notes/commits >actual &&
 	test_line_count = 1 actual &&
-	test "b4" = "$(git notes show)" &&
+	echo b4 >expect &&
+	git notes show >actual &&
+	test_cmp expect actual &&
 	git show HEAD^ &&
 	test_must_fail git notes show HEAD^
 '
@@ -79,14 +81,21 @@ test_expect_success 'edit existing notes' '
 	test_path_is_missing .git/NOTES_EDITMSG &&
 	git ls-tree -r refs/notes/commits >actual &&
 	test_line_count = 1 actual &&
-	test "b3" = "$(git notes show)" &&
+	echo b3 >expect &&
+	git notes show >actual &&
+	test_cmp expect actual &&
 	git show HEAD^ &&
 	test_must_fail git notes show HEAD^
 '
 
 test_expect_success 'show notes from treeish' '
-	test "b3" = "$(git notes --ref commits^{tree} show)" &&
-	test "b4" = "$(git notes --ref commits@{1} show)"
+	echo b3 >expect &&
+	git notes --ref commits^{tree} show >actual &&
+	test_cmp expect actual &&
+
+	echo b4 >expect &&
+	git notes --ref commits@{1} show >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'cannot edit notes from non-ref' '
@@ -99,7 +108,9 @@ test_expect_success 'cannot "git notes add -m" where notes already exists' '
 	test_path_is_missing .git/NOTES_EDITMSG &&
 	git ls-tree -r refs/notes/commits >actual &&
 	test_line_count = 1 actual &&
-	test "b3" = "$(git notes show)" &&
+	echo b3 >expect &&
+	git notes show >actual &&
+	test_cmp expect actual &&
 	git show HEAD^ &&
 	test_must_fail git notes show HEAD^
 '
@@ -109,7 +120,9 @@ test_expect_success 'can overwrite existing note with "git notes add -f -m"' '
 	test_path_is_missing .git/NOTES_EDITMSG &&
 	git ls-tree -r refs/notes/commits >actual &&
 	test_line_count = 1 actual &&
-	test "b1" = "$(git notes show)" &&
+	echo b1 >expect &&
+	git notes show >actual &&
+	test_cmp expect actual &&
 	git show HEAD^ &&
 	test_must_fail git notes show HEAD^
 '
@@ -119,7 +132,9 @@ test_expect_success 'add w/no options on existing note morphs into edit' '
 	test_path_is_missing .git/NOTES_EDITMSG &&
 	git ls-tree -r refs/notes/commits >actual &&
 	test_line_count = 1 actual &&
-	test "b2" = "$(git notes show)" &&
+	echo b2 >expect &&
+	git notes show >actual &&
+	test_cmp expect actual &&
 	git show HEAD^ &&
 	test_must_fail git notes show HEAD^
 '
@@ -129,7 +144,9 @@ test_expect_success 'can overwrite existing note with "git notes add -f"' '
 	test_path_is_missing .git/NOTES_EDITMSG &&
 	git ls-tree -r refs/notes/commits >actual &&
 	test_line_count = 1 actual &&
-	test "b1" = "$(git notes show)" &&
+	echo b1 >expect &&
+	git notes show >actual &&
+	test_cmp expect actual &&
 	git show HEAD^ &&
 	test_must_fail git notes show HEAD^
 '
@@ -146,7 +163,8 @@ test_expect_success 'show notes' '
 		Notes:
 		${indent}b1
 	EOF
-	! (git cat-file commit HEAD | grep b1) &&
+	git cat-file commit HEAD >commits &&
+	! grep b1 commits &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -472,9 +490,11 @@ test_expect_success 'removing with --stdin --ignore-missing' '
 test_expect_success 'list notes with "git notes list"' '
 	commit_2=$(git rev-parse 2nd) &&
 	commit_3=$(git rev-parse 3rd) &&
+	note_2=$(git rev-parse refs/notes/commits:$commit_2) &&
+	note_3=$(git rev-parse refs/notes/commits:$commit_3) &&
 	sort -t" " -k2 >expect <<-EOF &&
-		$(git rev-parse refs/notes/commits:$commit_2) $commit_2
-		$(git rev-parse refs/notes/commits:$commit_3) $commit_3
+		$note_2 $commit_2
+		$note_3 $commit_3
 	EOF
 	git notes list >actual &&
 	test_cmp expect actual
@@ -486,9 +506,7 @@ test_expect_success 'list notes with "git notes"' '
 '
 
 test_expect_success 'list specific note with "git notes list <object>"' '
-	cat >expect <<-EOF &&
-		$(git rev-parse refs/notes/commits:$commit_3)
-	EOF
+	git rev-parse refs/notes/commits:$commit_3 >expect &&
 	git notes list HEAD^^ >actual &&
 	test_cmp expect actual
 '
@@ -512,10 +530,11 @@ test_expect_success 'append to existing note with "git notes append"' '
 
 test_expect_success '"git notes list" does not expand to "git notes list HEAD"' '
 	commit_5=$(git rev-parse 5th) &&
+	note_5=$(git rev-parse refs/notes/commits:$commit_5) &&
 	sort -t" " -k2 >expect_list <<-EOF &&
-		$(git rev-parse refs/notes/commits:$commit_2) $commit_2
-		$(git rev-parse refs/notes/commits:$commit_3) $commit_3
-		$(git rev-parse refs/notes/commits:$commit_5) $commit_5
+		$note_2 $commit_2
+		$note_3 $commit_3
+		$note_5 $commit_5
 	EOF
 	git notes list >actual &&
 	test_cmp expect_list actual
@@ -721,7 +740,8 @@ test_expect_success 'Allow notes on non-commits (trees, blobs, tags)' '
 	git notes show HEAD: >actual &&
 	test_cmp expect actual &&
 	echo "Note on a blob" >expect &&
-	filename=$(git ls-tree --name-only HEAD | head -n1) &&
+	git ls-tree --name-only HEAD >files &&
+	filename=$(head -n1 files) &&
 	git notes add -m "Note on a blob" HEAD:$filename &&
 	git notes show HEAD:$filename >actual &&
 	test_cmp expect actual &&
@@ -745,10 +765,13 @@ test_expect_success 'create note from other note with "git notes add -C"' '
 		Notes:
 		${indent}order test
 	EOF
-	git notes add -C $(git notes list HEAD^) &&
+	note=$(git notes list HEAD^) &&
+	git notes add -C $note &&
 	git log -1 >actual &&
 	test_cmp expect actual &&
-	test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
+	git notes list HEAD^ >expect &&
+	git notes list HEAD >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'create note from non-existing note with "git notes add -C" fails' '
@@ -777,11 +800,12 @@ test_expect_success 'create note from blob with "git notes add -C" reuses blob i
 		Notes:
 		${indent}This is a blob object
 	EOF
-	blob=$(echo "This is a blob object" | git hash-object -w --stdin) &&
-	git notes add -C $blob &&
+	echo "This is a blob object" | git hash-object -w --stdin >blob &&
+	git notes add -C $(cat blob) &&
 	git log -1 >actual &&
 	test_cmp expect actual &&
-	test "$(git notes list HEAD)" = "$blob"
+	git notes list HEAD >actual &&
+	test_cmp blob actual
 '
 
 test_expect_success 'create note from other note with "git notes add -c"' '
@@ -797,7 +821,8 @@ test_expect_success 'create note from other note with "git notes add -c"' '
 		Notes:
 		${indent}yet another note
 	EOF
-	MSG="yet another note" git notes add -c $(git notes list HEAD^^) &&
+	note=$(git notes list HEAD^^) &&
+	MSG="yet another note" git notes add -c $note &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -822,7 +847,8 @@ test_expect_success 'append to note from other note with "git notes append -C"'
 		${indent}
 		${indent}yet another note
 	EOF
-	git notes append -C $(git notes list HEAD^) HEAD^ &&
+	note=$(git notes list HEAD^) &&
+	git notes append -C $note HEAD^ &&
 	git log -1 HEAD^ >actual &&
 	test_cmp expect actual
 '
@@ -839,7 +865,8 @@ test_expect_success 'create note from other note with "git notes append -c"' '
 		Notes:
 		${indent}other note
 	EOF
-	MSG="other note" git notes append -c $(git notes list HEAD^) &&
+	note=$(git notes list HEAD^) &&
+	MSG="other note" git notes append -c $note &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -858,7 +885,8 @@ test_expect_success 'append to note from other note with "git notes append -c"'
 		${indent}
 		${indent}yet another note
 	EOF
-	MSG="yet another note" git notes append -c $(git notes list HEAD) &&
+	note=$(git notes list HEAD) &&
+	MSG="yet another note" git notes append -c $note &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -878,7 +906,9 @@ test_expect_success 'copy note with "git notes copy"' '
 	git notes copy 8th 4th &&
 	git log 3rd..4th >actual &&
 	test_cmp expect actual &&
-	test "$(git note list 4th)" = "$(git note list 8th)"
+	git notes list 4th >expect &&
+	git notes list 8th >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'copy note with "git notes copy" with default' '
@@ -899,14 +929,30 @@ test_expect_success 'copy note with "git notes copy" with default' '
 	git notes copy HEAD^ &&
 	git log -1 >actual &&
 	test_cmp expect actual &&
-	test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
+	git notes list HEAD^ >expect &&
+	git notes list HEAD >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'prevent overwrite with "git notes copy"' '
 	test_must_fail git notes copy HEAD~2 HEAD &&
+	cat >expect <<-EOF &&
+		commit $commit
+		Author: A U Thor <author@example.com>
+		Date:   Thu Apr 7 15:23:13 2005 -0700
+
+		${indent}11th
+
+		Notes:
+		${indent}other note
+		${indent}
+		${indent}yet another note
+	EOF
 	git log -1 >actual &&
 	test_cmp expect actual &&
-	test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
+	git notes list HEAD^ >expect &&
+	git notes list HEAD >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'allow overwrite with "git notes copy -f"' '
@@ -924,7 +970,9 @@ test_expect_success 'allow overwrite with "git notes copy -f"' '
 	git notes copy -f HEAD~3 HEAD &&
 	git log -1 >actual &&
 	test_cmp expect actual &&
-	test "$(git notes list HEAD)" = "$(git notes list HEAD~3)"
+	git notes list HEAD~3 >expect &&
+	git notes list HEAD >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'allow overwrite with "git notes copy -f" with default' '
@@ -944,7 +992,9 @@ test_expect_success 'allow overwrite with "git notes copy -f" with default' '
 	git notes copy -f HEAD~2 &&
 	git log -1 >actual &&
 	test_cmp expect actual &&
-	test "$(git notes list HEAD)" = "$(git notes list HEAD~2)"
+	git notes list HEAD~2 >expect &&
+	git notes list HEAD >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'cannot copy note from object without notes' '
@@ -979,13 +1029,21 @@ test_expect_success 'git notes copy --stdin' '
 		${indent}
 		${indent}yet another note
 	EOF
-	(echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^) &&
-	echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
-	git notes copy --stdin &&
+	from=$(git rev-parse HEAD~3) &&
+	to=$(git rev-parse HEAD^) &&
+	echo "$from" "$to" >copy &&
+	from=$(git rev-parse HEAD~2) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >>copy &&
+	git notes copy --stdin <copy &&
 	git log -2 >actual &&
 	test_cmp expect actual &&
-	test "$(git notes list HEAD)" = "$(git notes list HEAD~2)" &&
-	test "$(git notes list HEAD^)" = "$(git notes list HEAD~3)"
+	git notes list HEAD~2 >expect &&
+	git notes list HEAD >actual &&
+	test_cmp expect actual &&
+	git notes list HEAD~3 >expect &&
+	git notes list HEAD^ >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'git notes copy --for-rewrite (unconfigured)' '
@@ -1006,9 +1064,13 @@ test_expect_success 'git notes copy --for-rewrite (unconfigured)' '
 
 		${indent}14th
 	EOF
-	(echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^) &&
-	echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
-	git notes copy --for-rewrite=foo &&
+	from=$(git rev-parse HEAD~3) &&
+	to=$(git rev-parse HEAD^) &&
+	echo "$from" "$to" >copy &&
+	from=$(git rev-parse HEAD~2) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >>copy &&
+	git notes copy --for-rewrite=foo <copy &&
 	git log -2 >actual &&
 	test_cmp expect actual
 '
@@ -1041,17 +1103,23 @@ test_expect_success 'git notes copy --for-rewrite (enabled)' '
 	EOF
 	test_config notes.rewriteMode overwrite &&
 	test_config notes.rewriteRef "refs/notes/*" &&
-	(echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^) &&
-	echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
-	git notes copy --for-rewrite=foo &&
+	from=$(git rev-parse HEAD~3) &&
+	to=$(git rev-parse HEAD^) &&
+	echo "$from" "$to" >copy &&
+	from=$(git rev-parse HEAD~2) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >>copy &&
+	git notes copy --for-rewrite=foo <copy &&
 	git log -2 >actual &&
 	test_cmp expect actual
 '
 
 test_expect_success 'git notes copy --for-rewrite (disabled)' '
 	test_config notes.rewrite.bar false &&
-	echo $(git rev-parse HEAD~3) $(git rev-parse HEAD) |
-	git notes copy --for-rewrite=bar &&
+	from=$(git rev-parse HEAD~3) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
+	git notes copy --for-rewrite=bar <copy &&
 	git log -2 >actual &&
 	test_cmp expect actual
 '
@@ -1071,8 +1139,10 @@ test_expect_success 'git notes copy --for-rewrite (overwrite)' '
 	git notes add -f -m"a fresh note" HEAD^ &&
 	test_config notes.rewriteMode overwrite &&
 	test_config notes.rewriteRef "refs/notes/*" &&
-	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
-	git notes copy --for-rewrite=foo &&
+	from=$(git rev-parse HEAD^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
+	git notes copy --for-rewrite=foo <copy &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -1080,8 +1150,10 @@ test_expect_success 'git notes copy --for-rewrite (overwrite)' '
 test_expect_success 'git notes copy --for-rewrite (ignore)' '
 	test_config notes.rewriteMode ignore &&
 	test_config notes.rewriteRef "refs/notes/*" &&
-	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
-	git notes copy --for-rewrite=foo &&
+	from=$(git rev-parse HEAD^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
+	git notes copy --for-rewrite=foo <copy &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -1103,8 +1175,10 @@ test_expect_success 'git notes copy --for-rewrite (append)' '
 	git notes add -f -m"another fresh note" HEAD^ &&
 	test_config notes.rewriteMode concatenate &&
 	test_config notes.rewriteRef "refs/notes/*" &&
-	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
-	git notes copy --for-rewrite=foo &&
+	from=$(git rev-parse HEAD^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
+	git notes copy --for-rewrite=foo <copy &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -1131,9 +1205,13 @@ test_expect_success 'git notes copy --for-rewrite (append two to one)' '
 	git notes add -f -m"append 2" HEAD^^ &&
 	test_config notes.rewriteMode concatenate &&
 	test_config notes.rewriteRef "refs/notes/*" &&
-	(echo $(git rev-parse HEAD^) $(git rev-parse HEAD) &&
-	echo $(git rev-parse HEAD^^) $(git rev-parse HEAD)) |
-	git notes copy --for-rewrite=foo &&
+	from=$(git rev-parse HEAD^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
+	from=$(git rev-parse HEAD^^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >>copy &&
+	git notes copy --for-rewrite=foo <copy &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -1142,8 +1220,10 @@ test_expect_success 'git notes copy --for-rewrite (append empty)' '
 	git notes remove HEAD^ &&
 	test_config notes.rewriteMode concatenate &&
 	test_config notes.rewriteRef "refs/notes/*" &&
-	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
-	git notes copy --for-rewrite=foo &&
+	from=$(git rev-parse HEAD^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
+	git notes copy --for-rewrite=foo <copy &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -1163,8 +1243,10 @@ test_expect_success 'GIT_NOTES_REWRITE_MODE works' '
 	test_config notes.rewriteMode concatenate &&
 	test_config notes.rewriteRef "refs/notes/*" &&
 	git notes add -f -m"replacement note 1" HEAD^ &&
-	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
-	GIT_NOTES_REWRITE_MODE=overwrite git notes copy --for-rewrite=foo &&
+	from=$(git rev-parse HEAD^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
+	GIT_NOTES_REWRITE_MODE=overwrite git notes copy --for-rewrite=foo <copy &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -1184,9 +1266,11 @@ test_expect_success 'GIT_NOTES_REWRITE_REF works' '
 	git notes add -f -m"replacement note 2" HEAD^ &&
 	test_config notes.rewriteMode overwrite &&
 	test_unconfig notes.rewriteRef &&
-	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
+	from=$(git rev-parse HEAD^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
 	GIT_NOTES_REWRITE_REF=refs/notes/commits:refs/notes/other \
-		git notes copy --for-rewrite=foo &&
+		git notes copy --for-rewrite=foo <copy &&
 	git log -1 >actual &&
 	test_cmp expect actual
 '
@@ -1195,9 +1279,11 @@ test_expect_success 'GIT_NOTES_REWRITE_REF overrides config' '
 	git notes add -f -m"replacement note 3" HEAD^ &&
 	test_config notes.rewriteMode overwrite &&
 	test_config notes.rewriteRef refs/notes/other &&
-	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
+	from=$(git rev-parse HEAD^) &&
+	to=$(git rev-parse HEAD) &&
+	echo "$from" "$to" >copy &&
 	GIT_NOTES_REWRITE_REF=refs/notes/commits \
-		git notes copy --for-rewrite=foo &&
+		git notes copy --for-rewrite=foo <copy &&
 	git log -1 >actual &&
 	grep "replacement note 3" actual
 '
@@ -1212,26 +1298,36 @@ test_expect_success 'git notes copy diagnoses too many or too few parameters' '
 test_expect_success 'git notes get-ref expands refs/heads/master to refs/notes/refs/heads/master' '
 	test_unconfig core.notesRef &&
 	sane_unset GIT_NOTES_REF &&
-	test "$(git notes --ref=refs/heads/master get-ref)" = "refs/notes/refs/heads/master"
+	echo refs/notes/refs/heads/master >expect &&
+	git notes --ref=refs/heads/master get-ref >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'git notes get-ref (no overrides)' '
 	test_unconfig core.notesRef &&
 	sane_unset GIT_NOTES_REF &&
-	test "$(git notes get-ref)" = "refs/notes/commits"
+	echo refs/notes/commits >expect &&
+	git notes get-ref >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'git notes get-ref (core.notesRef)' '
 	test_config core.notesRef refs/notes/foo &&
-	test "$(git notes get-ref)" = "refs/notes/foo"
+	echo refs/notes/foo >expect &&
+	git notes get-ref >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'git notes get-ref (GIT_NOTES_REF)' '
-	test "$(GIT_NOTES_REF=refs/notes/bar git notes get-ref)" = "refs/notes/bar"
+	echo refs/notes/bar >expect &&
+	GIT_NOTES_REF=refs/notes/bar git notes get-ref >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'git notes get-ref (--ref)' '
-	test "$(GIT_NOTES_REF=refs/notes/bar git notes --ref=baz get-ref)" = "refs/notes/baz"
+	echo refs/notes/baz >expect &&
+	GIT_NOTES_REF=refs/notes/bar git notes --ref=baz get-ref >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'setup testing of empty notes' '
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v5 06/26] t3600: use test_line_count() where possible
  2019-11-27 19:53       ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                           ` (4 preceding siblings ...)
  2019-11-27 19:53         ` [PATCH v5 05/26] t3301: " Denton Liu
@ 2019-11-27 19:53         ` Denton Liu
  2019-11-27 19:53         ` [PATCH v5 07/26] t3600: stop losing return codes of git commands Denton Liu
                           ` (19 subsequent siblings)
  25 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Since we have a helper function that can test the number of lines in a
file that gives better debugging information on failure, use
test_line_count() to test the number of lines.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t3600-rm.sh | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh
index 8c8cca5bfb..f6e659b7e9 100755
--- a/t/t3600-rm.sh
+++ b/t/t3600-rm.sh
@@ -113,9 +113,10 @@ test_expect_success '"rm" command printed' '
 	echo frotz >test-file &&
 	git add test-file &&
 	git commit -m "add file for rm test" &&
-	git rm test-file >rm-output &&
-	test $(grep "^rm " rm-output | wc -l) = 1 &&
-	rm -f test-file rm-output &&
+	git rm test-file >rm-output.raw &&
+	grep "^rm " rm-output.raw >rm-output &&
+	test_line_count = 1 rm-output &&
+	rm -f test-file rm-output.raw rm-output &&
 	git commit -m "remove file from rm test"
 '
 
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v5 07/26] t3600: stop losing return codes of git commands
  2019-11-27 19:53       ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                           ` (5 preceding siblings ...)
  2019-11-27 19:53         ` [PATCH v5 06/26] t3600: use test_line_count() where possible Denton Liu
@ 2019-11-27 19:53         ` Denton Liu
  2019-11-27 19:53         ` [PATCH v5 08/26] t3600: comment on inducing SIGPIPE in `git rm` Denton Liu
                           ` (18 subsequent siblings)
  25 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

When a command is in a non-assignment command substitution, the return
code will be lost in favour of the surrounding command's. As a result,
if a git command fails, we won't know about it. Rewrite instances of
this so that git commands are either run in an assignment-only command
substitution so that their return codes aren't lost.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t3600-rm.sh | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh
index f6e659b7e9..0c3bf10edd 100755
--- a/t/t3600-rm.sh
+++ b/t/t3600-rm.sh
@@ -304,7 +304,8 @@ EOF
 
 test_expect_success 'rm removes empty submodules from work tree' '
 	mkdir submod &&
-	git update-index --add --cacheinfo 160000 $(git rev-parse HEAD) submod &&
+	hash=$(git rev-parse HEAD) &&
+	git update-index --add --cacheinfo 160000 "$hash" submod &&
 	git config -f .gitmodules submodule.sub.url ./. &&
 	git config -f .gitmodules submodule.sub.path submod &&
 	git submodule init &&
@@ -623,7 +624,8 @@ test_expect_success 'setup subsubmodule' '
 	git submodule update &&
 	(
 		cd submod &&
-		git update-index --add --cacheinfo 160000 $(git rev-parse HEAD) subsubmod &&
+		hash=$(git rev-parse HEAD) &&
+		git update-index --add --cacheinfo 160000 "$hash" subsubmod &&
 		git config -f .gitmodules submodule.sub.url ../. &&
 		git config -f .gitmodules submodule.sub.path subsubmod &&
 		git submodule init &&
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v5 08/26] t3600: comment on inducing SIGPIPE in `git rm`
  2019-11-27 19:53       ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                           ` (6 preceding siblings ...)
  2019-11-27 19:53         ` [PATCH v5 07/26] t3600: stop losing return codes of git commands Denton Liu
@ 2019-11-27 19:53         ` Denton Liu
  2019-11-27 19:53         ` [PATCH v5 09/26] t4015: stop losing return codes of git commands Denton Liu
                           ` (17 subsequent siblings)
  25 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Add a comment about intentionally inducing SIGPIPE since this is unusual
and future developers should be aware. Also, even though we are trying
to refactor git commands out of the upstream of pipes, we cannot do it
here since we rely on it being upstream to induce SIGPIPE. Comment on
that as well so that future developers do not try to change it.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t3600-rm.sh | 1 +
 1 file changed, 1 insertion(+)

diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh
index 0c3bf10edd..0ea858d652 100755
--- a/t/t3600-rm.sh
+++ b/t/t3600-rm.sh
@@ -251,6 +251,7 @@ test_expect_success 'choking "git rm" should not let it die with cruft' '
 		echo "100644 $hash 0	some-file-$i"
 		i=$(( $i + 1 ))
 	done | git update-index --index-info &&
+	# git command is intentionally placed upstream of pipe to induce SIGPIPE
 	git rm -n "some-file-*" | : &&
 	test_path_is_missing .git/index.lock
 '
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v5 09/26] t4015: stop losing return codes of git commands
  2019-11-27 19:53       ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                           ` (7 preceding siblings ...)
  2019-11-27 19:53         ` [PATCH v5 08/26] t3600: comment on inducing SIGPIPE in `git rm` Denton Liu
@ 2019-11-27 19:53         ` Denton Liu
  2019-11-27 19:53         ` [PATCH v5 10/26] t4015: use test_write_lines() Denton Liu
                           ` (16 subsequent siblings)
  25 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Currently, there are two ways where the return codes of git commands are
lost. The first way is when a command is in the upstream of a pipe. In a
pipe, only the return code of the last command is used. Thus, all other
commands will have their return codes masked. Rewrite pipes so that
there are no git commands upstream.

The other way is when a command is in a non-assignment command
substitution. The return code will be lost in favour of the surrounding
command's. Rewrite instances of this so that git commands are either run
on their own or in an assignment-only command substitution.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t4015-diff-whitespace.sh | 119 ++++++++++++++++++++++---------------
 1 file changed, 72 insertions(+), 47 deletions(-)

diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh
index eadaf57262..7fb83c8eff 100755
--- a/t/t4015-diff-whitespace.sh
+++ b/t/t4015-diff-whitespace.sh
@@ -16,7 +16,8 @@ test_expect_success "Ray Lehtiniemi's example" '
 	} while (0);
 	EOF
 	git update-index --add x &&
-	before=$(git rev-parse --short $(git hash-object x)) &&
+	old_hash_x=$(git hash-object x) &&
+	before=$(git rev-parse --short "$old_hash_x") &&
 
 	cat <<-\EOF >x &&
 	do
@@ -25,7 +26,8 @@ test_expect_success "Ray Lehtiniemi's example" '
 	}
 	while (0);
 	EOF
-	after=$(git rev-parse --short $(git hash-object x)) &&
+	new_hash_x=$(git hash-object x) &&
+	after=$(git rev-parse --short "$new_hash_x") &&
 
 	cat <<-EOF >expect &&
 	diff --git a/x b/x
@@ -63,7 +65,8 @@ test_expect_success 'another test, without options' '
 	EOF
 
 	git update-index x &&
-	before=$(git rev-parse --short $(git hash-object x)) &&
+	old_hash_x=$(git hash-object x) &&
+	before=$(git rev-parse --short "$old_hash_x") &&
 
 	tr "_" " " <<-\EOF >x &&
 	_	whitespace at beginning
@@ -73,7 +76,8 @@ test_expect_success 'another test, without options' '
 	unchanged line
 	CR at end
 	EOF
-	after=$(git rev-parse --short $(git hash-object x)) &&
+	new_hash_x=$(git hash-object x) &&
+	after=$(git rev-parse --short "$new_hash_x") &&
 
 	tr "Q_" "\015 " <<-EOF >expect &&
 	diff --git a/x b/x
@@ -526,13 +530,15 @@ test_expect_success 'ignore-blank-lines: mix changes and blank lines' '
 test_expect_success 'check mixed spaces and tabs in indent' '
 	# This is indented with SP HT SP.
 	echo " 	 foo();" >x &&
-	git diff --check | grep "space before tab in indent"
+	test_must_fail git diff --check >check &&
+	grep "space before tab in indent" check
 '
 
 test_expect_success 'check mixed tabs and spaces in indent' '
 	# This is indented with HT SP HT.
 	echo "	 	foo();" >x &&
-	git diff --check | grep "space before tab in indent"
+	test_must_fail git diff --check >check &&
+	grep "space before tab in indent" check
 '
 
 test_expect_success 'check with no whitespace errors' '
@@ -753,20 +759,23 @@ test_expect_success 'check tab-in-indent excluded from wildcard whitespace attri
 test_expect_success 'line numbers in --check output are correct' '
 	echo "" >x &&
 	echo "foo(); " >>x &&
-	git diff --check | grep "x:2:"
+	test_must_fail git diff --check >check &&
+	grep "x:2:" check
 '
 
 test_expect_success 'checkdiff detects new trailing blank lines (1)' '
 	echo "foo();" >x &&
 	echo "" >>x &&
-	git diff --check | grep "new blank line"
+	test_must_fail git diff --check >check &&
+	grep "new blank line" check
 '
 
 test_expect_success 'checkdiff detects new trailing blank lines (2)' '
 	{ echo a; echo b; echo; echo; } >x &&
 	git add x &&
 	{ echo a; echo; echo; echo; echo; } >x &&
-	git diff --check | grep "new blank line"
+	test_must_fail git diff --check >check &&
+	grep "new blank line" check
 '
 
 test_expect_success 'checkdiff allows new blank lines' '
@@ -794,14 +803,16 @@ test_expect_success 'whitespace-only changes reported across renames' '
 	git reset --hard &&
 	for i in 1 2 3 4 5 6 7 8 9; do echo "$i$i$i$i$i$i"; done >x &&
 	git add x &&
-	before=$(git rev-parse --short $(git hash-object x)) &&
+	hash_x=$(git hash-object x) &&
+	before=$(git rev-parse --short "$hash_x") &&
 	git commit -m "base" &&
 	sed -e "5s/^/ /" x >z &&
 	git rm x &&
 	git add z &&
-	after=$(git rev-parse --short $(git hash-object z)) &&
-	git diff -w -M --cached |
-	sed -e "/^similarity index /s/[0-9][0-9]*/NUM/" >actual &&
+	hash_z=$(git hash-object z) &&
+	after=$(git rev-parse --short "$hash_z") &&
+	git diff -w -M --cached >actual.raw &&
+	sed -e "/^similarity index /s/[0-9][0-9]*/NUM/" actual.raw >actual &&
 	cat <<-EOF >expect &&
 	diff --git a/x b/z
 	similarity index NUM%
@@ -840,7 +851,8 @@ test_expect_success 'combined diff with autocrlf conversion' '
 	git config core.autocrlf true &&
 	test_must_fail git merge master &&
 
-	git diff | sed -e "1,/^@@@/d" >actual &&
+	git diff >actual.raw &&
+	sed -e "1,/^@@@/d" actual.raw >actual &&
 	! grep "^-" actual
 
 '
@@ -864,11 +876,14 @@ test_expect_success 'diff that introduces a line with only tabs' '
 	git config core.whitespace blank-at-eol &&
 	git reset --hard &&
 	echo "test" >x &&
-	before=$(git rev-parse --short $(git hash-object x)) &&
+	old_hash_x=$(git hash-object x) &&
+	before=$(git rev-parse --short "$old_hash_x") &&
 	git commit -m "initial" x &&
 	echo "{NTN}" | tr "NT" "\n\t" >>x &&
-	after=$(git rev-parse --short $(git hash-object x)) &&
-	git diff --color | test_decode_color >current &&
+	new_hash_x=$(git hash-object x) &&
+	after=$(git rev-parse --short "$new_hash_x") &&
+	git diff --color >current.raw &&
+	test_decode_color <current.raw >current &&
 
 	cat >expected <<-EOF &&
 	<BOLD>diff --git a/x b/x<RESET>
@@ -891,17 +906,19 @@ test_expect_success 'diff that introduces and removes ws breakages' '
 		echo "0. blank-at-eol " &&
 		echo "1. blank-at-eol "
 	} >x &&
-	before=$(git rev-parse --short $(git hash-object x)) &&
+	old_hash_x=$(git hash-object x) &&
+	before=$(git rev-parse --short "$old_hash_x") &&
 	git commit -a --allow-empty -m preimage &&
 	{
 		echo "0. blank-at-eol " &&
 		echo "1. still-blank-at-eol " &&
 		echo "2. and a new line "
 	} >x &&
-	after=$(git rev-parse --short $(git hash-object x)) &&
+	new_hash_x=$(git hash-object x) &&
+	after=$(git rev-parse --short "$new_hash_x") &&
 
-	git diff --color |
-	test_decode_color >current &&
+	git diff --color >current.raw &&
+	test_decode_color <current.raw >current &&
 
 	cat >expected <<-EOF &&
 	<BOLD>diff --git a/x b/x<RESET>
@@ -925,14 +942,16 @@ test_expect_success 'ws-error-highlight test setup' '
 		echo "0. blank-at-eol " &&
 		echo "1. blank-at-eol "
 	} >x &&
-	before=$(git rev-parse --short $(git hash-object x)) &&
+	old_hash_x=$(git hash-object x) &&
+	before=$(git rev-parse --short "$old_hash_x") &&
 	git commit -a --allow-empty -m preimage &&
 	{
 		echo "0. blank-at-eol " &&
 		echo "1. still-blank-at-eol " &&
 		echo "2. and a new line "
 	} >x &&
-	after=$(git rev-parse --short $(git hash-object x)) &&
+	new_hash_x=$(git hash-object x) &&
+	after=$(git rev-parse --short "$new_hash_x") &&
 
 	cat >expect.default-old <<-EOF &&
 	<BOLD>diff --git a/x b/x<RESET>
@@ -974,32 +993,32 @@ test_expect_success 'ws-error-highlight test setup' '
 
 test_expect_success 'test --ws-error-highlight option' '
 
-	git diff --color --ws-error-highlight=default,old |
-	test_decode_color >current &&
+	git diff --color --ws-error-highlight=default,old >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.default-old current &&
 
-	git diff --color --ws-error-highlight=all |
-	test_decode_color >current &&
+	git diff --color --ws-error-highlight=all >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.all current &&
 
-	git diff --color --ws-error-highlight=none |
-	test_decode_color >current &&
+	git diff --color --ws-error-highlight=none >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.none current
 
 '
 
 test_expect_success 'test diff.wsErrorHighlight config' '
 
-	git -c diff.wsErrorHighlight=default,old diff --color |
-	test_decode_color >current &&
+	git -c diff.wsErrorHighlight=default,old diff --color >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.default-old current &&
 
-	git -c diff.wsErrorHighlight=all diff --color |
-	test_decode_color >current &&
+	git -c diff.wsErrorHighlight=all diff --color >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.all current &&
 
-	git -c diff.wsErrorHighlight=none diff --color |
-	test_decode_color >current &&
+	git -c diff.wsErrorHighlight=none diff --color >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.none current
 
 '
@@ -1007,18 +1026,18 @@ test_expect_success 'test diff.wsErrorHighlight config' '
 test_expect_success 'option overrides diff.wsErrorHighlight' '
 
 	git -c diff.wsErrorHighlight=none \
-		diff --color --ws-error-highlight=default,old |
-	test_decode_color >current &&
+		diff --color --ws-error-highlight=default,old >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.default-old current &&
 
 	git -c diff.wsErrorHighlight=default \
-		diff --color --ws-error-highlight=all |
-	test_decode_color >current &&
+		diff --color --ws-error-highlight=all >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.all current &&
 
 	git -c diff.wsErrorHighlight=all \
-		diff --color --ws-error-highlight=none |
-	test_decode_color >current &&
+		diff --color --ws-error-highlight=none >current.raw &&
+	test_decode_color <current.raw >current &&
 	test_cmp expect.none current
 
 '
@@ -1038,7 +1057,8 @@ test_expect_success 'detect moved code, complete file' '
 	git mv test.c main.c &&
 	test_config color.diff.oldMoved "normal red" &&
 	test_config color.diff.newMoved "normal green" &&
-	git diff HEAD --color-moved=zebra --color --no-renames | test_decode_color >actual &&
+	git diff HEAD --color-moved=zebra --color --no-renames >actual.raw &&
+	test_decode_color <actual.raw >actual &&
 	cat >expected <<-EOF &&
 	<BOLD>diff --git a/main.c b/main.c<RESET>
 	<BOLD>new file mode 100644<RESET>
@@ -1141,9 +1161,12 @@ test_expect_success 'detect malicious moved code, inside file' '
 			bar();
 		}
 	EOF
-	after_main=$(git rev-parse --short $(git hash-object main.c)) &&
-	after_test=$(git rev-parse --short $(git hash-object test.c)) &&
-	git diff HEAD --no-renames --color-moved=zebra --color | test_decode_color >actual &&
+	hash_main=$(git hash-object main.c) &&
+	after_main=$(git rev-parse --short "$hash_main") &&
+	hash_test=$(git hash-object test.c) &&
+	after_test=$(git rev-parse --short "$hash_test") &&
+	git diff HEAD --no-renames --color-moved=zebra --color >actual.raw &&
+	test_decode_color <actual.raw >actual &&
 	cat <<-EOF >expected &&
 	<BOLD>diff --git a/main.c b/main.c<RESET>
 	<BOLD>index $before_main..$after_main 100644<RESET>
@@ -1192,7 +1215,8 @@ test_expect_success 'plain moved code, inside file' '
 	test_config color.diff.oldMovedAlternative "blue" &&
 	test_config color.diff.newMovedAlternative "yellow" &&
 	# needs previous test as setup
-	git diff HEAD --no-renames --color-moved=plain --color | test_decode_color >actual &&
+	git diff HEAD --no-renames --color-moved=plain --color >actual.raw &&
+	test_decode_color <actual.raw >actual &&
 	cat <<-EOF >expected &&
 	<BOLD>diff --git a/main.c b/main.c<RESET>
 	<BOLD>index $before_main..$after_main 100644<RESET>
@@ -1771,7 +1795,8 @@ test_expect_success 'move detection with submodules' '
 	! grep BRED decoded_actual &&
 
 	# nor did we mess with it another way
-	git diff --submodule=diff --color | test_decode_color >expect &&
+	git diff --submodule=diff --color >expect.raw &&
+	test_decode_color <expect.raw >expect &&
 	test_cmp expect decoded_actual &&
 	rm -rf bananas &&
 	git submodule deinit bananas
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v5 10/26] t4015: use test_write_lines()
  2019-11-27 19:53       ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                           ` (8 preceding siblings ...)
  2019-11-27 19:53         ` [PATCH v5 09/26] t4015: stop losing return codes of git commands Denton Liu
@ 2019-11-27 19:53         ` Denton Liu
  2019-11-27 19:53         ` [PATCH v5 11/26] t4138: stop losing return codes of git commands Denton Liu
                           ` (15 subsequent siblings)
  25 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Instead of rolling our own method to write out some lines into a file,
use the existing test_write_lines().

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t4015-diff-whitespace.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh
index 7fb83c8eff..4c540b1d70 100755
--- a/t/t4015-diff-whitespace.sh
+++ b/t/t4015-diff-whitespace.sh
@@ -771,9 +771,9 @@ test_expect_success 'checkdiff detects new trailing blank lines (1)' '
 '
 
 test_expect_success 'checkdiff detects new trailing blank lines (2)' '
-	{ echo a; echo b; echo; echo; } >x &&
+	test_write_lines a b "" "" >x &&
 	git add x &&
-	{ echo a; echo; echo; echo; echo; } >x &&
+	test_write_lines a "" "" "" "" >x &&
 	test_must_fail git diff --check >check &&
 	grep "new blank line" check
 '
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v5 11/26] t4138: stop losing return codes of git commands
  2019-11-27 19:53       ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                           ` (9 preceding siblings ...)
  2019-11-27 19:53         ` [PATCH v5 10/26] t4015: use test_write_lines() Denton Liu
@ 2019-11-27 19:53         ` Denton Liu
  2019-11-27 19:53         ` [PATCH v5 12/26] t5317: " Denton Liu
                           ` (14 subsequent siblings)
  25 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

In a pipe, only the return code of the last command is used. Thus, all
other commands will have their return codes masked. Rewrite pipes so
that there are no git commands upstream so that we will know if a
command fails.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t4138-apply-ws-expansion.sh | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/t/t4138-apply-ws-expansion.sh b/t/t4138-apply-ws-expansion.sh
index 3b636a63a3..b19faeb67a 100755
--- a/t/t4138-apply-ws-expansion.sh
+++ b/t/t4138-apply-ws-expansion.sh
@@ -17,8 +17,8 @@ test_expect_success setup '
 	printf "\t%s\n" 1 2 3 >after &&
 	printf "%64s\n" a b c >>after &&
 	printf "\t%s\n" 4 5 6 >>after &&
-	git diff --no-index before after |
-		sed -e "s/before/test-1/" -e "s/after/test-1/" >patch1.patch &&
+	test_expect_code 1 git diff --no-index before after >patch1.patch.raw &&
+	sed -e "s/before/test-1/" -e "s/after/test-1/" patch1.patch.raw >patch1.patch &&
 	printf "%64s\n" 1 2 3 4 5 6 >test-1 &&
 	printf "%64s\n" 1 2 3 a b c 4 5 6 >expect-1 &&
 
@@ -33,8 +33,8 @@ test_expect_success setup '
 		x=$(( $x + 1 ))
 	done &&
 	printf "\t%s\n" d e f >>after &&
-	git diff --no-index before after |
-		sed -e "s/before/test-2/" -e "s/after/test-2/" >patch2.patch &&
+	test_expect_code 1 git diff --no-index before after >patch2.patch.raw &&
+	sed -e "s/before/test-2/" -e "s/after/test-2/" patch2.patch.raw >patch2.patch &&
 	printf "%64s\n" a b c d e f >test-2 &&
 	printf "%64s\n" a b c >expect-2 &&
 	x=1 &&
@@ -56,8 +56,8 @@ test_expect_success setup '
 		x=$(( $x + 1 ))
 	done &&
 	printf "\t%s\n" d e f >>after &&
-	git diff --no-index before after |
-	sed -e "s/before/test-3/" -e "s/after/test-3/" >patch3.patch &&
+	test_expect_code 1 git diff --no-index before after >patch3.patch.raw &&
+	sed -e "s/before/test-3/" -e "s/after/test-3/" patch3.patch.raw >patch3.patch &&
 	printf "%64s\n" a b c d e f >test-3 &&
 	printf "%64s\n" a b c >expect-3 &&
 	x=0 &&
@@ -84,8 +84,8 @@ test_expect_success setup '
 		printf "\t%02d\n" $x >>after
 		x=$(( $x + 1 ))
 	done &&
-	git diff --no-index before after |
-	sed -e "s/before/test-4/" -e "s/after/test-4/" >patch4.patch &&
+	test_expect_code 1 git diff --no-index before after >patch4.patch.raw &&
+	sed -e "s/before/test-4/" -e "s/after/test-4/" patch4.patch.raw >patch4.patch &&
 	>test-4 &&
 	x=0 &&
 	while test $x -lt 50
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v5 12/26] t5317: stop losing return codes of git commands
  2019-11-27 19:53       ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                           ` (10 preceding siblings ...)
  2019-11-27 19:53         ` [PATCH v5 11/26] t4138: stop losing return codes of git commands Denton Liu
@ 2019-11-27 19:53         ` " Denton Liu
  2019-11-27 19:53         ` [PATCH v5 13/26] t5317: use ! grep to check for no matching lines Denton Liu
                           ` (13 subsequent siblings)
  25 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Currently, there are two ways where the return codes of git commands are
lost. The first way is when a command is in the upstream of a pipe. In a
pipe, only the return code of the last command is used. Thus, all other
commands will have their return codes masked. Rewrite pipes so that
there are no git commands upstream.

The other way is when a command is in a non-assignment command
substitution. The return code will be lost in favour of the surrounding
command's. Rewrite instances of this such that git commands output to a
file and surrounding commands only call command substitutions with
non-git commands.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5317-pack-objects-filter-objects.sh | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/t/t5317-pack-objects-filter-objects.sh b/t/t5317-pack-objects-filter-objects.sh
index 2d2f5d0229..a8bbad74e2 100755
--- a/t/t5317-pack-objects-filter-objects.sh
+++ b/t/t5317-pack-objects-filter-objects.sh
@@ -72,7 +72,8 @@ test_expect_success 'get an error for missing tree object' '
 	echo foo >r5/foo &&
 	git -C r5 add foo &&
 	git -C r5 commit -m "foo" &&
-	del=$(git -C r5 rev-parse HEAD^{tree} | sed "s|..|&/|") &&
+	git -C r5 rev-parse HEAD^{tree} >tree &&
+	del=$(sed "s|..|&/|" tree) &&
 	rm r5/.git/objects/$del &&
 	test_must_fail git -C r5 pack-objects --revs --stdout 2>bad_tree <<-EOF &&
 	HEAD
@@ -230,10 +231,9 @@ test_expect_success 'verify explicitly specifying oversized blob in input' '
 	awk -f print_2.awk ls_files_result |
 	sort >expected &&
 
-	git -C r2 pack-objects --revs --stdout --filter=blob:limit=1k >filter.pack <<-EOF &&
-	HEAD
-	$(git -C r2 rev-parse HEAD:large.10000)
-	EOF
+	echo HEAD >objects &&
+	git -C r2 rev-parse HEAD:large.10000 >>objects &&
+	git -C r2 pack-objects --revs --stdout --filter=blob:limit=1k <objects >filter.pack &&
 	git -C r2 index-pack ../filter.pack &&
 
 	git -C r2 verify-pack -v ../filter.pack >verify_result &&
@@ -377,7 +377,8 @@ test_expect_success 'verify sparse:oid=OID' '
 	awk -f print_2.awk ls_files_result |
 	sort >expected &&
 
-	oid=$(git -C r4 ls-files -s pattern | awk -f print_2.awk) &&
+	git -C r4 ls-files -s pattern >staged &&
+	oid=$(awk -f print_2.awk staged) &&
 	git -C r4 pack-objects --revs --stdout --filter=sparse:oid=$oid >filter.pack <<-EOF &&
 	HEAD
 	EOF
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v5 13/26] t5317: use ! grep to check for no matching lines
  2019-11-27 19:53       ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                           ` (11 preceding siblings ...)
  2019-11-27 19:53         ` [PATCH v5 12/26] t5317: " Denton Liu
@ 2019-11-27 19:53         ` Denton Liu
  2019-11-27 19:53         ` [PATCH v5 14/26] t5703: simplify one-time-sed generation logic Denton Liu
                           ` (12 subsequent siblings)
  25 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Several times in t5317, we would use `wc -l` to ensure that a grep
result is empty. However, grep already has a way to do that... Its
return code! Use `! grep` in the cases where we are ensuring that there
are no matching lines.

While at it, drop unnecessary invocations of `awk` and `sort` in each
affected test since those commands do not influence the outcome. It's
not clear why that extra work was being done in the first place, and the
code's history doesn't shed any light on the matter since these tests
were simply born this way[1], likely due to copy-paste programming. The
unnecessary work wasn't noticed even when the code was later touched for
various cleanups[2][3].

[1]: 9535ce7337 (pack-objects: add list-objects filtering, 2017-11-21)
[2]: bdbc17e86a (tests: standardize pipe placement, 2018-10-05)
[3]: 61de0ff695 (tests: don't swallow Git errors upstream of pipes, 2018-10-05)

Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5317-pack-objects-filter-objects.sh | 21 +++------------------
 1 file changed, 3 insertions(+), 18 deletions(-)

diff --git a/t/t5317-pack-objects-filter-objects.sh b/t/t5317-pack-objects-filter-objects.sh
index a8bbad74e2..dc0446574b 100755
--- a/t/t5317-pack-objects-filter-objects.sh
+++ b/t/t5317-pack-objects-filter-objects.sh
@@ -45,12 +45,7 @@ test_expect_success 'verify blob:none packfile has no blobs' '
 	git -C r1 index-pack ../filter.pack &&
 
 	git -C r1 verify-pack -v ../filter.pack >verify_result &&
-	grep blob verify_result |
-	awk -f print_1.awk |
-	sort >observed &&
-
-	nr=$(wc -l <observed) &&
-	test 0 -eq $nr
+	! grep blob verify_result
 '
 
 test_expect_success 'verify normal and blob:none packfiles have same commits/trees' '
@@ -149,12 +144,7 @@ test_expect_success 'verify blob:limit=500 omits all blobs' '
 	git -C r2 index-pack ../filter.pack &&
 
 	git -C r2 verify-pack -v ../filter.pack >verify_result &&
-	grep blob verify_result |
-	awk -f print_1.awk |
-	sort >observed &&
-
-	nr=$(wc -l <observed) &&
-	test 0 -eq $nr
+	! grep blob verify_result
 '
 
 test_expect_success 'verify blob:limit=1000' '
@@ -164,12 +154,7 @@ test_expect_success 'verify blob:limit=1000' '
 	git -C r2 index-pack ../filter.pack &&
 
 	git -C r2 verify-pack -v ../filter.pack >verify_result &&
-	grep blob verify_result |
-	awk -f print_1.awk |
-	sort >observed &&
-
-	nr=$(wc -l <observed) &&
-	test 0 -eq $nr
+	! grep blob verify_result
 '
 
 test_expect_success 'verify blob:limit=1001' '
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v5 14/26] t5703: simplify one-time-sed generation logic
  2019-11-27 19:53       ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                           ` (12 preceding siblings ...)
  2019-11-27 19:53         ` [PATCH v5 13/26] t5317: use ! grep to check for no matching lines Denton Liu
@ 2019-11-27 19:53         ` Denton Liu
  2019-11-27 19:53         ` [PATCH v5 15/26] t5703: stop losing return codes of git commands Denton Liu
                           ` (11 subsequent siblings)
  25 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

In inconsistency(), we had two `git rev-parse` invocations in the
upstream of a pipe within a command substitution. In case this
invocation ever failed, its exit code would be swallowed up and we would
not know about it.

Pull the command substitutions out into variable assignments so that
their return codes are not lost.

Drop the pipe into `tr` because the $(...) substitution already takes
care of stripping out newlines, so the `tr` invocations in the code are
superfluous.

Finally, given the way the tests actually employ "one-time-sed" via
$(cat one-time-sed) in t/lib-httpd/apply-one-time-sed.sh, convert the
`printf` into an `echo`. This makes it consistent with the final "server
loses a ref - ref in want" test, which does use `echo` rather than
`printf`.

Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5703-upload-pack-ref-in-want.sh | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/t/t5703-upload-pack-ref-in-want.sh b/t/t5703-upload-pack-ref-in-want.sh
index 3a2c143c6d..88338c4e09 100755
--- a/t/t5703-upload-pack-ref-in-want.sh
+++ b/t/t5703-upload-pack-ref-in-want.sh
@@ -312,10 +312,9 @@ inconsistency () {
 	# repository appears to change during negotiation, for example, when
 	# different servers in a load-balancing arrangement serve (stateless)
 	# RPCs during a single negotiation.
-	printf "s/%s/%s/" \
-	       $(git -C "$REPO" rev-parse $1 | tr -d "\n") \
-	       $(git -C "$REPO" rev-parse $2 | tr -d "\n") \
-	       >"$HTTPD_ROOT_PATH/one-time-sed"
+	oid1=$(git -C "$REPO" rev-parse $1) &&
+	oid2=$(git -C "$REPO" rev-parse $2) &&
+	echo "s/$oid1/$oid2/" >"$HTTPD_ROOT_PATH/one-time-sed"
 }
 
 test_expect_success 'server is initially ahead - no ref in want' '
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v5 15/26] t5703: stop losing return codes of git commands
  2019-11-27 19:53       ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                           ` (13 preceding siblings ...)
  2019-11-27 19:53         ` [PATCH v5 14/26] t5703: simplify one-time-sed generation logic Denton Liu
@ 2019-11-27 19:53         ` Denton Liu
  2019-11-27 19:53         ` [PATCH v5 16/26] t7501: remove spaces after redirect operators Denton Liu
                           ` (10 subsequent siblings)
  25 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Currently, there are two ways where the return codes of git commands are
lost. The first way is when a command is in the upstream of a pipe. In a
pipe, only the return code of the last command is used. Thus, all other
commands will have their return codes masked. Rewrite pipes so that
there are no git commands upstream.

The other way is when a command is in a non-assignment command
substitution. The return code will be lost in favour of the surrounding
command's. Rewrite instances of this such that git commands are in an
assignment-only command substitution.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5703-upload-pack-ref-in-want.sh | 46 +++++++++++++++++++-----------
 1 file changed, 29 insertions(+), 17 deletions(-)

diff --git a/t/t5703-upload-pack-ref-in-want.sh b/t/t5703-upload-pack-ref-in-want.sh
index 88338c4e09..1424fabd4a 100755
--- a/t/t5703-upload-pack-ref-in-want.sh
+++ b/t/t5703-upload-pack-ref-in-want.sh
@@ -18,14 +18,16 @@ get_actual_commits () {
 		p
 		}' <out | test-tool pkt-line unpack-sideband >o.pack &&
 	git index-pack o.pack &&
-	git verify-pack -v o.idx | grep commit | cut -c-40 | sort >actual_commits
+	git verify-pack -v o.idx >objs &&
+	grep commit objs | cut -c-40 | sort >actual_commits
 }
 
 check_output () {
 	get_actual_refs &&
 	test_cmp expected_refs actual_refs &&
 	get_actual_commits &&
-	test_cmp expected_commits actual_commits
+	sort expected_commits >sorted_commits &&
+	test_cmp sorted_commits actual_commits
 }
 
 # c(o/foo) d(o/bar)
@@ -75,17 +77,19 @@ test_expect_success 'invalid want-ref line' '
 '
 
 test_expect_success 'basic want-ref' '
+	oid=$(git rev-parse f) &&
 	cat >expected_refs <<-EOF &&
-	$(git rev-parse f) refs/heads/master
+	$oid refs/heads/master
 	EOF
-	git rev-parse f | sort >expected_commits &&
+	git rev-parse f >expected_commits &&
 
+	oid=$(git rev-parse a) &&
 	test-tool pkt-line pack >in <<-EOF &&
 	command=fetch
 	0001
 	no-progress
 	want-ref refs/heads/master
-	have $(git rev-parse a)
+	have $oid
 	done
 	0000
 	EOF
@@ -95,19 +99,22 @@ test_expect_success 'basic want-ref' '
 '
 
 test_expect_success 'multiple want-ref lines' '
+	oid_c=$(git rev-parse c) &&
+	oid_d=$(git rev-parse d) &&
 	cat >expected_refs <<-EOF &&
-	$(git rev-parse c) refs/heads/o/foo
-	$(git rev-parse d) refs/heads/o/bar
+	$oid_c refs/heads/o/foo
+	$oid_d refs/heads/o/bar
 	EOF
-	git rev-parse c d | sort >expected_commits &&
+	git rev-parse c d >expected_commits &&
 
+	oid=$(git rev-parse b) &&
 	test-tool pkt-line pack >in <<-EOF &&
 	command=fetch
 	0001
 	no-progress
 	want-ref refs/heads/o/foo
 	want-ref refs/heads/o/bar
-	have $(git rev-parse b)
+	have $oid
 	done
 	0000
 	EOF
@@ -117,10 +124,11 @@ test_expect_success 'multiple want-ref lines' '
 '
 
 test_expect_success 'mix want and want-ref' '
+	oid=$(git rev-parse f) &&
 	cat >expected_refs <<-EOF &&
-	$(git rev-parse f) refs/heads/master
+	$oid refs/heads/master
 	EOF
-	git rev-parse e f | sort >expected_commits &&
+	git rev-parse e f >expected_commits &&
 
 	test-tool pkt-line pack >in <<-EOF &&
 	command=fetch
@@ -138,17 +146,19 @@ test_expect_success 'mix want and want-ref' '
 '
 
 test_expect_success 'want-ref with ref we already have commit for' '
+	oid=$(git rev-parse c) &&
 	cat >expected_refs <<-EOF &&
-	$(git rev-parse c) refs/heads/o/foo
+	$oid refs/heads/o/foo
 	EOF
 	>expected_commits &&
 
+	oid=$(git rev-parse c) &&
 	test-tool pkt-line pack >in <<-EOF &&
 	command=fetch
 	0001
 	no-progress
 	want-ref refs/heads/o/foo
-	have $(git rev-parse c)
+	have $oid
 	done
 	0000
 	EOF
@@ -211,13 +221,14 @@ test_expect_success 'fetching with exact OID' '
 
 	rm -rf local &&
 	cp -r "$LOCAL_PRISTINE" local &&
+	oid=$(git -C "$REPO" rev-parse d) &&
 	GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin \
-		$(git -C "$REPO" rev-parse d):refs/heads/actual &&
+		"$oid":refs/heads/actual &&
 
 	git -C "$REPO" rev-parse "d" >expected &&
 	git -C local rev-parse refs/heads/actual >actual &&
 	test_cmp expected actual &&
-	grep "want $(git -C "$REPO" rev-parse d)" log
+	grep "want $oid" log
 '
 
 test_expect_success 'fetching multiple refs' '
@@ -239,13 +250,14 @@ test_expect_success 'fetching ref and exact OID' '
 
 	rm -rf local &&
 	cp -r "$LOCAL_PRISTINE" local &&
+	oid=$(git -C "$REPO" rev-parse b) &&
 	GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin \
-		master $(git -C "$REPO" rev-parse b):refs/heads/actual &&
+		master "$oid":refs/heads/actual &&
 
 	git -C "$REPO" rev-parse "master" "b" >expected &&
 	git -C local rev-parse refs/remotes/origin/master refs/heads/actual >actual &&
 	test_cmp expected actual &&
-	grep "want $(git -C "$REPO" rev-parse b)" log &&
+	grep "want $oid" log &&
 	grep "want-ref refs/heads/master" log
 '
 
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v5 16/26] t7501: remove spaces after redirect operators
  2019-11-27 19:53       ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                           ` (14 preceding siblings ...)
  2019-11-27 19:53         ` [PATCH v5 15/26] t5703: stop losing return codes of git commands Denton Liu
@ 2019-11-27 19:53         ` Denton Liu
  2019-11-27 19:53         ` [PATCH v5 17/26] t7501: stop losing return codes of git commands Denton Liu
                           ` (9 subsequent siblings)
  25 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

For shell scripts, the usual convention is for there to be no space
after redirection operators, (e.g. `>file`, not `> file`). Remove these
spaces wherever they appear.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7501-commit-basic-functionality.sh | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/t/t7501-commit-basic-functionality.sh b/t/t7501-commit-basic-functionality.sh
index f1349af56e..5765d33c53 100755
--- a/t/t7501-commit-basic-functionality.sh
+++ b/t/t7501-commit-basic-functionality.sh
@@ -150,7 +150,7 @@ test_expect_success 'setup: commit message from file' '
 test_expect_success 'amend commit' '
 	cat >editor <<-\EOF &&
 	#!/bin/sh
-	sed -e "s/a file/an amend commit/g" < "$1" > "$1-"
+	sed -e "s/a file/an amend commit/g" <"$1" >"$1-"
 	mv "$1-" "$1"
 	EOF
 	chmod 755 editor &&
@@ -263,7 +263,7 @@ test_expect_success 'using message from other commit' '
 test_expect_success 'editing message from other commit' '
 	cat >editor <<-\EOF &&
 	#!/bin/sh
-	sed -e "s/amend/older/g"  < "$1" > "$1-"
+	sed -e "s/amend/older/g"  <"$1" >"$1-"
 	mv "$1-" "$1"
 	EOF
 	chmod 755 editor &&
@@ -367,7 +367,7 @@ test_expect_success 'amend commit to fix author' '
 		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
 		expected &&
 	git commit --amend --author="$author" &&
-	git cat-file -p HEAD > current &&
+	git cat-file -p HEAD >current &&
 	test_cmp expected current
 
 '
@@ -382,7 +382,7 @@ test_expect_success 'amend commit to fix date' '
 		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
 		expected &&
 	git commit --amend --date="$newtick" &&
-	git cat-file -p HEAD > current &&
+	git cat-file -p HEAD >current &&
 	test_cmp expected current
 
 '
@@ -448,7 +448,7 @@ test_expect_success 'signoff gap' '
 	git commit -s -m "welcome
 
 $alt" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
+	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
 	(
 		echo welcome &&
 		echo &&
@@ -468,7 +468,7 @@ test_expect_success 'signoff gap 2' '
 
 We have now
 $alt" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
+	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
 	(
 		echo welcome &&
 		echo &&
@@ -489,7 +489,7 @@ test_expect_success 'signoff respects trailer config' '
 
 non-trailer line
 Myfooter: x" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
+	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
 	(
 		echo subject &&
 		echo &&
@@ -506,7 +506,7 @@ Myfooter: x" &&
 
 non-trailer line
 Myfooter: x" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
+	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
 	(
 		echo subject &&
 		echo &&
@@ -560,14 +560,14 @@ test_expect_success 'amend commit to fix author' '
 		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
 		expected &&
 	git commit --amend --author="$author" &&
-	git cat-file -p HEAD > current &&
+	git cat-file -p HEAD >current &&
 	test_cmp expected current
 
 '
 
 test_expect_success 'git commit <file> with dirty index' '
-	echo tacocat > elif &&
-	echo tehlulz > chz &&
+	echo tacocat >elif &&
+	echo tehlulz >chz &&
 	git add chz &&
 	git commit elif -m "tacocat is a palindrome" &&
 	git show --stat | grep elif &&
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v5 17/26] t7501: stop losing return codes of git commands
  2019-11-27 19:53       ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                           ` (15 preceding siblings ...)
  2019-11-27 19:53         ` [PATCH v5 16/26] t7501: remove spaces after redirect operators Denton Liu
@ 2019-11-27 19:53         ` Denton Liu
  2019-11-27 19:53         ` [PATCH v5 18/26] t7700: drop redirections to /dev/null Denton Liu
                           ` (8 subsequent siblings)
  25 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

In a pipe, only the return code of the last command is used. Thus, all
other commands will have their return codes masked. Rewrite pipes so
that there are no git commands upstream so that we will know if a
command fails.

In the 'interactive add' test case, we prepend a `test_must_fail` to
`git commit --interactive`. When there are no changes to commit,
`git commit` will exit with status code 1. Following along with the rest
of the file, we use `test_must_fail` to test for this case.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7501-commit-basic-functionality.sh | 69 +++++++++++++++------------
 1 file changed, 39 insertions(+), 30 deletions(-)

diff --git a/t/t7501-commit-basic-functionality.sh b/t/t7501-commit-basic-functionality.sh
index 5765d33c53..110b4bf459 100755
--- a/t/t7501-commit-basic-functionality.sh
+++ b/t/t7501-commit-basic-functionality.sh
@@ -285,9 +285,8 @@ test_expect_success 'overriding author from command line' '
 '
 
 test_expect_success PERL 'interactive add' '
-	echo 7 |
-	git commit --interactive |
-	grep "What now"
+	echo 7 | test_must_fail git commit --interactive >out &&
+	grep "What now" out
 '
 
 test_expect_success PERL "commit --interactive doesn't change index if editor aborts" '
@@ -362,10 +361,10 @@ test_expect_success 'amend commit to fix author' '
 	oldtick=$GIT_AUTHOR_DATE &&
 	test_tick &&
 	git reset --hard &&
-	git cat-file -p HEAD |
+	git cat-file -p HEAD >commit &&
 	sed -e "s/author.*/author $author $oldtick/" \
-		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
-		expected &&
+		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" \
+		commit >expected &&
 	git commit --amend --author="$author" &&
 	git cat-file -p HEAD >current &&
 	test_cmp expected current
@@ -377,10 +376,10 @@ test_expect_success 'amend commit to fix date' '
 	test_tick &&
 	newtick=$GIT_AUTHOR_DATE &&
 	git reset --hard &&
-	git cat-file -p HEAD |
+	git cat-file -p HEAD >commit &&
 	sed -e "s/author.*/author $author $newtick/" \
-		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
-		expected &&
+		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" \
+		commit >expected &&
 	git commit --amend --date="$newtick" &&
 	git cat-file -p HEAD >current &&
 	test_cmp expected current
@@ -409,12 +408,13 @@ test_expect_success 'sign off (1)' '
 	echo 1 >positive &&
 	git add positive &&
 	git commit -s -m "thank you" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
+	git cat-file commit HEAD >commit &&
+	sed -e "1,/^\$/d" commit >actual &&
 	(
 		echo thank you &&
 		echo &&
-		git var GIT_COMMITTER_IDENT |
-		sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
+		git var GIT_COMMITTER_IDENT >ident &&
+		sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" ident
 	) >expected &&
 	test_cmp expected actual
 
@@ -428,13 +428,14 @@ test_expect_success 'sign off (2)' '
 	git commit -s -m "thank you
 
 $existing" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
+	git cat-file commit HEAD >commit &&
+	sed -e "1,/^\$/d" commit >actual &&
 	(
 		echo thank you &&
 		echo &&
 		echo $existing &&
-		git var GIT_COMMITTER_IDENT |
-		sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
+		git var GIT_COMMITTER_IDENT >ident &&
+		sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" ident
 	) >expected &&
 	test_cmp expected actual
 
@@ -448,13 +449,14 @@ test_expect_success 'signoff gap' '
 	git commit -s -m "welcome
 
 $alt" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
+	git cat-file commit HEAD >commit &&
+	sed -e "1,/^\$/d" commit >actual &&
 	(
 		echo welcome &&
 		echo &&
 		echo $alt &&
-		git var GIT_COMMITTER_IDENT |
-		sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
+		git var GIT_COMMITTER_IDENT >ident &&
+		sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" ident
 	) >expected &&
 	test_cmp expected actual
 '
@@ -468,15 +470,16 @@ test_expect_success 'signoff gap 2' '
 
 We have now
 $alt" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
+	git cat-file commit HEAD >commit &&
+	sed -e "1,/^\$/d" commit >actual &&
 	(
 		echo welcome &&
 		echo &&
 		echo We have now &&
 		echo $alt &&
 		echo &&
-		git var GIT_COMMITTER_IDENT |
-		sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
+		git var GIT_COMMITTER_IDENT >ident &&
+		sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" ident
 	) >expected &&
 	test_cmp expected actual
 '
@@ -489,7 +492,8 @@ test_expect_success 'signoff respects trailer config' '
 
 non-trailer line
 Myfooter: x" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
+	git cat-file commit HEAD >commit &&
+	sed -e "1,/^\$/d" commit >actual &&
 	(
 		echo subject &&
 		echo &&
@@ -506,7 +510,8 @@ Myfooter: x" &&
 
 non-trailer line
 Myfooter: x" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
+	git cat-file commit HEAD >commit &&
+	sed -e "1,/^\$/d" commit >actual &&
 	(
 		echo subject &&
 		echo &&
@@ -538,7 +543,8 @@ test_expect_success 'multiple -m' '
 	>negative &&
 	git add negative &&
 	git commit -m "one" -m "two" -m "three" &&
-	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
+	git cat-file commit HEAD >commit &&
+	sed -e "1,/^\$/d" commit >actual &&
 	(
 		echo one &&
 		echo &&
@@ -555,10 +561,10 @@ test_expect_success 'amend commit to fix author' '
 	oldtick=$GIT_AUTHOR_DATE &&
 	test_tick &&
 	git reset --hard &&
-	git cat-file -p HEAD |
+	git cat-file -p HEAD >commit &&
 	sed -e "s/author.*/author $author $oldtick/" \
-		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
-		expected &&
+		-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" \
+		commit >expected &&
 	git commit --amend --author="$author" &&
 	git cat-file -p HEAD >current &&
 	test_cmp expected current
@@ -570,8 +576,10 @@ test_expect_success 'git commit <file> with dirty index' '
 	echo tehlulz >chz &&
 	git add chz &&
 	git commit elif -m "tacocat is a palindrome" &&
-	git show --stat | grep elif &&
-	git diff --cached | grep chz
+	git show --stat >stat &&
+	grep elif stat &&
+	git diff --cached >diff &&
+	grep chz diff
 '
 
 test_expect_success 'same tree (single parent)' '
@@ -584,7 +592,8 @@ test_expect_success 'same tree (single parent)' '
 test_expect_success 'same tree (single parent) --allow-empty' '
 
 	git commit --allow-empty -m "forced empty" &&
-	git cat-file commit HEAD | grep forced
+	git cat-file commit HEAD >commit &&
+	grep forced commit
 
 '
 
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v5 18/26] t7700: drop redirections to /dev/null
  2019-11-27 19:53       ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                           ` (16 preceding siblings ...)
  2019-11-27 19:53         ` [PATCH v5 17/26] t7501: stop losing return codes of git commands Denton Liu
@ 2019-11-27 19:53         ` Denton Liu
  2019-11-27 19:53         ` [PATCH v5 19/26] t7700: remove spaces after redirect operators Denton Liu
                           ` (7 subsequent siblings)
  25 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Since output is silenced when running without `-v` and debugging output
is useful with `-v`, remove redirections to /dev/null as it is not
useful.

In one case where the output of stdout is consumed, redirect the output
of test_commit to stderr.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7700-repack.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index 4e855bc21b..e1a689d6a9 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -5,7 +5,7 @@ test_description='git repack works correctly'
 . ./test-lib.sh
 
 commit_and_pack() {
-	test_commit "$@" >/dev/null &&
+	test_commit "$@" 1>&2 &&
 	SHA1=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) &&
 	echo pack-${SHA1}.pack
 }
@@ -19,7 +19,7 @@ test_expect_success 'objects in packs marked .keep are not repacked' '
 	# Create two packs
 	# The first pack will contain all of the objects except one
 	git rev-list --objects --all | grep -v file2 |
-		git pack-objects pack > /dev/null &&
+		git pack-objects pack &&
 	# The second pack will contain the excluded object
 	packsha1=$(git rev-list --objects --all | grep file2 |
 		git pack-objects pack) &&
@@ -235,7 +235,7 @@ test_expect_success 'incremental repack does not complain' '
 
 test_expect_success 'bitmaps can be disabled on bare repos' '
 	git -c repack.writeBitmaps=false -C bare.git repack -ad &&
-	bitmap=$(ls bare.git/objects/pack/*.bitmap 2>/dev/null || :) &&
+	bitmap=$(ls bare.git/objects/pack/*.bitmap || :) &&
 	test -z "$bitmap"
 '
 
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v5 19/26] t7700: remove spaces after redirect operators
  2019-11-27 19:53       ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                           ` (17 preceding siblings ...)
  2019-11-27 19:53         ` [PATCH v5 18/26] t7700: drop redirections to /dev/null Denton Liu
@ 2019-11-27 19:53         ` Denton Liu
  2019-11-27 19:53         ` [PATCH v5 20/26] t7700: move keywords onto their own line Denton Liu
                           ` (6 subsequent siblings)
  25 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

For shell scripts, the usual convention is for there to be no space
after redirection operators, (e.g. `>file`, not `> file`). Remove these
spaces wherever they appear.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7700-repack.sh | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index e1a689d6a9..8936928387 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -11,8 +11,8 @@ commit_and_pack() {
 }
 
 test_expect_success 'objects in packs marked .keep are not repacked' '
-	echo content1 > file1 &&
-	echo content2 > file2 &&
+	echo content1 >file1 &&
+	echo content2 >file2 &&
 	git add . &&
 	test_tick &&
 	git commit -m initial_commit &&
@@ -75,8 +75,8 @@ test_expect_success 'writing bitmaps via config can duplicate .keep objects' '
 
 test_expect_success 'loose objects in alternate ODB are not repacked' '
 	mkdir alt_objects &&
-	echo $(pwd)/alt_objects > .git/objects/info/alternates &&
-	echo content3 > file3 &&
+	echo $(pwd)/alt_objects >.git/objects/info/alternates &&
+	echo content3 >file3 &&
 	objsha1=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) &&
 	git add file3 &&
 	test_tick &&
@@ -111,7 +111,7 @@ test_expect_success 'packed obs in alt ODB are repacked even when local repo is
 
 test_expect_success 'packed obs in alt ODB are repacked when local repo has packs' '
 	rm -f .git/objects/pack/* &&
-	echo new_content >> file1 &&
+	echo new_content >>file1 &&
 	git add file1 &&
 	test_tick &&
 	git commit -m more_content &&
@@ -169,12 +169,12 @@ test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
 	mv pack-* .git/objects/pack/ &&
 	test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
 		egrep "^$csha1 " | sort | uniq | wc -l) &&
-	echo > .git/objects/info/alternates &&
+	echo >.git/objects/info/alternates &&
 	test_must_fail git show $csha1
 '
 
 test_expect_success 'local packed unreachable obs that exist in alternate ODB are not loosened' '
-	echo $(pwd)/alt_objects > .git/objects/info/alternates &&
+	echo $(pwd)/alt_objects >.git/objects/info/alternates &&
 	echo "$csha1" | git pack-objects --non-empty --all --reflog pack &&
 	rm -f .git/objects/pack/* &&
 	mv pack-* .git/objects/pack/ &&
@@ -186,7 +186,7 @@ test_expect_success 'local packed unreachable obs that exist in alternate ODB ar
 	mv pack-* .git/objects/pack/ &&
 	test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
 		egrep "^$csha1 " | sort | uniq | wc -l) &&
-	echo > .git/objects/info/alternates &&
+	echo >.git/objects/info/alternates &&
 	test_must_fail git show $csha1
 '
 
@@ -196,7 +196,7 @@ test_expect_success 'objects made unreachable by grafts only are kept' '
 	H0=$(git rev-parse HEAD) &&
 	H1=$(git rev-parse HEAD^) &&
 	H2=$(git rev-parse HEAD^^) &&
-	echo "$H0 $H2" > .git/info/grafts &&
+	echo "$H0 $H2" >.git/info/grafts &&
 	git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all &&
 	git repack -a -d &&
 	git cat-file -t $H1
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v5 20/26] t7700: move keywords onto their own line
  2019-11-27 19:53       ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                           ` (18 preceding siblings ...)
  2019-11-27 19:53         ` [PATCH v5 19/26] t7700: remove spaces after redirect operators Denton Liu
@ 2019-11-27 19:53         ` Denton Liu
  2019-11-27 19:53         ` [PATCH v5 21/26] t7700: s/test -f/test_path_is_file/ Denton Liu
                           ` (5 subsequent siblings)
  25 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

The code style for tests is to have statements on their own line if
possible. Move keywords onto their own line so that they conform with
the test style.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7700-repack.sh | 51 +++++++++++++++++++++++++++++++----------------
 1 file changed, 34 insertions(+), 17 deletions(-)

diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index 8936928387..a96e876c4e 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -29,10 +29,12 @@ test_expect_success 'objects in packs marked .keep are not repacked' '
 	mv pack-* .git/objects/pack/ &&
 	git repack -A -d -l &&
 	git prune-packed &&
-	for p in .git/objects/pack/*.idx; do
+	for p in .git/objects/pack/*.idx
+	do
 		idx=$(basename $p)
 		test "pack-$packsha1.idx" = "$idx" && continue
-		if git verify-pack -v $p | egrep "^$objsha1"; then
+		if git verify-pack -v $p | egrep "^$objsha1"
+		then
 			found_duplicate_object=1
 			echo "DUPLICATE OBJECT FOUND"
 			break
@@ -45,10 +47,12 @@ test_expect_success 'writing bitmaps via command-line can duplicate .keep object
 	# build on $objsha1, $packsha1, and .keep state from previous
 	git repack -Adbl &&
 	test_when_finished "found_duplicate_object=" &&
-	for p in .git/objects/pack/*.idx; do
+	for p in .git/objects/pack/*.idx
+	do
 		idx=$(basename $p)
 		test "pack-$packsha1.idx" = "$idx" && continue
-		if git verify-pack -v $p | egrep "^$objsha1"; then
+		if git verify-pack -v $p | egrep "^$objsha1"
+		then
 			found_duplicate_object=1
 			echo "DUPLICATE OBJECT FOUND"
 			break
@@ -61,10 +65,12 @@ test_expect_success 'writing bitmaps via config can duplicate .keep objects' '
 	# build on $objsha1, $packsha1, and .keep state from previous
 	git -c repack.writebitmaps=true repack -Adl &&
 	test_when_finished "found_duplicate_object=" &&
-	for p in .git/objects/pack/*.idx; do
+	for p in .git/objects/pack/*.idx
+	do
 		idx=$(basename $p)
 		test "pack-$packsha1.idx" = "$idx" && continue
-		if git verify-pack -v $p | egrep "^$objsha1"; then
+		if git verify-pack -v $p | egrep "^$objsha1"
+		then
 			found_duplicate_object=1
 			echo "DUPLICATE OBJECT FOUND"
 			break
@@ -83,8 +89,10 @@ test_expect_success 'loose objects in alternate ODB are not repacked' '
 	git commit -m commit_file3 &&
 	git repack -a -d -l &&
 	git prune-packed &&
-	for p in .git/objects/pack/*.idx; do
-		if git verify-pack -v $p | egrep "^$objsha1"; then
+	for p in .git/objects/pack/*.idx
+	do
+		if git verify-pack -v $p | egrep "^$objsha1"
+		then
 			found_duplicate_object=1
 			echo "DUPLICATE OBJECT FOUND"
 			break
@@ -99,10 +107,13 @@ test_expect_success 'packed obs in alt ODB are repacked even when local repo is
 	git repack -a &&
 	myidx=$(ls -1 .git/objects/pack/*.idx) &&
 	test -f "$myidx" &&
-	for p in alt_objects/pack/*.idx; do
+	for p in alt_objects/pack/*.idx
+	do
 		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
-	done | while read sha1 rest; do
-		if ! ( git verify-pack -v $myidx | grep "^$sha1" ); then
+	done | while read sha1 rest
+	do
+		if ! ( git verify-pack -v $myidx | grep "^$sha1" )
+		then
 			echo "Missing object in local pack: $sha1"
 			return 1
 		fi
@@ -119,10 +130,13 @@ test_expect_success 'packed obs in alt ODB are repacked when local repo has pack
 	git repack -a -d &&
 	myidx=$(ls -1 .git/objects/pack/*.idx) &&
 	test -f "$myidx" &&
-	for p in alt_objects/pack/*.idx; do
+	for p in alt_objects/pack/*.idx
+	do
 		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
-	done | while read sha1 rest; do
-		if ! ( git verify-pack -v $myidx | grep "^$sha1" ); then
+	done | while read sha1 rest
+	do
+		if ! ( git verify-pack -v $myidx | grep "^$sha1" )
+		then
 			echo "Missing object in local pack: $sha1"
 			return 1
 		fi
@@ -144,10 +158,13 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
 	git repack -a -d &&
 	myidx=$(ls -1 .git/objects/pack/*.idx) &&
 	test -f "$myidx" &&
-	for p in alt_objects/pack/*.idx; do
+	for p in alt_objects/pack/*.idx
+	do
 		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
-	done | while read sha1 rest; do
-		if ! ( git verify-pack -v $myidx | grep "^$sha1" ); then
+	done | while read sha1 rest
+	do
+		if ! ( git verify-pack -v $myidx | grep "^$sha1" )
+		then
 			echo "Missing object in local pack: $sha1"
 			return 1
 		fi
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v5 21/26] t7700: s/test -f/test_path_is_file/
  2019-11-27 19:53       ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                           ` (19 preceding siblings ...)
  2019-11-27 19:53         ` [PATCH v5 20/26] t7700: move keywords onto their own line Denton Liu
@ 2019-11-27 19:53         ` Denton Liu
  2019-11-27 19:53         ` [PATCH v5 22/26] t7700: consolidate code into test_no_missing_in_packs() Denton Liu
                           ` (4 subsequent siblings)
  25 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Since we have debugging-friendly alternatives to `test -f`, replace
instances of `test -f` with `test_path_is_file` so that if a command
ever fails, we get better debugging information.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7700-repack.sh | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index a96e876c4e..1d14ddcbdb 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -106,7 +106,7 @@ test_expect_success 'packed obs in alt ODB are repacked even when local repo is
 	mv .git/objects/pack/* alt_objects/pack &&
 	git repack -a &&
 	myidx=$(ls -1 .git/objects/pack/*.idx) &&
-	test -f "$myidx" &&
+	test_path_is_file "$myidx" &&
 	for p in alt_objects/pack/*.idx
 	do
 		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
@@ -129,7 +129,7 @@ test_expect_success 'packed obs in alt ODB are repacked when local repo has pack
 	git repack &&
 	git repack -a -d &&
 	myidx=$(ls -1 .git/objects/pack/*.idx) &&
-	test -f "$myidx" &&
+	test_path_is_file "$myidx" &&
 	for p in alt_objects/pack/*.idx
 	do
 		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
@@ -148,7 +148,7 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
 	for p in alt_objects/pack/*.pack
 	do
 		base_name=$(basename $p .pack) &&
-		if test -f alt_objects/pack/$base_name.keep
+		if test_path_is_file alt_objects/pack/$base_name.keep
 		then
 			rm alt_objects/pack/$base_name.keep
 		else
@@ -157,7 +157,7 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
 	done &&
 	git repack -a -d &&
 	myidx=$(ls -1 .git/objects/pack/*.idx) &&
-	test -f "$myidx" &&
+	test_path_is_file "$myidx" &&
 	for p in alt_objects/pack/*.idx
 	do
 		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v5 22/26] t7700: consolidate code into test_no_missing_in_packs()
  2019-11-27 19:53       ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                           ` (20 preceding siblings ...)
  2019-11-27 19:53         ` [PATCH v5 21/26] t7700: s/test -f/test_path_is_file/ Denton Liu
@ 2019-11-27 19:53         ` Denton Liu
  2019-11-29 21:39           ` Junio C Hamano
  2019-11-27 19:53         ` [PATCH v5 23/26] t7700: consolidate code into test_has_duplicate_object() Denton Liu
                           ` (3 subsequent siblings)
  25 siblings, 1 reply; 169+ messages in thread
From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

The code to test that objects were not missing from the packfile was
duplicated many times. Extract the duplicated code into
test_no_missing_in_packs() and use that instead.

Refactor the resulting extraction so that if any git commands fail,
their return codes are not silently lost.

We were using sed to filter lines. Although not incorrect, this is
exactly what grep is built for. Replace this invocation of sed with grep
so that we use the correct tool for the job.

Instead of verifying each file of `alt_objects/pack/*.idx` individually
in a for-loop, batch them together into one verification step.

The original testing construct was O(n^2): it used a grep in a loop to
test whether any objects were missing in the packfile. Rewrite this to
sort the files then use `comm -23` so that finding missing lines from
the original file is done more efficiently.

While we're at it, add a space to `commit_and_pack ()` for style.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7700-repack.sh | 55 +++++++++++++----------------------------------
 1 file changed, 15 insertions(+), 40 deletions(-)

diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index 1d14ddcbdb..4bcd9fcc80 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -4,12 +4,23 @@ test_description='git repack works correctly'
 
 . ./test-lib.sh
 
-commit_and_pack() {
+commit_and_pack () {
 	test_commit "$@" 1>&2 &&
 	SHA1=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) &&
 	echo pack-${SHA1}.pack
 }
 
+test_no_missing_in_packs () {
+	myidx=$(ls -1 .git/objects/pack/*.idx) &&
+	test_path_is_file "$myidx" &&
+	git verify-pack -v alt_objects/pack/*.idx >orig.raw &&
+	grep "^[0-9a-f]\{40\}" orig.raw | cut -d" " -f1 | sort >orig &&
+	git verify-pack -v $myidx >dest.raw &&
+	cut -d" " -f1 dest.raw | sort >dest &&
+	comm -23 orig dest >missing &&
+	test_must_be_empty missing
+}
+
 test_expect_success 'objects in packs marked .keep are not repacked' '
 	echo content1 >file1 &&
 	echo content2 >file2 &&
@@ -105,19 +116,7 @@ test_expect_success 'packed obs in alt ODB are repacked even when local repo is
 	mkdir alt_objects/pack &&
 	mv .git/objects/pack/* alt_objects/pack &&
 	git repack -a &&
-	myidx=$(ls -1 .git/objects/pack/*.idx) &&
-	test_path_is_file "$myidx" &&
-	for p in alt_objects/pack/*.idx
-	do
-		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
-	done | while read sha1 rest
-	do
-		if ! ( git verify-pack -v $myidx | grep "^$sha1" )
-		then
-			echo "Missing object in local pack: $sha1"
-			return 1
-		fi
-	done
+	test_no_missing_in_packs
 '
 
 test_expect_success 'packed obs in alt ODB are repacked when local repo has packs' '
@@ -128,19 +127,7 @@ test_expect_success 'packed obs in alt ODB are repacked when local repo has pack
 	git commit -m more_content &&
 	git repack &&
 	git repack -a -d &&
-	myidx=$(ls -1 .git/objects/pack/*.idx) &&
-	test_path_is_file "$myidx" &&
-	for p in alt_objects/pack/*.idx
-	do
-		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
-	done | while read sha1 rest
-	do
-		if ! ( git verify-pack -v $myidx | grep "^$sha1" )
-		then
-			echo "Missing object in local pack: $sha1"
-			return 1
-		fi
-	done
+	test_no_missing_in_packs
 '
 
 test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
@@ -156,19 +143,7 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
 		fi
 	done &&
 	git repack -a -d &&
-	myidx=$(ls -1 .git/objects/pack/*.idx) &&
-	test_path_is_file "$myidx" &&
-	for p in alt_objects/pack/*.idx
-	do
-		git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
-	done | while read sha1 rest
-	do
-		if ! ( git verify-pack -v $myidx | grep "^$sha1" )
-		then
-			echo "Missing object in local pack: $sha1"
-			return 1
-		fi
-	done
+	test_no_missing_in_packs
 '
 
 test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v5 23/26] t7700: consolidate code into test_has_duplicate_object()
  2019-11-27 19:53       ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                           ` (21 preceding siblings ...)
  2019-11-27 19:53         ` [PATCH v5 22/26] t7700: consolidate code into test_no_missing_in_packs() Denton Liu
@ 2019-11-27 19:53         ` Denton Liu
  2019-11-27 19:53         ` [PATCH v5 24/26] t7700: replace egrep with grep Denton Liu
                           ` (2 subsequent siblings)
  25 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

The code to test that objects were not duplicated from the packfile was
duplicated many times. Extract the duplicated code into
test_has_duplicate_object() and use that instead.

Refactor the resulting extraction so that if the git command fails,
the return code is not silently lost.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7700-repack.sh | 71 +++++++++++++++--------------------------------
 1 file changed, 23 insertions(+), 48 deletions(-)

diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index 4bcd9fcc80..5bbed02fe5 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -21,6 +21,25 @@ test_no_missing_in_packs () {
 	test_must_be_empty missing
 }
 
+# we expect $packsha1 and $objsha1 to be defined
+test_has_duplicate_object () {
+	want_duplicate_object="$1"
+	found_duplicate_object=false
+	for p in .git/objects/pack/*.idx
+	do
+		idx=$(basename $p)
+		test "pack-$packsha1.idx" = "$idx" && continue
+		git verify-pack -v $p >packlist || return $?
+		if egrep "^$objsha1" packlist
+		then
+			found_duplicate_object=true
+			echo "DUPLICATE OBJECT FOUND"
+			break
+		fi
+	done &&
+	test "$want_duplicate_object" = "$found_duplicate_object"
+}
+
 test_expect_success 'objects in packs marked .keep are not repacked' '
 	echo content1 >file1 &&
 	echo content2 >file2 &&
@@ -40,54 +59,19 @@ test_expect_success 'objects in packs marked .keep are not repacked' '
 	mv pack-* .git/objects/pack/ &&
 	git repack -A -d -l &&
 	git prune-packed &&
-	for p in .git/objects/pack/*.idx
-	do
-		idx=$(basename $p)
-		test "pack-$packsha1.idx" = "$idx" && continue
-		if git verify-pack -v $p | egrep "^$objsha1"
-		then
-			found_duplicate_object=1
-			echo "DUPLICATE OBJECT FOUND"
-			break
-		fi
-	done &&
-	test -z "$found_duplicate_object"
+	test_has_duplicate_object false
 '
 
 test_expect_success 'writing bitmaps via command-line can duplicate .keep objects' '
 	# build on $objsha1, $packsha1, and .keep state from previous
 	git repack -Adbl &&
-	test_when_finished "found_duplicate_object=" &&
-	for p in .git/objects/pack/*.idx
-	do
-		idx=$(basename $p)
-		test "pack-$packsha1.idx" = "$idx" && continue
-		if git verify-pack -v $p | egrep "^$objsha1"
-		then
-			found_duplicate_object=1
-			echo "DUPLICATE OBJECT FOUND"
-			break
-		fi
-	done &&
-	test "$found_duplicate_object" = 1
+	test_has_duplicate_object true
 '
 
 test_expect_success 'writing bitmaps via config can duplicate .keep objects' '
 	# build on $objsha1, $packsha1, and .keep state from previous
 	git -c repack.writebitmaps=true repack -Adl &&
-	test_when_finished "found_duplicate_object=" &&
-	for p in .git/objects/pack/*.idx
-	do
-		idx=$(basename $p)
-		test "pack-$packsha1.idx" = "$idx" && continue
-		if git verify-pack -v $p | egrep "^$objsha1"
-		then
-			found_duplicate_object=1
-			echo "DUPLICATE OBJECT FOUND"
-			break
-		fi
-	done &&
-	test "$found_duplicate_object" = 1
+	test_has_duplicate_object true
 '
 
 test_expect_success 'loose objects in alternate ODB are not repacked' '
@@ -100,16 +84,7 @@ test_expect_success 'loose objects in alternate ODB are not repacked' '
 	git commit -m commit_file3 &&
 	git repack -a -d -l &&
 	git prune-packed &&
-	for p in .git/objects/pack/*.idx
-	do
-		if git verify-pack -v $p | egrep "^$objsha1"
-		then
-			found_duplicate_object=1
-			echo "DUPLICATE OBJECT FOUND"
-			break
-		fi
-	done &&
-	test -z "$found_duplicate_object"
+	test_has_duplicate_object false
 '
 
 test_expect_success 'packed obs in alt ODB are repacked even when local repo is packless' '
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v5 24/26] t7700: replace egrep with grep
  2019-11-27 19:53       ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                           ` (22 preceding siblings ...)
  2019-11-27 19:53         ` [PATCH v5 23/26] t7700: consolidate code into test_has_duplicate_object() Denton Liu
@ 2019-11-27 19:53         ` Denton Liu
  2019-11-27 19:54         ` [PATCH v5 25/26] t7700: make references to SHA-1 generic Denton Liu
  2019-11-27 19:54         ` [PATCH v5 26/26] t7700: stop losing return codes of git commands Denton Liu
  25 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

The egrep expressions in this test suite were of the form `^$variable`.
Although egrep works just fine, it's overkill since we're not using any
extended regex. Replace egrep invocations with grep so that we aren't
swatting flies with a sledgehammer.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7700-repack.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index 5bbed02fe5..2493cc4e9b 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -30,7 +30,7 @@ test_has_duplicate_object () {
 		idx=$(basename $p)
 		test "pack-$packsha1.idx" = "$idx" && continue
 		git verify-pack -v $p >packlist || return $?
-		if egrep "^$objsha1" packlist
+		if grep "^$objsha1" packlist
 		then
 			found_duplicate_object=true
 			echo "DUPLICATE OBJECT FOUND"
@@ -135,7 +135,7 @@ test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
 	rm -f .git/objects/pack/* &&
 	mv pack-* .git/objects/pack/ &&
 	test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
-		egrep "^$csha1 " | sort | uniq | wc -l) &&
+		grep "^$csha1 " | sort | uniq | wc -l) &&
 	echo >.git/objects/info/alternates &&
 	test_must_fail git show $csha1
 '
@@ -152,7 +152,7 @@ test_expect_success 'local packed unreachable obs that exist in alternate ODB ar
 	rm -f .git/objects/pack/* &&
 	mv pack-* .git/objects/pack/ &&
 	test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
-		egrep "^$csha1 " | sort | uniq | wc -l) &&
+		grep "^$csha1 " | sort | uniq | wc -l) &&
 	echo >.git/objects/info/alternates &&
 	test_must_fail git show $csha1
 '
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v5 25/26] t7700: make references to SHA-1 generic
  2019-11-27 19:53       ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                           ` (23 preceding siblings ...)
  2019-11-27 19:53         ` [PATCH v5 24/26] t7700: replace egrep with grep Denton Liu
@ 2019-11-27 19:54         ` Denton Liu
  2019-11-27 19:54         ` [PATCH v5 26/26] t7700: stop losing return codes of git commands Denton Liu
  25 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-11-27 19:54 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

Make the test more hash-agnostic by renaming variables from "sha1" to
some variation of "oid" or "packid". Also, replace the regex,
`[0-9a-f]\{40\}` with `$OID_REGEX`.

A better name for "incrpackid" (incremental pack-id) might have been
just "packid". However, later in the test suite, we have other uses of
"packid". Although the scopes of these variables don't conflict, a
future developer may think that commit_and_pack() and
test_has_duplicate_object() are semantically related somehow since they
share the same variable name. Give them distinct names so that it's
clear these uses are unrelated.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7700-repack.sh | 38 +++++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index 2493cc4e9b..1edb21bf93 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -6,31 +6,31 @@ test_description='git repack works correctly'
 
 commit_and_pack () {
 	test_commit "$@" 1>&2 &&
-	SHA1=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) &&
-	echo pack-${SHA1}.pack
+	incrpackid=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) &&
+	echo pack-${incrpackid}.pack
 }
 
 test_no_missing_in_packs () {
 	myidx=$(ls -1 .git/objects/pack/*.idx) &&
 	test_path_is_file "$myidx" &&
 	git verify-pack -v alt_objects/pack/*.idx >orig.raw &&
-	grep "^[0-9a-f]\{40\}" orig.raw | cut -d" " -f1 | sort >orig &&
+	grep "^$OID_REGEX" orig.raw | cut -d" " -f1 | sort >orig &&
 	git verify-pack -v $myidx >dest.raw &&
 	cut -d" " -f1 dest.raw | sort >dest &&
 	comm -23 orig dest >missing &&
 	test_must_be_empty missing
 }
 
-# we expect $packsha1 and $objsha1 to be defined
+# we expect $packid and $oid to be defined
 test_has_duplicate_object () {
 	want_duplicate_object="$1"
 	found_duplicate_object=false
 	for p in .git/objects/pack/*.idx
 	do
 		idx=$(basename $p)
-		test "pack-$packsha1.idx" = "$idx" && continue
+		test "pack-$packid.idx" = "$idx" && continue
 		git verify-pack -v $p >packlist || return $?
-		if grep "^$objsha1" packlist
+		if grep "^$oid" packlist
 		then
 			found_duplicate_object=true
 			echo "DUPLICATE OBJECT FOUND"
@@ -51,11 +51,11 @@ test_expect_success 'objects in packs marked .keep are not repacked' '
 	git rev-list --objects --all | grep -v file2 |
 		git pack-objects pack &&
 	# The second pack will contain the excluded object
-	packsha1=$(git rev-list --objects --all | grep file2 |
+	packid=$(git rev-list --objects --all | grep file2 |
 		git pack-objects pack) &&
-	>pack-$packsha1.keep &&
-	objsha1=$(git verify-pack -v pack-$packsha1.idx | head -n 1 |
-		sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") &&
+	>pack-$packid.keep &&
+	oid=$(git verify-pack -v pack-$packid.idx | head -n 1 |
+		sed -e "s/^\($OID_REGEX\).*/\1/") &&
 	mv pack-* .git/objects/pack/ &&
 	git repack -A -d -l &&
 	git prune-packed &&
@@ -63,13 +63,13 @@ test_expect_success 'objects in packs marked .keep are not repacked' '
 '
 
 test_expect_success 'writing bitmaps via command-line can duplicate .keep objects' '
-	# build on $objsha1, $packsha1, and .keep state from previous
+	# build on $oid, $packid, and .keep state from previous
 	git repack -Adbl &&
 	test_has_duplicate_object true
 '
 
 test_expect_success 'writing bitmaps via config can duplicate .keep objects' '
-	# build on $objsha1, $packsha1, and .keep state from previous
+	# build on $oid, $packid, and .keep state from previous
 	git -c repack.writebitmaps=true repack -Adl &&
 	test_has_duplicate_object true
 '
@@ -78,7 +78,7 @@ test_expect_success 'loose objects in alternate ODB are not repacked' '
 	mkdir alt_objects &&
 	echo $(pwd)/alt_objects >.git/objects/info/alternates &&
 	echo content3 >file3 &&
-	objsha1=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) &&
+	oid=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) &&
 	git add file3 &&
 	test_tick &&
 	git commit -m commit_file3 &&
@@ -124,7 +124,7 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
 test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
 	rm -f alt_objects/pack/*.keep &&
 	mv .git/objects/pack/* alt_objects/pack/ &&
-	csha1=$(git rev-parse HEAD^{commit}) &&
+	coid=$(git rev-parse HEAD^{commit}) &&
 	git reset --hard HEAD^ &&
 	test_tick &&
 	git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all &&
@@ -135,14 +135,14 @@ test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
 	rm -f .git/objects/pack/* &&
 	mv pack-* .git/objects/pack/ &&
 	test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
-		grep "^$csha1 " | sort | uniq | wc -l) &&
+		grep "^$coid " | sort | uniq | wc -l) &&
 	echo >.git/objects/info/alternates &&
-	test_must_fail git show $csha1
+	test_must_fail git show $coid
 '
 
 test_expect_success 'local packed unreachable obs that exist in alternate ODB are not loosened' '
 	echo $(pwd)/alt_objects >.git/objects/info/alternates &&
-	echo "$csha1" | git pack-objects --non-empty --all --reflog pack &&
+	echo "$coid" | git pack-objects --non-empty --all --reflog pack &&
 	rm -f .git/objects/pack/* &&
 	mv pack-* .git/objects/pack/ &&
 	# The pack-objects call on the next line is equivalent to
@@ -152,9 +152,9 @@ test_expect_success 'local packed unreachable obs that exist in alternate ODB ar
 	rm -f .git/objects/pack/* &&
 	mv pack-* .git/objects/pack/ &&
 	test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
-		grep "^$csha1 " | sort | uniq | wc -l) &&
+		grep "^$coid " | sort | uniq | wc -l) &&
 	echo >.git/objects/info/alternates &&
-	test_must_fail git show $csha1
+	test_must_fail git show $coid
 '
 
 test_expect_success 'objects made unreachable by grafts only are kept' '
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* [PATCH v5 26/26] t7700: stop losing return codes of git commands
  2019-11-27 19:53       ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu
                           ` (24 preceding siblings ...)
  2019-11-27 19:54         ` [PATCH v5 25/26] t7700: make references to SHA-1 generic Denton Liu
@ 2019-11-27 19:54         ` Denton Liu
  2019-11-30 10:48           ` Danh Doan
  25 siblings, 1 reply; 169+ messages in thread
From: Denton Liu @ 2019-11-27 19:54 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King

In a pipe, only the return code of the last command is used. Thus, all
other commands will have their return codes masked. Rewrite pipes so
that there are no git commands upstream so that we will know if a
command fails.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7700-repack.sh | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index 1edb21bf93..d5cce7c06f 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -48,14 +48,13 @@ test_expect_success 'objects in packs marked .keep are not repacked' '
 	git commit -m initial_commit &&
 	# Create two packs
 	# The first pack will contain all of the objects except one
-	git rev-list --objects --all | grep -v file2 |
-		git pack-objects pack &&
+	git rev-list --objects --all >objs &&
+	grep -v file2 objs | git pack-objects pack &&
 	# The second pack will contain the excluded object
-	packid=$(git rev-list --objects --all | grep file2 |
-		git pack-objects pack) &&
+	packid=$(grep file2 objs | git pack-objects pack) &&
 	>pack-$packid.keep &&
-	oid=$(git verify-pack -v pack-$packid.idx | head -n 1 |
-		sed -e "s/^\($OID_REGEX\).*/\1/") &&
+	git verify-pack -v pack-$packid.idx >packlist &&
+	oid=$(head -n 1 packlist | sed -e "s/^\($OID_REGEX\).*/\1/") &&
 	mv pack-* .git/objects/pack/ &&
 	git repack -A -d -l &&
 	git prune-packed &&
@@ -134,8 +133,8 @@ test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
 	    --unpack-unreachable </dev/null pack &&
 	rm -f .git/objects/pack/* &&
 	mv pack-* .git/objects/pack/ &&
-	test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
-		grep "^$coid " | sort | uniq | wc -l) &&
+	git verify-pack -v -- .git/objects/pack/*.idx >packlist &&
+	! grep "^$coid " packlist &&
 	echo >.git/objects/info/alternates &&
 	test_must_fail git show $coid
 '
@@ -151,8 +150,8 @@ test_expect_success 'local packed unreachable obs that exist in alternate ODB ar
 	    --unpack-unreachable </dev/null pack &&
 	rm -f .git/objects/pack/* &&
 	mv pack-* .git/objects/pack/ &&
-	test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
-		grep "^$coid " | sort | uniq | wc -l) &&
+	git verify-pack -v -- .git/objects/pack/*.idx >packlist &&
+	! grep "^$coid " &&
 	echo >.git/objects/info/alternates &&
 	test_must_fail git show $coid
 '
-- 
2.24.0.504.g3cd56eb17d


^ permalink raw reply	[flat|nested] 169+ messages in thread

* Re: [PATCH v5 22/26] t7700: consolidate code into test_no_missing_in_packs()
  2019-11-27 19:53         ` [PATCH v5 22/26] t7700: consolidate code into test_no_missing_in_packs() Denton Liu
@ 2019-11-29 21:39           ` Junio C Hamano
  2019-12-02 20:50             ` Denton Liu
  0 siblings, 1 reply; 169+ messages in thread
From: Junio C Hamano @ 2019-11-29 21:39 UTC (permalink / raw)
  To: Denton Liu; +Cc: Git Mailing List, Eric Sunshine, Jeff King

Denton Liu <liu.denton@gmail.com> writes:

> The code to test that objects were not missing from the packfile was
> duplicated many times. Extract the duplicated code into
> test_no_missing_in_packs() and use that instead.
>
> Refactor the resulting extraction so that if any git commands fail,
> their return codes are not silently lost.
>
> We were using sed to filter lines. Although not incorrect, this is
> exactly what grep is built for. Replace this invocation of sed with grep
> so that we use the correct tool for the job.

Well, 

    $ sed -n -e 's/required match/desired part of the line/p'

is much much more approirate than 

    $ grep -e "requred match" |
      extract desired part of the line

"grep" is better only if the original were

    $ sed -n -e '/required match/p'

but everybody would write it with grep to begin with ;-)

So, I dunno about this part of the conversion.

> Instead of verifying each file of `alt_objects/pack/*.idx` individually
> in a for-loop, batch them together into one verification step.

Do you mean this one?

	git verify-pack -v alt_objects/pack/*.idx

where we may pass 1 or more .idx file to the command?  At first my
reading was interrupted by a "Huh?", but that does look good.  We'd
need to be a bit careful to make sure that we have at least 1 .idx
file, as the shell will happily feed a file whose name is "*.idx",
which verify-pack would be unhappy about.

> The original testing construct was O(n^2): it used a grep in a loop to
> test whether any objects were missing in the packfile. Rewrite this to
> sort the files then use `comm -23` so that finding missing lines from
> the original file is done more efficiently.

OK.  If we an show measurable speedups, it would be great, but the
loop structure does look O(n^2) and unnecessary costly.

> +test_no_missing_in_packs () {
> +	myidx=$(ls -1 .git/objects/pack/*.idx) &&
> +	test_path_is_file "$myidx" &&

If there are 2 or more .idx files, or if there is none, $myidx would
hopefully be a concatenation of these filenames or a string that
ends with asterisk-dot-idx and would fail path_is_file.  Sounds OK.

Ah, I do not have to review this part---these are repeated patterns
in the original.

> +	git verify-pack -v alt_objects/pack/*.idx >orig.raw &&
> +	grep "^[0-9a-f]\{40\}" orig.raw | cut -d" " -f1 | sort >orig &&

If output from 'grep' can be used as-is, it is worth doing, but if
you have to pipe it to cut, the original that used sed to filter and
edit the line would probably be a better way to write it.

> +	git verify-pack -v $myidx >dest.raw &&

This part does not quote $myidx" (inherited from the original); it
probably is OK, as any potentially problematic value in $myidx would
have been caught as an error much earlier in this test.


^ permalink raw reply	[flat|nested] 169+ messages in thread

* Re: [PATCH v5 26/26] t7700: stop losing return codes of git commands
  2019-11-27 19:54         ` [PATCH v5 26/26] t7700: stop losing return codes of git commands Denton Liu
@ 2019-11-30 10:48           ` Danh Doan
  2019-11-30 11:31             ` Eric Sunshine
  0 siblings, 1 reply; 169+ messages in thread
From: Danh Doan @ 2019-11-30 10:48 UTC (permalink / raw)
  To: Denton Liu; +Cc: Git Mailing List, Eric Sunshine, Junio C Hamano, Jeff King


Hi Denton,

On 2019-11-27 11:54:04-0800, Denton Liu <liu.denton@gmail.com> wrote:
> -	test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
> -		grep "^$coid " | sort | uniq | wc -l) &&
> +	git verify-pack -v -- .git/objects/pack/*.idx >packlist &&
> +	! grep "^$coid " packlist &&

I think we want to use test_must_fail instead of !

>  	echo >.git/objects/info/alternates &&
>  	test_must_fail git show $coid
>  '
> @@ -151,8 +150,8 @@ test_expect_success 'local packed unreachable obs that exist in alternate ODB ar
>  	    --unpack-unreachable </dev/null pack &&
>  	rm -f .git/objects/pack/* &&
>  	mv pack-* .git/objects/pack/ &&
> -	test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
> -		grep "^$coid " | sort | uniq | wc -l) &&
> +	git verify-pack -v -- .git/objects/pack/*.idx >packlist &&
> +	! grep "^$coid " &&

ditto

-- 
Danh

^ permalink raw reply	[flat|nested] 169+ messages in thread

* Re: [PATCH v5 26/26] t7700: stop losing return codes of git commands
  2019-11-30 10:48           ` Danh Doan
@ 2019-11-30 11:31             ` Eric Sunshine
  2019-11-30 17:00               ` Junio C Hamano
  0 siblings, 1 reply; 169+ messages in thread
From: Eric Sunshine @ 2019-11-30 11:31 UTC (permalink / raw)
  To: Danh Doan; +Cc: Denton Liu, Git Mailing List, Junio C Hamano, Jeff King

On Sat, Nov 30, 2019 at 5:48 AM Danh Doan <congdanhqx@gmail.com> wrote:
> On 2019-11-27 11:54:04-0800, Denton Liu <liu.denton@gmail.com> wrote:
> > +   ! grep "^$coid " packlist &&
>
> I think we want to use test_must_fail instead of !

test_must_fail() is intended only for use with 'git' commands; "!"
should be used otherwise. Quoting from t/README:

    Don't use '! git cmd' when you want to make sure the git command
    exits with failure in a controlled way by calling "die()".  Instead,
    use 'test_must_fail git cmd'.  This will signal a failure if git
    dies in an unexpected way (e.g. segfault).

    On the other hand, don't use test_must_fail for running regular
    platform commands; just use '! cmd'.  We are not in the business
    of verifying that the world given to us sanely works.

So, Denton's use of "!" here is correct.

^ permalink raw reply	[flat|nested] 169+ messages in thread

* Re: [PATCH v5 26/26] t7700: stop losing return codes of git commands
  2019-11-30 11:31             ` Eric Sunshine
@ 2019-11-30 17:00               ` Junio C Hamano
  2019-12-04 12:59                 ` t: remove inappropriate uses of test_must_fail(), was " Denton Liu
  0 siblings, 1 reply; 169+ messages in thread
From: Junio C Hamano @ 2019-11-30 17:00 UTC (permalink / raw)
  To: Eric Sunshine; +Cc: Danh Doan, Denton Liu, Git Mailing List, Jeff King

Eric Sunshine <sunshine@sunshineco.com> writes:

> On Sat, Nov 30, 2019 at 5:48 AM Danh Doan <congdanhqx@gmail.com> wrote:
>> On 2019-11-27 11:54:04-0800, Denton Liu <liu.denton@gmail.com> wrote:
>> > +   ! grep "^$coid " packlist &&
>>
>> I think we want to use test_must_fail instead of !
>
> test_must_fail() is intended only for use with 'git' commands; "!"
> should be used otherwise. Quoting from t/README:
>
>     Don't use '! git cmd' when you want to make sure the git command
>     exits with failure in a controlled way by calling "die()".  Instead,
>     use 'test_must_fail git cmd'.  This will signal a failure if git
>     dies in an unexpected way (e.g. segfault).
>
>     On the other hand, don't use test_must_fail for running regular
>     platform commands; just use '! cmd'.  We are not in the business
>     of verifying that the world given to us sanely works.
>
> So, Denton's use of "!" here is correct.

I wonder we can make the framework a bit more self-documenting to
avoid having to waste time on discovering potential issues and
explaining why it is not an issue, like this exchange.

Some ideas:

 * Perhaps test_must_fail is not descriptive enough that it should
   apply only to git command invocation.  Would it make it more
   obvious to rename it to say git_must_fail?  That would also make
   it unnecessary to give this rather unfortunate comment in
   test-lib-functions.sh:

   # This is not among top-level (test_expect_success | test_expect_failure)
   # but is a prefix that can be used in the test script, like:
   #
   #	test_expect_success 'complain and die' '
   #           do something &&
   #           do something else &&
   #	    test_must_fail git checkout ../outerspace
   #	'
   #

 * If it is too much trouble to rename it, perhaps test_must_fail
   can be documented better up there?

   diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
   index b299ecc326..052d88c5da 100644
   --- a/t/test-lib-functions.sh
   +++ b/t/test-lib-functions.sh
   @@ -817,6 +817,13 @@ list_contains () {
    #     Multiple signals can be specified as a comma separated list.
    #     Currently recognized signal names are: sigpipe, success.
    #     (Don't use 'success', use 'test_might_fail' instead.)
   +#
   +# Do not use this to run anything but "git".  We are not in the business
   +# of vetting system supplied commands---IOW this is wrong:
   +#
   +#    test_must_fail grep pattern output
   +#
   +# Just use '!' instead.

    test_must_fail () {
           case "$1" in

 * Or perhaps we can detect its use on anything that is not "git"
   automatically?  This is merely to illustrate the idea (the
   exemption of "env" shown here is too broad for production use)

   diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
   index b299ecc326..7ab113cd50 100644
   --- a/t/test-lib-functions.sh
   +++ b/t/test-lib-functions.sh
   @@ -828,6 +828,10 @@ test_must_fail () {
                   _test_ok=
                   ;;
           esac
   +	case "$1" in
   +	git|test-tool|env) ;;
   +	*) echo >&7 "warning: test_must_fail $*???" ;;
   +	esac
           "$@" 2>&7
           exit_code=$?
           if test $exit_code -eq 0 && ! list_contains "$_test_ok" success

Hmm?

^ permalink raw reply	[flat|nested] 169+ messages in thread

* Re: [PATCH v5 22/26] t7700: consolidate code into test_no_missing_in_packs()
  2019-11-29 21:39           ` Junio C Hamano
@ 2019-12-02 20:50             ` Denton Liu
  2019-12-02 22:53               ` Junio C Hamano
  0 siblings, 1 reply; 169+ messages in thread
From: Denton Liu @ 2019-12-02 20:50 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git Mailing List, Eric Sunshine, Jeff King

Hi Junio,

On Fri, Nov 29, 2019 at 01:39:30PM -0800, Junio C Hamano wrote:
> Denton Liu <liu.denton@gmail.com> writes:
> 
> > The code to test that objects were not missing from the packfile was
> > duplicated many times. Extract the duplicated code into
> > test_no_missing_in_packs() and use that instead.
> >
> > Refactor the resulting extraction so that if any git commands fail,
> > their return codes are not silently lost.
> >
> > We were using sed to filter lines. Although not incorrect, this is
> > exactly what grep is built for. Replace this invocation of sed with grep
> > so that we use the correct tool for the job.
> 
> Well, 
> 
>     $ sed -n -e 's/required match/desired part of the line/p'
> 
> is much much more approirate than 
> 
>     $ grep -e "requred match" |
>       extract desired part of the line
> 
> "grep" is better only if the original were
> 
>     $ sed -n -e '/required match/p'
> 
> but everybody would write it with grep to begin with ;-)

This was what I was intending. It was originally written like the above
and it made sense to convert it to use grep. I guess "filter lines" in
my commit message is a little bit vague. Could we change this to "filter
matching lines" perhaps?

> 
> So, I dunno about this part of the conversion.
> 
> > Instead of verifying each file of `alt_objects/pack/*.idx` individually
> > in a for-loop, batch them together into one verification step.
> 
> Do you mean this one?
> 
> 	git verify-pack -v alt_objects/pack/*.idx
> 
> where we may pass 1 or more .idx file to the command?  At first my
> reading was interrupted by a "Huh?", but that does look good.  We'd
> need to be a bit careful to make sure that we have at least 1 .idx
> file, as the shell will happily feed a file whose name is "*.idx",
> which verify-pack would be unhappy about.
> 
> > The original testing construct was O(n^2): it used a grep in a loop to
> > test whether any objects were missing in the packfile. Rewrite this to
> > sort the files then use `comm -23` so that finding missing lines from
> > the original file is done more efficiently.
> 
> OK.  If we an show measurable speedups, it would be great, but the
> loop structure does look O(n^2) and unnecessary costly.
> 
> > +test_no_missing_in_packs () {
> > +	myidx=$(ls -1 .git/objects/pack/*.idx) &&
> > +	test_path_is_file "$myidx" &&
> 
> If there are 2 or more .idx files, or if there is none, $myidx would
> hopefully be a concatenation of these filenames or a string that
> ends with asterisk-dot-idx and would fail path_is_file.  Sounds OK.
> 
> Ah, I do not have to review this part---these are repeated patterns
> in the original.
> 
> > +	git verify-pack -v alt_objects/pack/*.idx >orig.raw &&
> > +	grep "^[0-9a-f]\{40\}" orig.raw | cut -d" " -f1 | sort >orig &&
> 
> If output from 'grep' can be used as-is, it is worth doing, but if
> you have to pipe it to cut, the original that used sed to filter and
> edit the line would probably be a better way to write it.

The original sed actually only filtered the line; no editing done. The
cut invocation was a consequence of using comm. Previously, in the while
loop, we would separate the line into `sha1` and `rest` components and
only match using the `sha1`. Since we use comm now, we have to use cut
to grab the sha1 and omit the rest of the line.

We could rewrite it with sed like this:

	sed -n -e "/^[0-9a-f]\{40\}/s/^\($[0-9a-f]\{40\}\).*/\1/" orig.raw

but I believe that breaking it into grep and cut makes the intent much
more clear. 

What do you think?

(By the way, if I were to reroll this series, should I keep sending out
the entire patchset? It feels very noisy to send out 20-something emails
every reroll when I'm just making a small one or two line change.)

Thanks,

Denton

> 
> > +	git verify-pack -v $myidx >dest.raw &&
> 
> This part does not quote $myidx" (inherited from the original); it
> probably is OK, as any potentially problematic value in $myidx would
> have been caught as an error much earlier in this test.
> 

^ permalink raw reply	[flat|nested] 169+ messages in thread

* Re: [PATCH v5 22/26] t7700: consolidate code into test_no_missing_in_packs()
  2019-12-02 20:50             ` Denton Liu
@ 2019-12-02 22:53               ` Junio C Hamano
  2019-12-02 23:28                 ` Denton Liu
  0 siblings, 1 reply; 169+ messages in thread
From: Junio C Hamano @ 2019-12-02 22:53 UTC (permalink / raw)
  To: Denton Liu; +Cc: Git Mailing List, Eric Sunshine, Jeff King

Denton Liu <liu.denton@gmail.com> writes:

> Hi Junio,
> ...
>> "grep" is better only if the original were
>> 
>>     $ sed -n -e '/required match/p'
>> 
>> but everybody would write it with grep to begin with ;-)
>
> This was what I was intending. It was originally written like the above
> and it made sense to convert it to use grep. I guess "filter lines" in
> my commit message is a little bit vague. Could we change this to "filter
> matching lines" perhaps?

Ah, I see.  I somehow thought that some of the "sed" invocation in
the original version were doing "find lines and filter its
contents" (i.e. "-n -e 's/find/munge/p'"), but all three of them are
just "find lines" (i.e. "-n -e '/find/p'").  So I think the change
made by the patch is OK.

I think I was reacting to the output of "grep" being piped to "cut".
IOW, the original

	... | sed -n -e '/find/p' |
	while read sha1 garbage
	do
		... use sha1 ...

were rewritten to

	... >raw &&
	grep -e 'find' raw | cut -d" " -f1 >orig
	... use orig as a list of sha1s ...

But the "grep piped to cut" can be a single process

	... >raw &&
	sed -n -e 's/\(find\).*/\1/p' raw >orig
	... use orig as a list of sha1s ...

So in the tiniest picture, turning "sed -n -e /find/p" into "grep"
is not wrong per-se, but if you step back a bit and see a larger
picture, using "sed" a bit more effectively turns out to be still a
better rewrite.

... and I wrote the above before I read the remainder of your
response, where you considered which one is easier to read between
"grep piped to cut" and "sed" ;-)


> (By the way, if I were to reroll this series, should I keep sending out
> the entire patchset? It feels very noisy to send out 20-something emails
> every reroll when I'm just making a small one or two line change.)

Especially if it is near the end of the series, just a single step
is OK.  But is there anything that is glaringly wrong that needs a
reroll?  Or would it be "this is good enough, so let's have them
cook in 'next' and graduate to 'master'---further clean-up can be
done after all the dust settles"?  I have an impression that we
reached the latter by now.

Thanks.

^ permalink raw reply	[flat|nested] 169+ messages in thread

* Re: [PATCH v5 22/26] t7700: consolidate code into test_no_missing_in_packs()
  2019-12-02 22:53               ` Junio C Hamano
@ 2019-12-02 23:28                 ` Denton Liu
  2019-12-03 15:41                   ` Junio C Hamano
  0 siblings, 1 reply; 169+ messages in thread
From: Denton Liu @ 2019-12-02 23:28 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git Mailing List, Eric Sunshine, Jeff King

Hi Junio,

On Mon, Dec 02, 2019 at 02:53:09PM -0800, Junio C Hamano wrote:
> > (By the way, if I were to reroll this series, should I keep sending out
> > the entire patchset? It feels very noisy to send out 20-something emails
> > every reroll when I'm just making a small one or two line change.)
> 
> Especially if it is near the end of the series, just a single step
> is OK.  But is there anything that is glaringly wrong that needs a
> reroll?  Or would it be "this is good enough, so let's have them
> cook in 'next' and graduate to 'master'---further clean-up can be
> done after all the dust settles"?  I have an impression that we
> reached the latter by now.

Perhaps the log message could use some improvement to document the
discussion we had? I don't know if that's worth a reroll, though. Aside
from that, I agree that it's ready for 'next'.

> 
> Thanks.

^ permalink raw reply	[flat|nested] 169+ messages in thread

* Re: [PATCH v5 22/26] t7700: consolidate code into test_no_missing_in_packs()
  2019-12-02 23:28                 ` Denton Liu
@ 2019-12-03 15:41                   ` Junio C Hamano
  2019-12-04  7:24                     ` Denton Liu
  0 siblings, 1 reply; 169+ messages in thread
From: Junio C Hamano @ 2019-12-03 15:41 UTC (permalink / raw)
  To: Denton Liu; +Cc: Git Mailing List, Eric Sunshine, Jeff King

Denton Liu <liu.denton@gmail.com> writes:

>> Especially if it is near the end of the series, just a single step
>> is OK.  But is there anything that is glaringly wrong that needs a
>> reroll?  Or would it be "this is good enough, so let's have them
>> cook in 'next' and graduate to 'master'---further clean-up can be
>> done after all the dust settles"?  I have an impression that we
>> reached the latter by now.
>
> Perhaps the log message could use some improvement to document the
> discussion we had? I don't know if that's worth a reroll, though. Aside
> from that, I agree that it's ready for 'next'.

Sure, let's see what you have in mind.

Thanks for working on this.

^ permalink raw reply	[flat|nested] 169+ messages in thread

* Re: [PATCH v5 22/26] t7700: consolidate code into test_no_missing_in_packs()
  2019-12-03 15:41                   ` Junio C Hamano
@ 2019-12-04  7:24                     ` Denton Liu
  2019-12-04 18:13                       ` Junio C Hamano
  0 siblings, 1 reply; 169+ messages in thread
From: Denton Liu @ 2019-12-04  7:24 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git Mailing List, Eric Sunshine, Jeff King

Hi Junio,

On Tue, Dec 03, 2019 at 07:41:19AM -0800, Junio C Hamano wrote:
> Denton Liu <liu.denton@gmail.com> writes:
> 
> >> Especially if it is near the end of the series, just a single step
> >> is OK.  But is there anything that is glaringly wrong that needs a
> >> reroll?  Or would it be "this is good enough, so let's have them
> >> cook in 'next' and graduate to 'master'---further clean-up can be
> >> done after all the dust settles"?  I have an impression that we
> >> reached the latter by now.
> >
> > Perhaps the log message could use some improvement to document the
> > discussion we had? I don't know if that's worth a reroll, though. Aside
> > from that, I agree that it's ready for 'next'.
> 
> Sure, let's see what you have in mind.

Here's a complete replacement for the commit message:

	t7700: consolidate code into test_no_missing_in_packs()

	The code to test that objects were not missing from the packfile was
	duplicated many times. Extract the duplicated code into
	test_no_missing_in_packs() and use that instead.

	Refactor the resulting extraction so that if any git commands fail,
	their return codes are not silently lost.

	We were using sed to filter lines. Although not incorrect, this is
	exactly what grep is built for. Replace this invocation of sed with grep
	so that we use the correct tool for the job.

	Instead of verifying each file of `alt_objects/pack/*.idx` individually
	in a for-loop, batch them together into one verification step.

	The original testing construct was O(n^2): it used a grep in a loop to
	test whether any objects were missing in the packfile. Rewrite this to
	sort the files then use `comm -23` so that finding missing lines from
	the original file is done more efficiently.

	The result of this is that we end up with a `grep | cut | sort`
	pipeline. Previously, we were extracting the `sha1` as part of the
	`while read sha1 rest` loop. Since we removed the while-loop, we need to
	use `cut` to extract the `sha1` field. Note that we could have chosen to
	combine the `grep | cut` into a single `sed` invocation but we
	consciously leave it separate as it makes the intent more clear.

	While we're at it, add a space to `commit_and_pack ()` for style.

	Signed-off-by: Denton Liu <liu.denton@gmail.com>

The only change between this and the old commit message is the addition
of the "The result of this..." paragraph.

Thanks,

Denton

> 
> Thanks for working on this.

^ permalink raw reply	[flat|nested] 169+ messages in thread

* t: remove inappropriate uses of test_must_fail(), was Re: [PATCH v5 26/26] t7700: stop losing return codes of git commands
  2019-11-30 17:00               ` Junio C Hamano
@ 2019-12-04 12:59                 ` " Denton Liu
  0 siblings, 0 replies; 169+ messages in thread
From: Denton Liu @ 2019-12-04 12:59 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Eric Sunshine, Danh Doan, Git Mailing List, Jeff King

Hi all,

On Sat, Nov 30, 2019 at 09:00:08AM -0800, Junio C Hamano wrote:
>  * Or perhaps we can detect its use on anything that is not "git"
>    automatically?  This is merely to illustrate the idea (the
>    exemption of "env" shown here is too broad for production use)
> 
>    diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
>    index b299ecc326..7ab113cd50 100644
>    --- a/t/test-lib-functions.sh
>    +++ b/t/test-lib-functions.sh
>    @@ -828,6 +828,10 @@ test_must_fail () {
>                    _test_ok=
>                    ;;
>            esac
>    +	case "$1" in
>    +	git|test-tool|env) ;;
>    +	*) echo >&7 "warning: test_must_fail $*???" ;;
>    +	esac
>            "$@" 2>&7
>            exit_code=$?
>            if test $exit_code -eq 0 && ! list_contains "$_test_ok" success

I've been cooking a series that gets rid of inappropriate uses
test_must_fail() for a while now. As a finishing touch, I implemented
the idea Junio suggested above and it seems to be working well.

It's a pretty hefty series, weighing in at 46 patches. After the dust
settles on 'dl/test-cleanup' (once it gets merged to master), I'll
probably start sending out this test_must_fail() series around 10
patches at a time.

An advanced preview can be found here[1]. Or, if you'd like me to
privately mail you the series, I can do that too. Early comments would
be very appreciated.

Thanks,

Denton

[1]: https://github.com/Denton-L/git/commits/ready/cleanup-test-must-fail

^ permalink raw