git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Andy Lowry <andy.work@nglowry.com>
Cc: git@vger.kernel.org
Subject: Re: BUG in git diff-index
Date: Thu, 31 Mar 2016 10:05:15 -0400	[thread overview]
Message-ID: <20160331140515.GA31116@sigill.intra.peff.net> (raw)
In-Reply-To: <loom.20160331T143733-916@post.gmane.org>

On Thu, Mar 31, 2016 at 12:39:23PM +0000, Andy Lowry wrote:

> Following transcript illustrates what I believe to be a bug in git diff-
> index. The session used a git built from latest source, located in 
> /tmp/git/git.
> 
> 1. New repo, create empty file A, commit changes.
> 2. touch A
> 3. git diff-index reports A has changed, and reports bogus destination 
> SHA
> 4. This is stable behavior until next step
> 5. git diff correctly reports no changes
> 6. git diff-index now also reports nothing
> 
> My understanding is that git diff-index should care only about content 
> and file mode, not modification time.

This is working as designed (though I agree it is a little confusing).
From "git help diff-index":

       These commands all compare two sets of things; what is compared differs:

       git-diff-index <tree-ish>
           compares the <tree-ish> and the files on the filesystem.

       git-diff-index --cached <tree-ish>
           compares the <tree-ish> and the index.

       git-diff-tree [-r] <tree-ish-1> <tree-ish-2> [<pattern>...]
           compares the trees named by the two arguments.

       git-diff-files [<pattern>...]
           compares the index and the files on the filesystem.

Your invocation triggers the first, though it is not a true comparison
of what is on the filesystem, but rather a tree/index comparison, taking
into account the filesystem values. The all-zeroes sha1 indicates that
the index entry is not up to date with what is in the filesystem, but we
don't actually read the file contents to refresh the entry.

Back when diff-index was written, it was generally assumed that scripts
would refresh the index as their first operation, and then proceed to do
one or more operations like diff-index, which would rely on the refresh
from the first step.

Running the porcelain "git diff" does refresh the index, which is why
your step 6 shows no diff.

If you want a pure tree-to-index comparison, use --cached (this will
also be slightly faster, as it does not have to stat the working tree at
all).

-Peff

  parent reply	other threads:[~2016-03-31 14:05 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-31 12:39 BUG in git diff-index Andy Lowry
2016-03-31 13:57 ` Carlos Martín Nieto
2016-03-31 14:05 ` Jeff King [this message]
2016-03-31 14:12   ` Andy Lowry
2016-03-31 14:27     ` Jeff King
2016-03-31 19:30       ` Andy Lowry
2016-03-31 20:39         ` Junio C Hamano
2017-09-26 19:46           ` Marc Herbert
2017-09-26 20:11             ` Eric Wong
2017-09-26 23:27               ` Google indexing https://public-inbox.org/git (was: BUG in git diff-index) Marc Herbert
2017-09-27 21:06             ` Wrong -dirty suffix set by setlocalversion " Marc Herbert
2018-05-24 23:03               ` Mike Mason
2018-05-25  3:50                 ` Marc Herbert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160331140515.GA31116@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=andy.work@nglowry.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).