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

Git pre-received hook not failing with exit code 1 correcly

From
MCMarc C <marc@mccd.space>
Date
Jan 21, 2024, 01:57 UTC
Message-ID
<CYK0FIQPVI22.2RHKOY4L00FZS@mccd.space>
Heya!

I am trying to understand why my pre-publish hook does not exit with the correct status code.

I have a pre-publish script

``` #!/bin/sh set -euo pipefail echo "Testing nixos config" nixos-rebuild dry-build echo "Success" ```

Running it directly in my CLI, it acts like I would expect and return exit code 1.

```
$ ./.git/hooks/pre-receive
Testing nixos config
building the system configuration...
error:
       … while calling the 'seq' builtin
       ....
       ...

$ echo "$?" 1 ```

However, when running the script as a pre-receive hook, it is not running the commands correctly and returns the wrong exit code. I get the following:

```
remote: Testing nixos config
remote: building the system configuration...
remote: Success <-- ????
remote: error:
remote:        … while calling the 'seq' builtin
...
To myserver:/myrepo
   bffa94e..a14b3f6  main -> main
```

Any clue what I am missing? When running it as a pre-receive hook, the failing command returns exit code 0. Running it in the CLI, it returns exit code 1. It is Schrodinger's exit code.

Thank you so much for your help.

Sincerely, Marc

Next: brian m. carlson
Message 1 of 2 in “Git pre-received hook not failing with exit code 1 correcly”
  1. Marc CJan 21, 2024
  2. brian m. carlsonJan 21, 2024

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.