Skip to content

Commit f51e4df

Browse files
committed
send-pack: gracefully close the connection for atomic push
Patrick reported an issue that the exit code of git-receive-pack(1) is ignored during atomic push with "--porcelain" flag, and added new test cases in t5543. This issue originated from commit 7dcbeaa (send-pack: fix inconsistent porcelain output, 2020-04-17). At that time, I chose to ignore the exit code of "finish_connect()" without investigating the root cause of the abnormal termination of git-receive-pack. That was an incorrect solution. The root cause is that an atomic push operation terminates early without sending a flush packet to git-receive-pack. As a result, git-receive-pack continues waiting for commands without exiting. By sending a flush packet at the appropriate location in "send_pack()", we ensure that the git-receive-pack process closes properly, avoiding an erroneous exit code for git-push. At the same time, revert the changes to the "transport.c" file made in commit 7dcbeaa. Reported-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
1 parent 621887f commit f51e4df

File tree

3 files changed

+4
-11
lines changed

3 files changed

+4
-11
lines changed

send-pack.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,7 @@ int send_pack(struct send_pack_args *args,
631631
error("atomic push failed for ref %s. status: %d",
632632
ref->name, ref->status);
633633
ret = ERROR_SEND_PACK_BAD_REF_STATUS;
634+
packet_flush(out);
634635
goto out;
635636
}
636637
/* else fallthrough */

t/t5543-atomic-push.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ test_expect_success 'atomic push reports (reject by non-ff)' '
280280
test_cmp expect actual
281281
'
282282

283-
test_expect_failure 'atomic push reports exit code failure' '
283+
test_expect_success 'atomic push reports exit code failure' '
284284
write_script receive-pack-wrapper <<-\EOF &&
285285
git-receive-pack "$@"
286286
exit 1
@@ -296,7 +296,7 @@ test_expect_failure 'atomic push reports exit code failure' '
296296
test_cmp expect err
297297
'
298298

299-
test_expect_failure 'atomic push reports exit code failure with porcelain' '
299+
test_expect_success 'atomic push reports exit code failure with porcelain' '
300300
write_script receive-pack-wrapper <<-\EOF &&
301301
git-receive-pack "$@"
302302
exit 1

transport.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -928,15 +928,7 @@ static int git_transport_push(struct transport *transport, struct ref *remote_re
928928

929929
close(data->fd[1]);
930930
close(data->fd[0]);
931-
/*
932-
* Atomic push may abort the connection early and close the pipe,
933-
* which may cause an error for `finish_connect()`. Ignore this error
934-
* for atomic git-push.
935-
*/
936-
if (ret || args.atomic)
937-
finish_connect(data->conn);
938-
else
939-
ret = finish_connect(data->conn);
931+
ret |= finish_connect(data->conn);
940932
data->conn = NULL;
941933
data->finished_handshake = 0;
942934

0 commit comments

Comments
 (0)