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

Re: --exit-code (and --quiet) broken in git-diff?

From
René Scharfe <rene.scharfe@lsrfire.ath.cx>
Date
Aug 12, 2007, 09:40 UTC
Message-ID
<46BED5AA.7050900@lsrfire.ath.cx>
In-Reply-To
<17875.88.10.191.55.1186873960.squirrel@secure.wincent.com>
Wincent Colaiuta schrieb:
Show 40 quoted lines
> The git-diff man page documents an "--exit-code" option, as well as a
> "--quiet" option which automatically implies the former.
> 
> In my tests on Mac OS X and Bash 3, however, "git diff" always return an
> exit code of 0, never of 1, regardless of how I use the "--quiet" and
> "--exit-code" options. I see that there are tests in t/t4017-quiet.sh for
> the lower-level git-diff-files, git-diff-index, git-diff-tree commands,
> but none for the porcelain git-diff.
> 
> Is this a bug with a missing test case? Or am I using this incorrectly? In
> the example below I'm looking for differences between the working tree and
> the last commit, so I'm using "git diff HEAD", but as you can see, the
> exit code is always 0 for "git diff" and "git diff --cached" as well:
> 
> $ git --version
> git version 1.5.2.4
> $ mkdir example
> $ cd example
> $ git init
> Initialized empty Git repository in .git/
> $ echo "start" > foo
> $ git add foo
> $ git commit -m "Add foo"
> Created initial commit 85954f6: Add foo
>  1 files changed, 1 insertions(+), 0 deletions(-)
>  create mode 100644 foo
> $ git diff --quiet HEAD; echo $?
> 0
> $ echo "more" >> foo
> $ git diff --quiet HEAD; echo $?
> 0
> $ git add foo
> $ git diff --quiet HEAD; echo $?
> 0
> $ git diff --quiet; echo $?
> 0
> $ git diff --exit-code; echo $?
> 0
> $ git diff --cached --quiet; echo $?
> 0

git diff passes the output through your pager by default, so you see the exit code of that instead of diff's. Set PAGER=cat or redirect the output to /dev/null to get rid of it.

A test case for diff would be nice regardless, though. :)
René
Previous: Wincent ColaiutaNext: Wincent Colaiuta
Message 2 of 12 in “--exit-code (and --quiet) broken in git-diff?”
  1. Wincent ColaiutaAug 11, 2007
  2. René ScharfeAug 12, 2007
  3. Wincent ColaiutaAug 12, 2007
  4. David KastrupAug 12, 2007
  5. Steven GrimmAug 12, 2007
  6. David KastrupAug 12, 2007
  7. Wincent ColaiutaAug 12, 2007
  8. Steffen ProhaskaAug 12, 2007
  9. diff: don't run pager if user asked for a diff style exit codeRené Scharfe, Aug 12, 2007
  10. Wincent ColaiutaAug 13, 2007
  11. David KastrupAug 13, 2007
  12. Junio C HamanoAug 13, 2007

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.