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

[PATCH] submodule update: silence underlying fetch with "--quiet"

From
NCNicholas Clark <nick@ccl4.org>
Date
Apr 30, 2021, 09:59 UTC
Message-ID
<20210430095906.GG9170@etla.org>
Commands such as
    $ git submodule update --quiet --init --depth=1

involving shallow clones, call the shell function fetch_in_submodule, which in turn invokes git fetch. Pass the --quiet option onward there.

Signed-off-by: Nicholas Clark <nick@ccl4.org>
---
I tried to adopt the same approach as the previous commit that fixed a
--quiet bug, 3ad0401e9e (submodule update: silence underlying merge/rebase
with "--quiet", 2020-09-30)

I believe that the bugfix is correct but I struggled to create a concise regression test demonstrates the bug and the bug fix.

That commit is not the only fix of a --quiet bug, so I'm wondering if there are others still to find. I looked in git-submodule.sh and see many invocations of git commands in git-submodule.sh, most of which don't pass ${GIT_QUIET:+--quiet} onward, but I don't know git well enough to know which might matter (ie might generate output), and it feels like cargo-cult to add that code unthinkingly to every git command, so I didn't do this.

 git-submodule.sh            |  4 ++--
 t/t7406-submodule-update.sh | 24 ++++++++++++++++++++++++
 2 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/git-submodule.sh b/git-submodule.sh
index eb90f18229..4678378424 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -420,9 +420,9 @@ fetch_in_submodule () (
 	cd "$1" &&
 	if test $# -eq 3
 	then
-		echo "$3" | git fetch --stdin ${2:+"$2"}
+		echo "$3" | git fetch ${GIT_QUIET:+--quiet} --stdin ${2:+"$2"}
 	else
-		git fetch ${2:+"$2"}
+		git fetch ${GIT_QUIET:+--quiet} ${2:+"$2"}
 	fi
 )
 
diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index ff3ba5422e..f4f61fe554 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -1037,4 +1037,28 @@ test_expect_success 'submodule update --quiet passes quietness to merge/rebase'
 	)
 '
 
+test_expect_success 'submodule update --quiet passes quietness to fetch with a shallow clone' '
+	test_when_finished "rm -rf super4 super5 super6" &&
+	git clone . super4 &&
+	(cd super4 &&
+	 git submodule add --quiet file://"$TRASH_DIRECTORY"/submodule submodule3 &&
+	 git commit -am "setup submodule3"
+	) &&
+	(cd submodule &&
+	  test_commit line6 file
+	) &&
+	git clone super4 super5 &&
+	(cd super5 &&
+	 git submodule update --quiet --init --depth=1 submodule3 >out 2>err &&
+	 test_must_be_empty out &&
+	 test_must_be_empty err
+	) &&
+	git clone super4 super6 &&
+	(cd super6 &&
+	 git submodule update --init --depth=1 submodule3 >out 2>err &&
+	 test_file_not_empty out &&
+	 test_file_not_empty err
+	)
+'
+
 test_done
-- 
2.31.1
Message 1 of 1 in “submodule update: silence underlying fetch with "--quiet"”
  1. submodule update: silence underlying fetch with "--quiet"Nicholas Clark, Apr 30, 2021

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.