# [PATCH 2/4] git-push: squelch advice message if in --porcelain mode

6 messages from 2010-02-09 to 2010-02-11. Participants: Larry D'Anna, Tay Ray Chuan, Junio C Hamano.
Thread: https://gitlist.dev/t/22579

## Larry D'Anna, 2010-02-09 05:53

Subject: [PATCH 1/4] git-push: fix an error message so it goes to stderr
Message-ID: <1d1ce7e0ad28fd0cad8d9d7bfeda04ba58be36d4.1265694627.git.larry@elder-gods.org>
URL: https://gitlist.dev/e/1d1ce7e0ad28fd0cad8d9d7bfeda04ba58be36d4.1265694627.git.larry%40elder-gods.org
In-Reply-To: <20100209054820.GA30907@cthulhu>

```
These sort of messages typically go to the standard error.

Signed-off-by: Larry D'Anna <larry@elder-gods.org>
---
 builtin-push.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/builtin-push.c b/builtin-push.c
index 5633f0a..0a27072 100644
--- a/builtin-push.c
+++ b/builtin-push.c
@@ -124,9 +124,9 @@ static int push_with_options(struct transport *transport, int flags)
 		return 0;
 
 	if (nonfastforward && advice_push_nonfastforward) {
-		printf("To prevent you from losing history, non-fast-forward updates were rejected\n"
-		       "Merge the remote changes before pushing again.  See the 'Note about\n"
-		       "fast-forwards' section of 'git push --help' for details.\n");
+		fprintf(stderr, "To prevent you from losing history, non-fast-forward updates were rejected\n"
+				"Merge the remote changes before pushing again.  See the 'Note about\n"
+				"fast-forwards' section of 'git push --help' for details.\n");
 	}
 
 	return 1;
-- 
1.7.0.rc1.33.g07cf0f.dirty

```

## Larry D'Anna, 2010-02-09 05:54

Subject: [PATCH 2/4] git-push: squelch advice message if in --porcelain mode
Message-ID: <82ed08a77b08dd046be932ad4c08f65136c22c29.1265694627.git.larry@elder-gods.org>
URL: https://gitlist.dev/e/82ed08a77b08dd046be932ad4c08f65136c22c29.1265694627.git.larry%40elder-gods.org
In-Reply-To: <1d1ce7e0ad28fd0cad8d9d7bfeda04ba58be36d4.1265694627.git.larry@elder-gods.org>

```
By default, git-push may give the user a verbose advice message if a ref is
rejected for not being a fast-forward.  This patch squelches that message for
--porcelain mode.

Signed-off-by: Larry D'Anna <larry@elder-gods.org>
---
 builtin-push.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/builtin-push.c b/builtin-push.c
index 0a27072..aacba45 100644
--- a/builtin-push.c
+++ b/builtin-push.c
@@ -226,6 +226,11 @@ int cmd_push(int argc, const char **argv, const char *prefix)
 	git_config(git_default_config, NULL);
 	argc = parse_options(argc, argv, prefix, options, push_usage, 0);
 
+	if (flags & TRANSPORT_PUSH_PORCELAIN) {
+		/* Do not give advice messages to Porcelain scripts */
+		advice_push_nonfastforward = 0;
+	}
+
 	if (deleterefs && (tags || (flags & (TRANSPORT_PUSH_ALL | TRANSPORT_PUSH_MIRROR))))
 		die("--delete is incompatible with --all, --mirror and --tags");
 	if (deleterefs && argc < 2)
-- 
1.7.0.rc1.33.g07cf0f.dirty

```

## Larry D'Anna, 2010-02-09 05:54

Subject: [PATCH 3/4] git-push: send "To <remoteurl>" messages to the standard output in --porcelain mode
Message-ID: <45357037fd8f928759c9e9064736c62e793b84be.1265694627.git.larry@elder-gods.org>
URL: https://gitlist.dev/e/45357037fd8f928759c9e9064736c62e793b84be.1265694627.git.larry%40elder-gods.org
In-Reply-To: <1d1ce7e0ad28fd0cad8d9d7bfeda04ba58be36d4.1265694627.git.larry@elder-gods.org>

```
git-push prints the line "To <remoteurl>" before above each of the ref status
lines.  In --porcelain mode, these "To <remoteurl>" lines go to the standard
error, but the ref status lines go to the standard output.  This makes it
difficult for the process reading standard output to know which ref status lines
correspond to which remote.  This patch sends the "To <remoteurl>" lines to the
the standard output instead.

Signed-off-by: Larry D'Anna <larry@elder-gods.org>
---
 transport.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/transport.c b/transport.c
index 3846aac..fb653c6 100644
--- a/transport.c
+++ b/transport.c
@@ -675,7 +675,7 @@ static void print_ok_ref_status(struct ref *ref, int porcelain)
 static int print_one_push_status(struct ref *ref, const char *dest, int count, int porcelain)
 {
 	if (!count)
-		fprintf(stderr, "To %s\n", dest);
+		fprintf(porcelain ? stdout : stderr, "To %s\n", dest);
 
 	switch(ref->status) {
 	case REF_STATUS_NONE:
-- 
1.7.0.rc1.33.g07cf0f.dirty

```

## Larry D'Anna, 2010-02-09 05:54

