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

[PATCH] fetch: don't output non-errors on stderr

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Jun 24, 2010, 22:34 UTC
Message-ID
<1277418881-11286-1-git-send-email-avarab@gmail.com>
In-Reply-To
<AANLkTingtgeWuTrocesTIhTPsVz4dfU8CbwZF1TEl6AI@mail.gmail.com>

Change git-fetch to only print to stderr if it has encountered an error.

A normal branch update (like "* branch HEAD -> FETCH_HEAD") is no longer output to stderr but on stdout. Genuine errors (like "[rejected]" messages) still go to stderr.

With this change I can run a cron script I've been developing (http://github.com/avar/github-backup) without redirecting stderr to /dev/null.

Before the change error messages were drowned out by git-fetch's non-error update notices, which didn't need my attention.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
On Sat, Jun 12, 2010 at 16:52, Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:
> Shouldn't that fprintf() be called as:
>
>    fprintf((rc ? stderr : stdout), ...)

To answer my own question: Yes it should. This patch fixes git-fetch so that it doesn't taint stderr with non-error messages.

The small changes to the test suite that this requires is a testiment to how bad our test coverage is in this area. As far as I can see the error messages that update_local_ref can emit aren't being tested for. Fixing that is outside the scope of this patch, however.

 builtin/fetch.c         |    5 +++--
 t/t5521-pull-options.sh |   12 ++++++------
 2 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 5cb369c..116b322 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -397,13 +397,14 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
 				TRANSPORT_SUMMARY_WIDTH, *kind ? kind : "branch",
 				 REFCOL_WIDTH, *what ? what : "HEAD");
 		if (*note) {
+			FILE *fout = rc ? stderr : stdout;
 			if (verbosity >= 0 && !shown_url) {
-				fprintf(stderr, "From %.*s\n",
+				fprintf(fout, "From %.*s\n",
 						url_len, url);
 				shown_url = 1;
 			}
 			if (verbosity >= 0)
-				fprintf(stderr, " %s\n", note);
+				fprintf(fout, " %s\n", note);
 		}
 	}
 	free(url);
diff --git a/t/t5521-pull-options.sh b/t/t5521-pull-options.sh
index 1b06691..7ec36e7 100755
--- a/t/t5521-pull-options.sh
+++ b/t/t5521-pull-options.sh
@@ -23,16 +23,16 @@ test_expect_success 'git pull' '
 	mkdir cloned &&
 	(cd cloned && git init &&
 	git pull "../parent" >out 2>err &&
-	test -s err &&
-	test ! -s out)
+	test ! -s err &&
+	test -s out)
 '
 
 test_expect_success 'git pull -v' '
 	mkdir clonedv &&
 	(cd clonedv && git init &&
 	git pull -v "../parent" >out 2>err &&
-	test -s err &&
-	test ! -s out)
+	test ! -s err &&
+	test -s out)
 '
 
 test_expect_success 'git pull -v -q' '
@@ -47,8 +47,8 @@ test_expect_success 'git pull -q -v' '
 	mkdir clonedqv &&
 	(cd clonedqv && git init &&
 	git pull -q -v "../parent" >out 2>err &&
-	test ! -s out &&
-	test -s err)
+	test ! -s err &&
+	test -s out)
 '
 
 test_expect_success 'git pull --force' '
-- 
1.7.1.251.g92a7
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 8 of 19 in “Bugreport: Git responds with stderr instead of stdout”
  1. Jack DesertApr 25, 2010
  2. Jacob HelwigApr 25, 2010
  3. Ævar Arnfjörð BjarmasonApr 25, 2010
  4. Jeff KingApr 25, 2010
  5. Ævar Arnfjörð BjarmasonApr 25, 2010
  6. Jeff KingApr 25, 2010
  7. Ævar Arnfjörð BjarmasonJun 12, 2010
  8. fetch: don't output non-errors on stderrÆvar Arnfjörð Bjarmason, Jun 24, 2010
  9. fetch: don't output non-errors on stderrÆvar Arnfjörð Bjarmason, Jun 25, 2010
  10. Junio C HamanoJun 25, 2010
  11. Ævar Arnfjörð BjarmasonJun 25, 2010
  12. Junio C HamanoJun 25, 2010
  13. Jeff KingJun 26, 2010
  14. Ævar Arnfjörð BjarmasonJun 26, 2010
  15. Tay Ray ChuanJun 26, 2010
  16. Ævar Arnfjörð BjarmasonJun 26, 2010
  17. Jeff KingJun 26, 2010
  18. Ævar Arnfjörð BjarmasonJun 26, 2010
  19. Jack DesertApr 25, 2010

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.