Skip to content

Commit

Permalink
push: only ignore finish_connect() for dry-run mode
Browse files Browse the repository at this point in the history
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.

Atomic push may abort the connection early and close the pipe, which
may cause an error for `finish_connect()`. Arbitrarily ignoring this
error will lead to issues. Modify it to only ignore the finish_connect()
error when both the --atomic and --dry-run flags are set.

Signed-off-by: Jiang Xin <[email protected]>
  • Loading branch information
jiangxin committed Dec 10, 2024
1 parent b10df53 commit 85f8f2d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions t/t5543-atomic-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ test_expect_success 'atomic push reports (reject by non-ff)' '
test_cmp expect actual
'

test_expect_failure 'atomic push reports exit code failure' '
test_expect_success 'atomic push reports exit code failure' '
write_script receive-pack-wrapper <<-\EOF &&
git-receive-pack "$@"
exit 1
Expand All @@ -296,7 +296,7 @@ test_expect_failure 'atomic push reports exit code failure' '
test_cmp expect err
'

test_expect_failure 'atomic push reports exit code failure with porcelain' '
test_expect_success 'atomic push reports exit code failure with porcelain' '
write_script receive-pack-wrapper <<-\EOF &&
git-receive-pack "$@"
exit 1
Expand Down
6 changes: 3 additions & 3 deletions transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -926,10 +926,10 @@ static int git_transport_push(struct transport *transport, struct ref *remote_re
close(data->fd[0]);
/*
* 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.
* which may cause an error for `finish_connect()`. We can ignore
* this error when both `--atomic` and `--dry-run` flags provided.
*/
if (ret || args.atomic)
if (ret || (args.atomic && args.dry_run))
finish_connect(data->conn);
else
ret = finish_connect(data->conn);
Expand Down

0 comments on commit 85f8f2d

Please sign in to comment.