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

exit code in git diff-index [was: Re: concurrent access to multiple local git repos is error prone]

From
Thomas Gummerer <t.gummerer@gmail.com>
Date
Aug 5, 2018, 19:34 UTC
Message-ID
<20180805193406.GH2734@hank.intra.tgummerer.com>
In-Reply-To
<CA+KyZp6KXFfEKNho7njg=0tDxAk-mSMP9r9hZFFH+gZcJ8KptQ@mail.gmail.com>
On 08/05, Alexander Mills wrote:
Show 21 quoted lines
> Also, as an aside, this seems to be a bug, but probably a known bug:
> 
> $ git diff-index  HEAD; echo $?
> 
> :100755 100755 60e5d683c1eb3e61381b1a8ec2db822b94b9faec
> 0000000000000000000000000000000000000000 M      cli/npp_check_merge.sh
> :100644 100644 35a453544de41e2227ab0afab31a396d299139e9
> 0000000000000000000000000000000000000000 M      src/find-projects.ts
> :100644 100644 c1ee7bc18e6604cbf0d16653e9366109d6ac2ec9
> 0000000000000000000000000000000000000000 M      src/tables.ts
> :100644 100644 29d9674fbb48f223f3434179d666b2aa991ad05a
> 0000000000000000000000000000000000000000 M
> src/vcs-helpers/git-helpers.ts
> 0
> 
> $ git diff-index --quiet HEAD; echo $?
> 1
> 
> different exit codes depending on whether --quiet was used. In this
> case, the exit code should be consistent.
> The bug is with the `git diff-index` command, as you can see.

This is not a bug. 'git diff-index' (and 'git diff') only give an exit code other than 0 in the default case if something actually goes wrong with generating the diff, which in the usual case it shouldn't.

To get an exit code from 'git diff-index' if there are differences, you'd have to pass the '--exit-code' flag. The '--quite' flag implies '--exit-code', as there's not much use in 'git diff --quiet' if there's not even an exit code showing whether there are differences or not.

The original patch (and more importantly the reasoning why '--exit-code' is not the default behaviour for 'git diff') can be found at [1].

[1]: https://public-inbox.org/git/81b0412b0703131717k7106ee1cg964628f0bda2c83e@mail.gmail.com/
> -alex
Previous: Alexander MillsNext: Alexander Mills
Message 7 of 11 in “concurrent access to multiple local git repos is error prone”
  1. Alexander MillsAug 4, 2018
  2. Alexander MillsAug 4, 2018
  3. Jonathan NiederAug 5, 2018
  4. Jonathan NiederAug 5, 2018
  5. Jonathan NiederAug 5, 2018
  6. Alexander MillsAug 5, 2018
  7. exit code in git diff-index [was: Re: concurrent access to multiple local git repos is error prone]Thomas Gummerer, Aug 5, 2018
  8. Alexander MillsAug 6, 2018
  9. Alexander MillsAug 6, 2018
  10. Jonathan NiederAug 6, 2018
  11. Duy NguyenAug 6, 2018

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.