Does git return specific return error codes?

前端 未结 6 507
醉梦人生
醉梦人生 2020-12-13 22:52

Like merging errors, or rebase errors. Does it have a unique error code?

6条回答
  •  轮回少年
    2020-12-13 23:32

    Git 2.24 (Q4 2019) does illustrate how git commands return code.

    See commit 50094ca, commit c1a6f21, commit 854b5cb, commit dd2b6b6, commit 6bd26f5, commit c6ec6da, commit f2e2fa8, commit 460609c, commit 92014b6, commit 0ab74e9, commit cb46c40, commit b562a54 (27 Aug 2019), and commit fe49814 (20 Aug 2019) by Denton Liu (Denton-L).
    (Merged by Junio C Hamano -- gitster -- in commit 1c6fc94, 30 Sep 2019)

    t4014: stop losing return codes of git commands

    Currently, there are two ways where the return codes of Git commands are lost.

    The first way is when a command is in the upstream of a pipe. In a pipe, only the return code of the last command is used. Thus, all other commands will have their return codes masked.
    Rewrite pipes so that there are no Git commands upstream.

    The other way is when a command is in a non-assignment subshell.
    The return code will be lost in favour of the surrounding command's.
    Rewrite instances of this such that Git commands output to a file and surrounding commands only call subshells with non-Git commands.

    So instead of writing:

    git cat-file commit rebuild-1 | grep "^Side .* with .* backslash-n"
    

    Type:

    git cat-file commit rebuild-1 >actual &&
        grep "^Side .* with .* backslash-n" actual
    

提交回复
热议问题