git-push: make git push --porcelain print "Done"
authorLarry D'Anna <larry@elder-gods.org>
Sat, 27 Feb 2010 04:52:15 +0000 (23:52 -0500)
committerJunio C Hamano <gitster@pobox.com>
Sun, 28 Feb 2010 18:39:30 +0000 (10:39 -0800)
The script calling git push --porcelain --dry-run can see clearly from the
output if an update was rejected.  However, it will probably need to distinguish
this condition from the push failing for other reasons, such as the remote not
being reachable.

This patch modifies git push --porcelain to print "Done" after the rest of its
output unless any errors have occurred.  For the purpose of the "Done" line,
knowing a ref will be rejected in a --dry-run does not count as an error.
Actual rejections in non --dry-run pushes do count as errors.

Signed-off-by: Larry D'Anna <larry@elder-gods.org>
Acked-by: Tay Ray Chuan <rctay89@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-send-pack.c
send-pack.h
transport.c

index 76c72065de73ea3f0da4665c0a47a64610e2ead2..078bc3e8ec2c19f7fc5e8688cccd3ac4679c7a51 100644 (file)
@@ -476,6 +476,10 @@ int send_pack(struct send_pack_args *args,
 
        if (ret < 0)
                return ret;
+
+       if (args->porcelain)
+               return 0;
+
        for (ref = remote_refs; ref; ref = ref->next) {
                switch (ref->status) {
                case REF_STATUS_NONE:
index 28141ac913f6558b81ff0b1b21a1e1b5ead43fa0..60b4ba66eb8cac3378326378dc4e0cbdb88162ac 100644 (file)
@@ -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,
index fb653c654a884906ecb5163e8a3f8d9c3f63cc63..260350b5a6f1eb38e3755a6be5befef66c04fa29 100644 (file)
@@ -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);
@@ -1035,7 +1036,7 @@ int transport_push(struct transport *transport,
                int quiet = flags & TRANSPORT_PUSH_QUIET;
                int porcelain = flags & TRANSPORT_PUSH_PORCELAIN;
                int pretend = flags & TRANSPORT_PUSH_DRY_RUN;
-               int ret, err;
+               int push_ret, ret, err;
 
                if (flags & TRANSPORT_PUSH_ALL)
                        match_flags |= MATCH_REFS_ALL;
@@ -1051,10 +1052,9 @@ int transport_push(struct transport *transport,
                        flags & TRANSPORT_PUSH_MIRROR,
                        flags & TRANSPORT_PUSH_FORCE);
 
-               ret = transport->push_refs(transport, remote_refs, flags);
+               push_ret = transport->push_refs(transport, remote_refs, flags);
                err = push_had_errors(remote_refs);
-
-               ret |= err;
+               ret = push_ret | err;
 
                if (!quiet || err)
                        print_push_status(transport->url, remote_refs,
@@ -1070,8 +1070,11 @@ int transport_push(struct transport *transport,
                                update_tracking_ref(transport->remote, ref, verbose);
                }
 
-               if (!quiet && !ret && !refs_pushed(remote_refs))
+               if (porcelain && !push_ret)
+                       puts("Done");
+               else if (!quiet && !ret && !refs_pushed(remote_refs))
                        fprintf(stderr, "Everything up-to-date\n");
+
                return ret;
        }
        return 1;