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

Re: BUG in git diff-index

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 31, 2016, 20:39 UTC
Message-ID
<xmqqwpoil6vt.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<56FD7AE8.4090905@nglowry.com>
Andy Lowry <andy.work@nglowry.com> writes:
> So I think now that the script should do "update-index --refresh"
> followed by "diff-index --quiet HEAD". Sound correct?

Yes. That has always been one of the kosher ways for any script to make sure that the files in the working tree that are tracked have not been modified relative to HEAD (assuming that the index matches HEAD). If you are fuzzy about that assumption, you would also do "diff-index --quiet --cached HEAD" to ensure it, making the whole thing:

	update-index --refresh
        diff-index --quiet --cached HEAD && diff-index --quiet HEAD

Our scripts traditionally do the equivalent in a slightly different way. require_clean_work_tree() in git-sh-setup makes sure that (1) your working tree files match what is in your index and that (2) your index matches the HEAD, i.e.

	update-index --refresh
        diff-files --quiet && diff-index --cached --quiet HEAD

They are equivalent in that H==I && H==W (yours) mean H==I==W, while I==W && H==I (ours) also mean H==I==W. Two diff-index would require you to open the tree object of the HEAD twice, so our version may be more efficient but you probably wouldn't be able to measure the difference.

Previous: Andy LowryNext: Marc Herbert
Message 7 of 13 in “BUG in git diff-index”
  1. Andy LowryMar 31, 2016
  2. Carlos Martín NietoMar 31, 2016
  3. Jeff KingMar 31, 2016
  4. Andy LowryMar 31, 2016
  5. Jeff KingMar 31, 2016
  6. Andy LowryMar 31, 2016
  7. Junio C HamanoMar 31, 2016
  8. Marc HerbertSep 26, 2017
  9. Eric WongSep 26, 2017
  10. Google indexing https://public-inbox.org/git (was: BUG in git diff-index)Marc Herbert, Sep 26, 2017
  11. Wrong -dirty suffix set by setlocalversion (was: BUG in git diff-index)Marc Herbert, Sep 27, 2017
  12. Mike MasonMay 24, 2018
  13. Marc HerbertMay 25, 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.