Subject: [PATCH 4/4] git-push: make git push --dry-run --porcelain exit with status 0 even if updates will be rejected
Message-ID: <d19f6773a0b44d4ec07738727dc474a354c6236d.1265694627.git.larry@elder-gods.org>
URL: https://gitlist.dev/e/d19f6773a0b44d4ec07738727dc474a354c6236d.1265694627.git.larry%40elder-gods.org
In-Reply-To: <1d1ce7e0ad28fd0cad8d9d7bfeda04ba58be36d4.1265694627.git.larry@elder-gods.org>

```
The script calling git push --dry-run --porcelain can see clearly from the
output that the updates will be rejected.  However, it will probably need to
distinguish this condition from the push failing for other reasons, such as the
remote not being reachable.

Signed-off-by: Larry D'Anna <larry@elder-gods.org>
---
 builtin-send-pack.c |    4 ++++
 send-pack.h         |    1 +
 transport.c         |    3 ++-
 3 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/builtin-send-pack.c b/builtin-send-pack.c
index 76c7206..358f5e1 100644
--- a/builtin-send-pack.c
+++ b/builtin-send-pack.c
@@ -476,6 +476,10 @@ int send_pack(struct send_pack_args *args,
 
 	if (ret < 0)
 		return ret;
+
+	if (args->porcelain && args->dry_run)
+		return 0;
+
 	for (ref = remote_refs; ref; ref = ref->next) {
 		switch (ref->status) {
 		case REF_STATUS_NONE:
diff --git a/send-pack.h b/send-pack.h
index 28141ac..60b4ba6 100644
--- a/send-pack.h
+++ b/send-pack.h
@@ -4,6 +4,7 @@
 struct send_pack_args {
 	unsigned verbose:1,
 		quiet:1,
+		porcelain:1,
 		send_mirror:1,
 		force_update:1,
 		use_thin_pack:1,
diff --git a/transport.c b/transport.c
index fb653c6..0edcc16 100644
--- a/transport.c
+++ b/transport.c
@@ -791,6 +791,7 @@ static int git_transport_push(struct transport *transport, struct ref *remote_re
 	args.verbose = !!(flags & TRANSPORT_PUSH_VERBOSE);
 	args.quiet = !!(flags & TRANSPORT_PUSH_QUIET);
 	args.dry_run = !!(flags & TRANSPORT_PUSH_DRY_RUN);
+	args.porcelain = !!(flags & TRANSPORT_PUSH_PORCELAIN);
 
 	ret = send_pack(&args, data->fd, data->conn, remote_refs,
 			&data->extra_have);
@@ -1052,7 +1053,7 @@ int transport_push(struct transport *transport,
 			flags & TRANSPORT_PUSH_FORCE);
 
 		ret = transport->push_refs(transport, remote_refs, flags);
-		err = push_had_errors(remote_refs);
+		err = (pretend && porcelain) ? 0 : push_had_errors(remote_refs);
 
 		ret |= err;
 
-- 
1.7.0.rc1.33.g07cf0f.dirty

```

## Tay Ray Chuan, 2010-02-11 22:54

Subject: Re: [PATCH 3/4] git-push: send "To <remoteurl>" messages to the standard output in --porcelain mode
Message-ID: <be6fef0d1002111454w10ad965ej72699d1e185d2a9f@mail.gmail.com>
URL: https://gitlist.dev/e/be6fef0d1002111454w10ad965ej72699d1e185d2a9f%40mail.gmail.com
In-Reply-To: <45357037fd8f928759c9e9064736c62e793b84be.1265694627.git.larry@elder-gods.org>

```
Hi,

On Tue, Feb 9, 2010 at 1:54 PM, Larry D'Anna <larry@elder-gods.org> wrote:
> diff --git a/transport.c b/transport.c
> index 3846aac..fb653c6 100644
> --- a/transport.c
> +++ b/transport.c
> @@ -675,7 +675,7 @@ static void print_ok_ref_status(struct ref *ref, int porcelain)
>  static int print_one_push_status(struct ref *ref, const char *dest, int count, int porcelain)
>  {
>        if (!count)
> -               fprintf(stderr, "To %s\n", dest);
> +               fprintf(porcelain ? stdout : stderr, "To %s\n", dest);
>
>        switch(ref->status) {
>        case REF_STATUS_NONE:

just to check - are debug and user-specific messages (like advice and
info) to be sent, by convention/design/force-of-habit, to stderr? Are
those the "cruft" that has been referred to in other threads?

If that's the case, then perhaps the "To: <destination>" lines should
be sent to both stdout and stderr - stdout, for porcelain scripts as a
"header", and stderr, to help the user make sense of any errors that
occur ("oh, these errors were triggered when pushing to so-and-so
remote").

-- 
Cheers,
Ray Chuan

```

## Junio C Hamano, 2010-02-11 23:19

Subject: Re: [PATCH 3/4] git-push: send "To <remoteurl>" messages to the standard output in --porcelain mode
Message-ID: <7veikrs6m1.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7veikrs6m1.fsf%40alter.siamese.dyndns.org
In-Reply-To: <be6fef0d1002111454w10ad965ej72699d1e185d2a9f@mail.gmail.com>

```
Tay Ray Chuan <rctay89@gmail.com> writes:

> If that's the case, then perhaps the "To: <destination>" lines should
> be sent to both stdout and stderr - stdout, for porcelain scripts as a
> "header", and stderr, to help the user make sense of any errors that
> occur ("oh, these errors were triggered when pushing to so-and-so
> remote").

Under --porcelain, to show or not to show is under control of the calling
script.  Not sending it to standard error stream doesn't cause any harm,
as the calling script can choose to echo it out to its standard error (or
standard output).

```
