git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/2] transport: don't ignore git-receive-pack(1) exit code on atomic push

From
Jiang Xin <worldhello.net@gmail.com>
Date
Nov 14, 2024, 08:57 UTC
Message-ID
<CANYiYbHGdJsTgdzJj1r4sPdTAcZCf3C-qA538fcXbD1jjB1BUw@mail.gmail.com>
In-Reply-To
<20241113-pks-push-atomic-respect-exit-code-v1-2-7965f01e7f4e@pks.im>
On Wed, Nov 13, 2024 at 7:25 PM Patrick Steinhardt <ps@pks.im> wrote:
Show 23 quoted lines
>
> When executing git-push(1) with the "--porcelain" flag, then we will
> print updated references in a machine-readable format that looks like
> this:
>
>     To destination
>     =   refs/heads/noop:refs/heads/noop [up to date]
>     !   refs/heads/rejected:refs/heads/rejected [rejected] (atomic push failed)
>     !   refs/heads/noff:refs/heads/(off (non-fast-forward)
>     Done
>
> The final "Done" stanza was introduced via 77555854be (git-push: make
> git push --porcelain print "Done", 2010-02-26), where it was printed
> "unless any errors have occurred". This behaviour was later changed via
> 7dcbeaa0df (send-pack: fix inconsistent porcelain output, 2020-04-17)
> such that the stanza will also be printed when there was an error with
> atomic pushes, which was previously inconsistent with non-atomic pushes.
> The fixup commit has introduced a new issue though. During atomic pushes
> it is expected that git-receive-pack(1) may exit early, and that causes
> us to receive an error on the client-side. We (seemingly) still want to
> print the "Done" stanza, but given that we only do so when the push has
> been successful we started to ignore the error code by the child process
> completely when doing an atomic push.

I introduced the commit 7dcbeaa0df (send-pack: fix inconsistent porcelain output, 2020-04-17), because the porcelain output for git push over local file protocol and HTTP protocol are different and was hard to write the some test cases to work for both protocols. I acknowledge the patch was not perfect.

I read the commit 77555854be (git-push: make git push --porcelain print "Done", 2010-02-26) and the code path of git push over two protocols a second time, and find something:

The code snippet from 77555854be:
Show 7 quoted lines
> -    ret = transport->push_refs(transport, remote_refs, flags);
> +    push_ret = transport->push_refs(transport, remote_refs, flags);
>      err = push_had_errors(remote_refs);
> -
> -    ret |= err;
> +    ret = push_ret | err;
>

The return code "push_ret" of push_refs() from different transport vtable is not consist. For HTTP protocol, "push_ret" is zero if no connection error or no protocol errors. So we should consider “push_ret" as a protocol error rather than a reference update error.

If we want to print "Done" in porcelain mode when there are no errors. (In dry run mode, ref-update-errors should not be considered as errors, but the opposite should be regarded as errors).

Instead of using the following code,
> +    if (porcelain && !push_ret)
> +         puts("Done");
We can use like this ("pretend" is the flag for dry-run mode):
+    ret = pretend ? push_ret : (push_ret | err);
+    if (porcelain && !ret)
+         puts("Done");
I will send patches follow this patch series.

-- Jiang Xin

Previous: Patrick SteinhardtNext: Jiang Xin
Message 4 of 54 in “transport: don't ignore git-receive-pack(1) exit code on atomic push”
  1. 0/2 transport: don't ignore git-receive-pack(1) exit code on atomic pushPatrick Steinhardt, Nov 13, 2024
  2. 1/2 t5504: modernize test by moving heredocs into test bodiesPatrick Steinhardt, Nov 13, 2024
  3. 2/2 transport: don't ignore git-receive-pack(1) exit code on atomic pushPatrick Steinhardt, Nov 13, 2024
  4. Jiang XinNov 14, 2024
  5. 0/6 fix behaviors of git-push --porcelainJiang Xin, Nov 14, 2024
  6. 1/6 t5548: new test cases for push --porcelain and --dry-runJiang Xin, Nov 14, 2024
  7. Patrick SteinhardtNov 25, 2024
  8. Jiang XinDec 3, 2024
  9. 2/6 push: fix the behavior of the Done message for porcelainJiang Xin, Nov 14, 2024
  10. Patrick SteinhardtNov 25, 2024
  11. 3/6 t5504: modernize test by moving heredocs into test bodiesJiang Xin, Nov 14, 2024
  12. 4/6 t5543: atomic push reports exit code failureJiang Xin, Nov 14, 2024
  13. 5/6 push: only ignore finish_connect() for dry-run modeJiang Xin, Nov 14, 2024
  14. Patrick SteinhardtNov 25, 2024
  15. 6/6 push: not send push-options to server with --dry-runJiang Xin, Nov 14, 2024
  16. Patrick SteinhardtNov 25, 2024
  17. 0/8 fix behaviors of git-push --porcelainJiang Xin, Dec 10, 2024
  18. 1/8 t5504: modernize test by moving heredocs into test bodiesJiang Xin, Dec 10, 2024
  19. 2/8 t5548: refactor to reuse setup_upstream() functionJiang Xin, Dec 10, 2024
  20. 3/8 t5548: refactor test cases by resetting upstreamJiang Xin, Dec 10, 2024
  21. 4/8 t5548: add new porcelain test casesJiang Xin, Dec 10, 2024
  22. 5/8 t5548: add porcelain push test cases for dry-run modeJiang Xin, Dec 10, 2024
  23. Jiang XinDec 10, 2024
  24. 6/8 send-pack: new return code "ERROR_SEND_PACK_BAD_REF_STATUS"Jiang Xin, Dec 10, 2024
  25. Patrick SteinhardtDec 16, 2024
  26. 7/8 t5543: atomic push reports exit code failureJiang Xin, Dec 10, 2024
  27. 8/8 send-pack: gracefully close the connection for atomic pushJiang Xin, Dec 10, 2024
  28. Patrick SteinhardtDec 16, 2024
  29. Junio C HamanoNov 14, 2024
  30. Patrick SteinhardtNov 25, 2024
  31. 0/8 transport: don't ignore git-receive-pack(1) exit code on atomic pushPatrick Steinhardt, Jan 31, 2025
  32. 1/8 t5504: modernize test by moving heredocs into test bodiesPatrick Steinhardt, Jan 31, 2025
  33. Eric SunshineJan 31, 2025
  34. Junio C HamanoJan 31, 2025
  35. Patrick SteinhardtFeb 3, 2025
  36. 2/8 t5548: refactor to reuse setup_upstream() functionPatrick Steinhardt, Jan 31, 2025
  37. Eric SunshineJan 31, 2025
  38. 4/8 t5548: add new porcelain test casesPatrick Steinhardt, Jan 31, 2025
  39. Eric SunshineJan 31, 2025
  40. 5/8 t5548: add porcelain push test cases for dry-run modePatrick Steinhardt, Jan 31, 2025
  41. 3/8 t5548: refactor test cases by resetting upstreamPatrick Steinhardt, Jan 31, 2025
  42. 7/8 t5543: atomic push reports exit code failurePatrick Steinhardt, Jan 31, 2025
  43. 6/8 send-pack: new return code "ERROR_SEND_PACK_BAD_REF_STATUS"Patrick Steinhardt, Jan 31, 2025
  44. 8/8 send-pack: gracefully close the connection for atomic pushPatrick Steinhardt, Jan 31, 2025
  45. 0/8 transport: don't ignore git-receive-pack(1) exit code on atomic pushPatrick Steinhardt, Feb 3, 2025
  46. 1/8 t5504: modernize test by moving heredocs into test bodiesPatrick Steinhardt, Feb 3, 2025
  47. 2/8 t5548: refactor to reuse setup_upstream() functionPatrick Steinhardt, Feb 3, 2025
  48. 3/8 t5548: refactor test cases by resetting upstreamPatrick Steinhardt, Feb 3, 2025
  49. 4/8 t5548: add new porcelain test casesPatrick Steinhardt, Feb 3, 2025
  50. 5/8 t5548: add porcelain push test cases for dry-run modePatrick Steinhardt, Feb 3, 2025
  51. 6/8 send-pack: new return code "ERROR_SEND_PACK_BAD_REF_STATUS"Patrick Steinhardt, Feb 3, 2025
  52. 7/8 t5543: atomic push reports exit code failurePatrick Steinhardt, Feb 3, 2025
  53. 8/8 send-pack: gracefully close the connection for atomic pushPatrick Steinhardt, Feb 3, 2025
  54. Junio C HamanoFeb 3, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.