Tuesday, July 12, 2016

git log exit code 141?

Something's that been bugging me for a while now is that when I do a `git log` command and quit before scrolling through all the output, my terminal prompt shows my last command (the git log) exited non-zero with status code 141.

I have git configured to use `less -+S` as the pager.

The answer turns out to be really straightforward, but took me a little bit of internet searching. I am capturing the learning here to save my future self the research and possibly anyone else typing the exact same thing into Google that I did ;-)

The explanation:

  • Git pipes the logs into less
  • I quit the less process, which sends a SIGPIPE signal (13) to the underlying git process streaming the logs
  • git catches the interrupt and exits prematurely and per POSIX convention returns 128 + the SIGPIPE status ==> 141 to indicate that it was terminated by signal 13
The background:
  1. http://stackoverflow.com/questions/19120263/why-exit-code-141-with-grep-q
  2. http://www.pixelbeat.org/programming/sigpipe_handling.html
  3. http://unix.stackexchange.com/questions/99112/default-exit-code-when-process-is-terminated/99134#99134

6 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. Updating with the latest technology and implementing it is the only way to survive in our niche. Thanks for making me this article. You have done a great job by sharing this content in here. Keep writing article like this.
    SAS Training in Chennai | SAS Course in Chennai

    ReplyDelete
  3. Is there any way to fix the exit code so that it is 0?

    ReplyDelete
    Replies
    1. Yes, change your git pager configuration to just `less`

      Delete
    2. you have arrived to the ideal spot. We are best and cheap escort Agency in Gurgaon, who can provide best in class escorts services. Our delightful organization is the best that you will discover anyplace and will give you awesome client satisfaction. Finding the right woman, paying little respect to the event, Escorts in Gurgaon

      Delete
    3. I have tried setting core.pager to 'less' as well as removing all color-related env vars, and I continue to get error 141 when I quit 'git log'. Any more ideas?

      Delete