Git development
 help / color / mirror / Atom feed
From: "Marc C" <marc@mccd.space>
To: <git@vger.kernel.org>
Subject: Git pre-received hook not failing with exit code 1 correcly
Date: Sat, 20 Jan 2024 19:57:28 -0600	[thread overview]
Message-ID: <CYK0FIQPVI22.2RHKOY4L00FZS@mccd.space> (raw)

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


             reply	other threads:[~2024-01-21  1:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-21  1:57 Marc C [this message]
2024-01-21 18:05 ` Git pre-received hook not failing with exit code 1 correcly brian m. carlson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CYK0FIQPVI22.2RHKOY4L00FZS@mccd.space \
    --to=marc@mccd.space \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox