Skip to content

Commit fd3b41e

Browse files
committed
Merge branch 'ps/send-pack-unhide-error-in-atomic-push' into seen
"git push --atomic --porcelain" used to ignore failures from the other side, losing the error status from the child process, which has been corrected. * ps/send-pack-unhide-error-in-atomic-push: transport: don't ignore git-receive-pack(1) exit code on atomic push t5504: modernize test by moving heredocs into test bodies
2 parents ab24d63 + 0e1dd9f commit fd3b41e

File tree

4 files changed

+50
-27
lines changed

4 files changed

+50
-27
lines changed

send-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ int send_pack(struct repository *r,
632632
reject_atomic_push(remote_refs, args->send_mirror);
633633
error("atomic push failed for ref %s. status: %d",
634634
ref->name, ref->status);
635-
ret = args->porcelain ? 0 : -1;
635+
ret = -1;
636636
goto out;
637637
}
638638
/* else fallthrough */

t/t5504-fetch-receive-strict.sh

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,6 @@ test_expect_success 'fetch with transfer.fsckobjects' '
6464
)
6565
'
6666

67-
cat >exp <<EOF
68-
To dst
69-
! refs/heads/main:refs/heads/test [remote rejected] (missing necessary objects)
70-
Done
71-
EOF
72-
7367
test_expect_success 'push without strict' '
7468
rm -rf dst &&
7569
git init dst &&
@@ -78,6 +72,11 @@ test_expect_success 'push without strict' '
7872
git config fetch.fsckobjects false &&
7973
git config transfer.fsckobjects false
8074
) &&
75+
cat >exp <<-EOF &&
76+
To dst
77+
! refs/heads/main:refs/heads/test [remote rejected] (missing necessary objects)
78+
Done
79+
EOF
8180
test_must_fail git push --porcelain dst main:refs/heads/test >act &&
8281
test_cmp exp act
8382
'
@@ -94,11 +93,6 @@ test_expect_success 'push with !receive.fsckobjects' '
9493
test_cmp exp act
9594
'
9695

97-
cat >exp <<EOF
98-
To dst
99-
! refs/heads/main:refs/heads/test [remote rejected] (unpacker error)
100-
EOF
101-
10296
test_expect_success 'push with receive.fsckobjects' '
10397
rm -rf dst &&
10498
git init dst &&
@@ -107,6 +101,11 @@ test_expect_success 'push with receive.fsckobjects' '
107101
git config receive.fsckobjects true &&
108102
git config transfer.fsckobjects false
109103
) &&
104+
cat >exp <<-EOF &&
105+
To dst
106+
! refs/heads/main:refs/heads/test [remote rejected] (unpacker error)
107+
Done
108+
EOF
110109
test_must_fail git push --porcelain dst main:refs/heads/test >act &&
111110
test_cmp exp act
112111
'
@@ -129,15 +128,14 @@ test_expect_success 'repair the "corrupt or missing" object' '
129128
git fsck
130129
'
131130

132-
cat >bogus-commit <<EOF
133-
tree $EMPTY_TREE
134-
author Bugs Bunny 1234567890 +0000
135-
committer Bugs Bunny <[email protected]> 1234567890 +0000
136-
137-
This commit object intentionally broken
138-
EOF
139-
140131
test_expect_success 'setup bogus commit' '
132+
cat >bogus-commit <<-EOF &&
133+
tree $EMPTY_TREE
134+
author Bugs Bunny 1234567890 +0000
135+
committer Bugs Bunny <[email protected]> 1234567890 +0000
136+
137+
This commit object intentionally broken
138+
EOF
141139
commit="$(git hash-object --literally -t commit -w --stdin <bogus-commit)"
142140
'
143141

t/t5543-atomic-push.sh

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

283+
test_expect_success 'atomic push reports exit code failure' '
284+
write_script receive-pack-wrapper <<-\EOF &&
285+
git-receive-pack "$@"
286+
exit 1
287+
EOF
288+
test_must_fail git -C workbench push --atomic \
289+
--receive-pack="${SQ}$(pwd)${SQ}/receive-pack-wrapper" \
290+
up HEAD:refs/heads/no-conflict 2>err &&
291+
cat >expect <<-EOF &&
292+
To ../upstream
293+
* [new branch] HEAD -> no-conflict
294+
error: failed to push some refs to ${SQ}../upstream${SQ}
295+
EOF
296+
test_cmp expect err
297+
'
298+
299+
test_expect_success 'atomic push reports exit code failure with porcelain' '
300+
write_script receive-pack-wrapper <<-\EOF &&
301+
git-receive-pack "$@"
302+
exit 1
303+
EOF
304+
test_must_fail git -C workbench push --atomic --porcelain \
305+
--receive-pack="${SQ}$(pwd)${SQ}/receive-pack-wrapper" \
306+
up HEAD:refs/heads/no-conflict-porcelain 2>err &&
307+
cat >expect <<-EOF &&
308+
error: failed to push some refs to ${SQ}../upstream${SQ}
309+
EOF
310+
test_cmp expect err
311+
'
312+
283313
test_done

transport.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -967,12 +967,7 @@ static int git_transport_push(struct transport *transport, struct ref *remote_re
967967

968968
close(data->fd[1]);
969969
close(data->fd[0]);
970-
/*
971-
* Atomic push may abort the connection early and close the pipe,
972-
* which may cause an error for `finish_connect()`. Ignore this error
973-
* for atomic git-push.
974-
*/
975-
if (ret || args.atomic)
970+
if (ret)
976971
finish_connect(data->conn);
977972
else
978973
ret = finish_connect(data->conn);
@@ -1547,7 +1542,7 @@ int transport_push(struct repository *r,
15471542
transport_update_tracking_ref(transport->remote, ref, verbose);
15481543
}
15491544

1550-
if (porcelain && !push_ret)
1545+
if (porcelain)
15511546
puts("Done");
15521547
else if (!quiet && !ret && !transport_refs_pushed(remote_refs))
15531548
/* stable plumbing output; do not modify or localize */

0 commit comments

Comments
 (0)