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>
This commit is contained in:
committed by
Junio C Hamano
parent
274b9cc253
commit
7dcbeaa0df
@ -190,10 +190,8 @@ static int receive_status(struct packet_reader *reader, struct ref *refs)
|
||||
|
||||
if (reader->line[0] == 'o' && reader->line[1] == 'k')
|
||||
hint->status = REF_STATUS_OK;
|
||||
else {
|
||||
else
|
||||
hint->status = REF_STATUS_REMOTE_REJECT;
|
||||
ret = -1;
|
||||
}
|
||||
hint->remote_status = xstrdup_or_null(msg);
|
||||
/* start our next search from the next ref */
|
||||
hint = hint->next;
|
||||
@ -489,7 +487,8 @@ int send_pack(struct send_pack_args *args,
|
||||
if (use_atomic) {
|
||||
strbuf_release(&req_buf);
|
||||
strbuf_release(&cap_buf);
|
||||
return atomic_push_failure(args, remote_refs, ref);
|
||||
atomic_push_failure(args, remote_refs, ref);
|
||||
return args->porcelain ? 0 : -1;
|
||||
}
|
||||
/* else fallthrough */
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user