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

[PATCH 07/10] submodule foreach: send messages to stderr

From
Stefan Beller <sbeller@google.com>
Date
Apr 30, 2016, 00:40 UTC
Message-ID
<1461976845-18228-8-git-send-email-sbeller@google.com>
In-Reply-To
<1461976845-18228-1-git-send-email-sbeller@google.com>

Reroute the output of stdout to stderr as it is just informative messages, not to be consumed by machines.

This should not regress any scripts that try to parse the current output, as the output is already internationalized and therefore unstable.

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 git-submodule.sh             |  2 +-
 t/t7407-submodule-foreach.sh | 35 ++++++++++++++++++++++-------------
 2 files changed, 23 insertions(+), 14 deletions(-)
diff --git a/git-submodule.sh b/git-submodule.sh
index 3f67f4e..80270db 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -341,7 +341,7 @@ cmd_foreach()
 		if test -e "$sm_path"/.git
 		then
 			displaypath=$(relative_path "$prefix$sm_path")
-			say "$(eval_gettext "Entering '\$displaypath'")"
+			say >&2 "$(eval_gettext "Entering '\$displaypath'")"
 			name=$(git submodule--helper name "$sm_path")
 			(
 				prefix="$prefix$sm_path/"
diff --git a/t/t7407-submodule-foreach.sh b/t/t7407-submodule-foreach.sh
index 6ba5daf..f9b979a 100755
--- a/t/t7407-submodule-foreach.sh
+++ b/t/t7407-submodule-foreach.sh
@@ -61,29 +61,36 @@ sub3sha1=$(cd super/sub3 && git rev-parse HEAD)
 
 pwd=$(pwd)
 
-cat > expect <<EOF
-Entering 'sub1'
+cat >expect <<EOF
 $pwd/clone-foo1-sub1-$sub1sha1
-Entering 'sub3'
 $pwd/clone-foo3-sub3-$sub3sha1
 EOF
 
+cat >expect2 <<EOF
+Entering 'sub1'
+Entering 'sub3'
+EOF
+
 test_expect_success 'test basic "submodule foreach" usage' '
 	git clone super clone &&
 	(
 		cd clone &&
 		git submodule update --init -- sub1 sub3 &&
-		git submodule foreach "echo \$toplevel-\$name-\$path-\$sha1" > ../actual &&
+		git submodule foreach "echo \$toplevel-\$name-\$path-\$sha1" >../actual 2>../actual2 &&
 		git config foo.bar zar &&
 		git submodule foreach "git config --file \"\$toplevel/.git/config\" foo.bar"
 	) &&
-	test_i18ncmp expect actual
+	test_i18ncmp expect actual &&
+	test_i18ncmp expect2 actual2
 '
 
-cat >expect <<EOF
+cat >expect2 <<EOF
 Entering '../sub1'
-$pwd/clone-foo1-../sub1-$sub1sha1
 Entering '../sub3'
+EOF
+
+cat >expect <<EOF
+$pwd/clone-foo1-../sub1-$sub1sha1
 $pwd/clone-foo3-../sub3-$sub3sha1
 EOF
 
@@ -91,9 +98,10 @@ test_expect_success 'test "submodule foreach" from subdirectory' '
 	mkdir clone/sub &&
 	(
 		cd clone/sub &&
-		git submodule foreach "echo \$toplevel-\$name-\$sm_path-\$sha1" >../../actual
+		git submodule foreach "echo \$toplevel-\$name-\$sm_path-\$sha1" >../../actual 2>../../actual2
 	) &&
-	test_i18ncmp expect actual
+	test_i18ncmp expect actual &&
+	test_i18ncmp expect2 actual2
 '
 
 test_expect_success 'setup nested submodules' '
@@ -172,7 +180,7 @@ EOF
 test_expect_success 'test messages from "foreach --recursive"' '
 	(
 		cd clone2 &&
-		git submodule foreach --recursive "true" > ../actual
+		git submodule foreach --recursive "true" 2>../actual
 	) &&
 	test_i18ncmp expect actual
 '
@@ -192,7 +200,7 @@ test_expect_success 'test messages from "foreach --recursive" from subdirectory'
 		cd clone2 &&
 		mkdir untracked &&
 		cd untracked &&
-		git submodule foreach --recursive >../../actual
+		git submodule foreach --recursive 2>../../actual
 	) &&
 	test_i18ncmp expect actual
 '
@@ -210,9 +218,10 @@ EOF
 test_expect_success 'test "foreach --quiet --recursive"' '
 	(
 		cd clone2 &&
-		git submodule foreach -q --recursive "echo \$name-\$path" > ../actual
+		git submodule foreach -q --recursive "echo \$name-\$path" >../actual 2> ../actual2
 	) &&
-	test_cmp expect actual
+	test_cmp expect actual &&
+	test_must_be_empty actual2
 '
 
 test_expect_success 'use "update --recursive" to checkout all submodules' '
-- 
2.8.0.32.g71f8beb.dirty
Previous: Junio C HamanoNext: Stefan Beller
Message 14 of 20 in “submodule output patches”
  1. 00/10 submodule output patchesStefan Beller, Apr 30, 2016
  2. 01/10 submodule deinit test: fix broken && chain in subshellStefan Beller, Apr 30, 2016
  3. 02/10 submodule deinit: lose requirement for giving '.'Stefan Beller, Apr 30, 2016
  4. 03/10 submodule init: redirect stdout to stderrStefan Beller, Apr 30, 2016
  5. 04/10 shell helpers usage: always send help to stderrStefan Beller, Apr 30, 2016
  6. Junio C HamanoMay 2, 2016
  7. Stefan BellerMay 2, 2016
  8. Junio C HamanoMay 3, 2016
  9. Junio C HamanoMay 3, 2016
  10. 05/10 submodule add: send messages to stderrStefan Beller, Apr 30, 2016
  11. Junio C HamanoMay 2, 2016
  12. 06/10 submodule deinit: send messages to stderrStefan Beller, Apr 30, 2016
  13. Junio C HamanoMay 2, 2016
  14. 07/10 submodule foreach: send messages to stderrStefan Beller, Apr 30, 2016
  15. 08/10 submodule update: send messages to stderrStefan Beller, Apr 30, 2016
  16. 09/10 submodule sync: send messages to stderrStefan Beller, Apr 30, 2016
  17. 10/10 submodule deinit: complain when given a file instead of a submoduleStefan Beller, Apr 30, 2016
  18. Per CederqvistMay 2, 2016
  19. Stefan BellerMay 2, 2016
  20. Stefan BellerMay 2, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.