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

git diff/log --check exitcode and PAGER environment variable

From
PLPeter Valdemar Mørch (Lists) <4ux6as402@sneakemail.com>
Date
Aug 8, 2008, 09:39 UTC
Message-ID
<489C145B.5090400@sneakemail.com>

Using my default PAGER=less, git log --check exits with exit code 0, contrary to documentation.

There is this old thread: "[PATCH 1/5] "diff --check" should affect exit status" http://thread.gmane.org/gmane.comp.version-control.git/68145/focus=68148 which seemed not to reach a conclusion.

For git log, I still have not been able to make it exit with anything other than 0 - contrary to documentation.

May I propose a change to either documentation or behavior of "git diff --check". The current one has:

--check::
	Warn if changes introduce trailing whitespace
	or an indent that uses a space before a tab. Exits with
	non-zero status if problems are found. Not compatible with
	--exit-code.
This, clearly, is not correct:

$ PAGER=less git diff --check (my default PAGER) or $ unset PAGER ; git diff --check always exits with exit code 0. But

$ git --no-pager diff --check or $ PAGER=cat git diff --check or $ PAGER= git diff --check exits with exit code 2 on error (curiously PAGER= and unset PAGER give different results)

But the --exit-code overrides any of that:

$ git --no-pager diff --check --exit-code exits with exit code 3 on error (with or without the --no-pager).

I'm not sure about a good rephrasing. How about: '... "git diff" exits with non-zero status if problems are found and run with --exit-code.'

While this documentation string is found in diff-options.txt and included in:

git-diff-files.txt git-diff-index.txt git-diff-tree.txt git-diff.txt git-format-patch.txt git-log.txt

At least for the git-log cases, the behavior is not the same as for git-diff:

$ PAGER=cat git --no-pager log HEAD~20..HEAD --check --exit-code $ echo $? 0 Though there are several check failures (red squares in output), it exits with 0, even when using all the tricks that work with "git diff".

Clearly here, the documentation is "even more wrong". Hence the explicit mention of "git diff" in the help string for the --check option.

What do you think?
Peter
-- 
Peter Valdemar Mørch
http://www.morch.com
Next: Junio C Hamano
Message 1 of 18 in “git diff/log --check exitcode and PAGER environment variable”
  1. Peter Valdemar Mørch (Lists)Aug 8, 2008
  2. Junio C HamanoAug 8, 2008
  3. Peter Valdemar Mørch (Lists)Aug 8, 2008
  4. Re* git diff/log --check exitcode and PAGER environment variableJunio C Hamano, Aug 8, 2008
  5. Peter Valdemar Mørch (Lists)Aug 8, 2008
  6. Johannes SchindelinAug 8, 2008
  7. Junio C HamanoAug 8, 2008
  8. Teach git log --check to return an appropriate error codePeter Valdemar Mørch, Aug 9, 2008
  9. Johannes SchindelinAug 9, 2008
  10. Junio C HamanoAug 9, 2008
  11. Peter Valdemar Mørch (Lists)Aug 10, 2008
  12. Junio C HamanoAug 10, 2008
  13. Junio C HamanoAug 9, 2008
  14. PATCH v2 0/2 Trying patch againPeter Valdemar Mørch, Aug 11, 2008
  15. 1/2 Teach git log --check to return an appropriate exit codePeter Valdemar Mørch, Aug 11, 2008
  16. 2/2 Teach git log --exit-code to return an appropriate exit codePeter Valdemar Mørch, Aug 11, 2008
  17. Jeff KingAug 8, 2008
  18. Jeff KingAug 8, 2008

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.