All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Jeff King" <peff@peff.net>, "Junio C Hamano" <gitster@pobox.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH] fetch: don't output non-errors on stderr
Date: Thu, 24 Jun 2010 22:34:41 +0000	[thread overview]
Message-ID: <1277418881-11286-1-git-send-email-avarab@gmail.com> (raw)
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

  reply	other threads:[~2010-06-24 22:35 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-25 18:06 Bugreport: Git responds with stderr instead of stdout Jack Desert
2010-04-25 18:10 ` Jacob Helwig
2010-04-25 18:24   ` Ævar Arnfjörð Bjarmason
2010-04-25 19:22     ` Jeff King
2010-04-25 19:32       ` Ævar Arnfjörð Bjarmason
2010-04-25 19:32         ` Jeff King
2010-06-12 16:52           ` Ævar Arnfjörð Bjarmason
2010-06-24 22:34             ` Ævar Arnfjörð Bjarmason [this message]
2010-06-25 13:30               ` [PATCH v2] fetch: don't output non-errors on stderr Ævar Arnfjörð Bjarmason
2010-06-25 17:25               ` [PATCH] " Junio C Hamano
2010-06-25 21:28                 ` Ævar Arnfjörð Bjarmason
2010-06-25 21:43                   ` Junio C Hamano
2010-06-26  6:13                     ` Jeff King
2010-06-26 12:14                       ` Ævar Arnfjörð Bjarmason
2010-06-26 13:40                         ` Tay Ray Chuan
2010-06-26 15:07                           ` Ævar Arnfjörð Bjarmason
2010-06-26 16:46                         ` Jeff King
2010-06-26 16:50                           ` Ævar Arnfjörð Bjarmason
2010-04-25 18:34   ` Bugreport: Git responds with stderr instead of stdout Jack Desert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1277418881-11286-1-git-send-email-avarab@gmail.com \
    --to=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.