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

Re: Determining if a tree is clean

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 6, 2010, 19:23 UTC
Message-ID
<7vy6i5fe5h.fsf@alter.siamese.dyndns.org>
In-Reply-To
<799406d61003060712t120d7f11me6e2ab212c55271@mail.gmail.com>
Adam Mercer <ramercer@gmail.com> writes:
> git diff-index --quiet HEAD

It is expected that a Porcelain script that implements a custom feature may call diff-files, diff-index and other plumbing commands many times during its lifetime, and that it knows what it is doing (namely, when it touches the working tree itself and why).

For this reason, most plumbing commands do not refresh the cached stat information in the index. A Porcelain script is responsible for running "update-index --refresh" once before it makes a call that cached stat information matters, and as long as it doesn't touch the files in the working tree, it doesn't have to run it again and again.

Porcelain commands like "git diff" that are expected to be run directly by the end user cannot assume that, so they do not optimize---they typically refresh the cached stat information by themselves internally whey they start up.

Your Porcelain script should look something like:
    git update-index --refresh
    git diff-files -q || { echo "modified working tree"; exit 1 }
    git diff-index --cached -q HEAD || { echo "modified index"; exit 2 }
See contrib/examples/*.sh for examples.
Previous: Adam MercerNext: Adam Mercer
Message 2 of 3 in “Determining if a tree is clean”
  1. Adam MercerMar 6, 2010
  2. Junio C HamanoMar 6, 2010
  3. Adam MercerMar 6, 2010

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.