commit c3cc85a3c5ab8491266b207eeb1fb6b6061274ed from: Stefan Sperling date: Tue Apr 30 13:36:58 2024 UTC make gotd notifications work when 'git push' is used instead of 'got send' Git clients disconnect earlier, which resulted in session_write exiting before notifications were sent. Do not treat early EOF as a fatal error if we are sending notifications. Add regression test coverage for 'git push'. Problem found by Thomas Adam. commit - e6370d593b348b23199788e4b0d5a23f14dde15e commit + c3cc85a3c5ab8491266b207eeb1fb6b6061274ed blob - d957c78baa66812aad479f8135c63971e8397e2e blob + 71dc0c77ac342b6091e80eba631e77bc42265dda --- gotd/session_write.c +++ gotd/session_write.c @@ -1341,7 +1341,8 @@ session_dispatch_client(int fd, short events, void *ar if (err) { if (err->code != GOT_ERR_EOF || - gotd_session.state != GOTD_STATE_EXPECT_PACKFILE) + (gotd_session.state != GOTD_STATE_EXPECT_PACKFILE && + gotd_session.state != GOTD_STATE_NOTIFY)) disconnect_on_error(client, err); } else { gotd_imsg_event_add(iev); blob - 33fbf586ff94a94ca7f4a10f06a3814106db946d blob + daa3a3c53c47d2e2f9f1506b58b3ea5def124c05 --- regress/gotd/http_notification.sh +++ regress/gotd/http_notification.sh @@ -106,7 +106,73 @@ test_file_changed() { test_done "$testroot" "$ret" return 1 fi + + # Try the same thing again with 'git push' instead of 'got send' + echo "change alpha once more" > $testroot/wt/alpha + (cd $testroot/wt && got commit -m 'make more changes' > /dev/null) + local commit_id=`git_show_head $testroot/repo-clone` + local author_time=`git_show_author_time $testroot/repo-clone` + + timeout 5 ./http-server -a $AUTH -p $GOTD_TEST_HTTP_PORT \ + > $testroot/stdout & + + git -C $testroot/repo-clone push -q origin main + ret=$? + if [ $ret -ne 0 ]; then + echo "git push failed unexpectedly" >&2 + test_done "$testroot" "1" + return 1 + fi + + wait %1 # wait for the http "server" + + echo -n > "$testroot/stdout.expected" + ed -s "$testroot/stdout.expected" <<-EOF + a + {"notifications":[{ + "type":"commit", + "short":false, + "repo":"test-repo", + "auth_user":"${GOTD_DEVUSER}", + "id":"$commit_id", + "author":{ + "full":"$GOT_AUTHOR", + "name":"$GIT_AUTHOR_NAME", + "mail":"$GIT_AUTHOR_EMAIL", + "user":"$GOT_AUTHOR_11" + }, + "committer":{ + "full":"$GOT_AUTHOR", + "name":"$GIT_AUTHOR_NAME", + "mail":"$GIT_AUTHOR_EMAIL", + "user":"$GOT_AUTHOR_11" + }, + "date":$author_time, + "short_message":"make more changes", + "message":"make more changes\n", + "diffstat":{ + "files":[{ + "action":"modified", + "file":"alpha", + "added":1, + "removed":1 + }], + "total":{ + "added":1, + "removed":1 + } + } + }]} + . + ,j + w + EOF + cmp -s $testroot/stdout.expected $testroot/stdout + ret=$? + if [ $ret -ne 0 ]; then + diff -u $testroot/stdout.expected $testroot/stdout + fi test_done "$testroot" "$ret" }