summaryrefslogtreecommitdiff
path: root/transport.c
diff options
context:
space:
mode:
authorJiang Xin <zhiyou.jx@alibaba-inc.com>2020-04-17 05:45:32 -0400
committerJunio C Hamano <gitster@pobox.com>2020-04-17 12:16:31 -0700
commit7dcbeaa0df01661f31a0d93e5d5787a5d3767358 (patch)
tree09801410b978d6e1295793b7248514175c960e35 /transport.c
parent274b9cc25322d9ee79aa8e6d4e86f0ffe5ced925 (diff)
downloadgit-7dcbeaa0df01661f31a0d93e5d5787a5d3767358.tar.gz
send-pack: fix inconsistent porcelain output
The porcelain output of a failed `git-push` command is inconsistent for different protocols. For example, the following `git-push` command may fail due to the failure of the `pre-receive` hook. git push --porcelain origin HEAD:refs/heads/master For SSH protocol, the porcelain output does not end with a "Done" message: To <URL/of/upstream.git> ! HEAD:refs/heads/master [remote rejected] (pre-receive hook declined) While for HTTP protocol, the porcelain output does end with a "Done" message: To <URL/of/upstream.git> ! HEAD:refs/heads/master [remote rejected] (pre-receive hook declined) Done The following code at the end of function `send_pack()` indicates that `send_pack()` should not return an error if some references are rejected in porcelain mode. int send_pack(...) ... ... if (args->porcelain) return 0; for (ref = remote_refs; ref; ref = ref->next) { switch (ref->status) { case REF_STATUS_NONE: case REF_STATUS_UPTODATE: case REF_STATUS_OK: break; default: return -1; } } return 0; } So if atomic push failed, must check the porcelain mode before return an error. And `receive_status()` should not return an error for a failed updated reference, because `send_pack()` will check them instead. Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'transport.c')
-rw-r--r--transport.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/transport.c b/transport.c
index 1fdc7dac1a..13d638d5fe 100644
--- a/transport.c
+++ b/transport.c
@@ -715,7 +715,15 @@ static int git_transport_push(struct transport *transport, struct ref *remote_re
close(data->fd[1]);
close(data->fd[0]);
- ret |= finish_connect(data->conn);
+ /*
+ * Atomic push may abort the connection early and close the pipe,
+ * which may cause an error for `finish_connect()`. Ignore this error
+ * for atomic git-push.
+ */
+ if (ret || args.atomic)
+ finish_connect(data->conn);
+ else
+ ret = finish_connect(data->conn);
data->conn = NULL;
data->got_remote_heads = 0;