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

Re: git does not wait on hook exes (^C)

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Feb 21, 2020, 00:01 UTC
Message-ID
<20200221000141.GA6462@camp.crustytoothpaste.net>
In-Reply-To
<CA+dzEB=jJEkuvcX5qDfeXS=mbJu_m=-yUsmHd_KrKAXC3YDe7w@mail.gmail.com>
On 2020-02-20 at 21:14:55, Anthony Sottile wrote:
Show 28 quoted lines
> Here's a small example:
> 
> ```bash
> #!/usr/bin/env bash
> foo() {
>     echo zzz part 2
>     sleep 1
>     echo exiting now
> }
> trap foo SIGINT
> 
> echo zzz part 1
> sleep 10
> ```
> 
> ```console
> $ git --version
> git version 2.25.GIT
> $ git commit --allow-empty -m foo
> zzz part 1
> ^Czzz part 2
> 
> $ exiting now
> ```
> 
> - I pressed ^C during the first sleep
> - control was returned back to my terminal
> - the hook script was still running in the background

I believe the way that SIGINT works on a terminal is that it sends the signal to all processes in the foreground process group. So my guess of what's happening here is that Git and your script both get SIGINT, Git cleans up and exits quickly, leaving your script running.

If so, I'm not sure that Git can do much here. If Git waited for the hook to exit, then a broken or hung hook would cause Git to hang indefinitely, which is not what the user intended when they pressed Ctrl-C. Usually what the user wants is an immediate return to the terminal in such a case, and I think most users would consider it a bug if Git were to wait for its children.

Certainly I'm open to hearing other views on this, though.
-- 
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204
Previous: Anthony SottileNext: Anthony Sottile
Message 2 of 8 in “git does not wait on hook exes (^C)”
  1. Anthony SottileFeb 20, 2020
  2. brian m. carlsonFeb 21, 2020
  3. Anthony SottileFeb 21, 2020
  4. brian m. carlsonFeb 21, 2020
  5. Anthony SottileFeb 21, 2020
  6. brian m. carlsonFeb 21, 2020
  7. Jeff KingFeb 21, 2020
  8. Anthony SottileFeb 21, 2020

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.