# [PATCH v2 1/3] fix an error message in git-push so it goes to stderr

7 messages from 2010-02-05 to 2010-02-08. Participants: Larry D'Anna, Junio C Hamano, Tay Ray Chuan.
Thread: https://gitlist.dev/t/22536

## Larry D'Anna, 2010-02-05 20:49

Subject: [PATCH v2 0/3]
Message-ID: <cover.1265402797.git.larry@elder-gods.org>
URL: https://gitlist.dev/e/cover.1265402797.git.larry%40elder-gods.org
In-Reply-To: <7v1vgz5ta7.fsf@alter.siamese.dyndns.org>

```
I've fixed his series according to Jeff' and Junio's comments.

Larry D'Anna (3):
  fix an error message in git-push so it goes to stderr
  clean up some of the output from git push --porcelain
  make git push --dry-run --porcelain exit with status 0 even if
    updates will be rejected

 builtin-push.c      |    8 ++++----
 builtin-send-pack.c |    4 ++++
 send-pack.h         |    1 +
 transport.c         |   11 +++++++----
 4 files changed, 16 insertions(+), 8 deletions(-)

```

## Larry D'Anna, 2010-02-05 20:49

Subject: [PATCH v2 1/3] fix an error message in git-push so it goes to stderr
Message-ID: <c48cda45fbbc257debb737818137a5bd01a8bc5c.1265402797.git.larry@elder-gods.org>
URL: https://gitlist.dev/e/c48cda45fbbc257debb737818137a5bd01a8bc5c.1265402797.git.larry%40elder-gods.org
In-Reply-To: <cover.1265402797.git.larry@elder-gods.org>

```
Having it go to standard output interferes with git-push --porcelain.

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-05 20:49

Subject: [PATCH v2 2/3] clean up some of the output from git push --porcelain
Message-ID: <ec0db70b8166ee4093a5a2400cd592e4263db20b.1265402797.git.larry@elder-gods.org>
URL: https://gitlist.dev/e/ec0db70b8166ee4093a5a2400cd592e4263db20b.1265402797.git.larry%40elder-gods.org
In-Reply-To: <cover.1265402797.git.larry@elder-gods.org>

```
* don't emit long explanatory message about non-fast-forward updates.

* send "To dest" lines to standard out so whoever is reading standard out knows
  which ref updates went to which remotes.

* only send the "Everything up-to-date" line if verbose.

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

diff --git a/builtin-push.c b/builtin-push.c
index 0a27072..ff0b1c6 100644
--- a/builtin-push.c
+++ b/builtin-push.c
@@ -123,7 +123,7 @@ static int push_with_options(struct transport *transport, int flags)
 	if (!err)
 		return 0;
 
-	if (nonfastforward && advice_push_nonfastforward) {
+	if (!(flags & TRANSPORT_PUSH_PORCELAIN) && nonfastforward && advice_push_nonfastforward) {
 		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");
diff --git a/transport.c b/transport.c
index 3846aac..00d986c 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:
@@ -1070,7 +1070,7 @@ int transport_push(struct transport *transport,
 				update_tracking_ref(transport->remote, ref, verbose);
 		}
 
-		if (!quiet && !ret && !refs_pushed(remote_refs))
+		if (!quiet && (!porcelain || verbose) && !ret && !refs_pushed(remote_refs))
 			fprintf(stderr, "Everything up-to-date\n");
 		return ret;
 	}
-- 
1.7.0.rc1.33.g07cf0f.dirty

```

## Larry D'Anna, 2010-02-05 20:49

Subject: [PATCH v2 3/3] make git push --dry-run --porcelain exit with status 0 even if updates will be rejected
Message-ID: <cea7001d626116d76d885e24152d68cf41eca4dd.1265402797.git.larry@elder-gods.org>
URL: https://gitlist.dev/e/cea7001d626116d76d885e24152d68cf41eca4dd.1265402797.git.larry%40elder-gods.org
In-Reply-To: <cover.1265402797.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         |    7 +++++--
 3 files changed, 10 insertions(+), 2 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 00d986c..b41e1dc 100644
--- a/transport.c
+++ b/transport.c
@@ -558,8 +558,10 @@ static int fetch_refs_via_pack(struct transport *transport,
 	return (refs ? 0 : -1);
 }
 
-static int push_had_errors(struct ref *ref)
+static int push_had_errors(struct ref *ref, int flags)
 {
+	if (flags & TRANSPORT_PUSH_DRY_RUN && flags & TRANSPORT_PUSH_PORCELAIN)
+		return 0;
 	for (; ref; ref = ref->next) {
 		switch (ref->status) {
 		case REF_STATUS_NONE:
@@ -791,6 +793,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 +1055,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 = push_had_errors(remote_refs, flags);
 
 		ret |= err;
 
-- 
1.7.0.rc1.33.g07cf0f.dirty

```

## Junio C Hamano, 2010-02-05 21:07

Subject: Re: [PATCH v2 2/3] clean up some of the output from git push --porcelain
Message-ID: <7vpr4j1jeq.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vpr4j1jeq.fsf%40alter.siamese.dyndns.org
In-Reply-To: <ec0db70b8166ee4093a5a2400cd592e4263db20b.1265402797.git.larry@elder-gods.org>

```
Larry D'Anna <larry@elder-gods.org> writes:

> diff --git a/builtin-push.c b/builtin-push.c
> index 0a27072..ff0b1c6 100644
> --- a/builtin-push.c
> +++ b/builtin-push.c
> @@ -123,7 +123,7 @@ static int push_with_options(struct transport *transport, int flags)
>  	if (!err)
>  		return 0;
>  
> -	if (nonfastforward && advice_push_nonfastforward) {
> +	if (!(flags & TRANSPORT_PUSH_PORCELAIN) && nonfastforward && advice_push_nonfastforward) {

I suspect that it would be a much nicer solution if you turned advice_*
off in very early parts of the codepath after you read configuration and
command line options to see if --porcelain was asked for.  That way, we
don't have to add code check for PORCELAIN next time we add code for new
kinds of advice.  People who are adding new advice_* would grep for
existing one (e.g. "advice_push_nonfastforward") and will notice this
line, but if you had

	if (flags & TRANSPORT_PUSH_PORDCELAIN) {
        	advice_push_nonfastforward = 0;
	}

in early parts of the code, they will notice that as well, and then they
know where to add the corresponding change necessary.

```

## Tay Ray Chuan, 2010-02-05 23:50

Subject: Re: [PATCH v2 3/3] make git push --dry-run --porcelain exit with status 0 even if updates will be rejected
Message-ID: <20100206075025.c1fe6b5a.rctay89@gmail.com>
URL: https://gitlist.dev/e/20100206075025.c1fe6b5a.rctay89%40gmail.com
In-Reply-To: <cea7001d626116d76d885e24152d68cf41eca4dd.1265402797.git.larry@elder-gods.org>

```
Hi,

instead of:

> diff --git a/transport.c b/transport.c
> index 00d986c..b41e1dc 100644
> --- a/transport.c
> +++ b/transport.c
> @@ -558,8 +558,10 @@ static int fetch_refs_via_pack(struct transport *transport,
>  	return (refs ? 0 : -1);
>  }
>  
> -static int push_had_errors(struct ref *ref)
> +static int push_had_errors(struct ref *ref, int flags)
>  {
> +	if (flags & TRANSPORT_PUSH_DRY_RUN && flags & TRANSPORT_PUSH_PORCELAIN)
> +		return 0;
>  	for (; ref; ref = ref->next) {
>  		switch (ref->status) {
>  		case REF_STATUS_NONE:

and:

> @@ -1052,7 +1055,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 = push_had_errors(remote_refs, flags);
>  
>  		ret |= err;
>  

why not:

-->8--
@@ -1049,7 +1052,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;

-->8--

-- 
Cheers,
Ray Chuan

```

## Larry D'Anna, 2010-02-08 20:19

Subject: Re: [PATCH v2 3/3] make git push --dry-run --porcelain exit with status 0 even if updates will be rejected
Message-ID: <20100208201956.GA7015@cthulhu>
URL: https://gitlist.dev/e/20100208201956.GA7015%40cthulhu
In-Reply-To: <20100206075025.c1fe6b5a.rctay89@gmail.com>

```

good idea.  

     --larry

```
