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

Re: False positives in git diff-index

From
Jeff King <peff@peff.net>
Date
Jan 5, 2011, 05:48 UTC
Message-ID
<20110105054825.GC5884@sigill.intra.peff.net>
In-Reply-To
<AANLkTinDSCPz-oukxzn24hj94d9WpzZ8_64TBHeNTmoG@mail.gmail.com>
On Tue, Jan 04, 2011 at 12:45:33PM +0300, Alexander Gladysh wrote:
Show 23 quoted lines
> > Anyway, I'm ready to debug this issue if someone will guide me.
> >
> > Workflow:
> >
> > <...change files in /path/dir1/...>
> > (cd /path && git add </path/dir1/>)
> > (cd /path && git commit -m <message1>)
> >
> > ... repeat change-add-commit several times for various directories
> > (can be the same directory or not) ...
> >
> > <...generate file /path/dirN/foo...>
> > # Accidentally the file is generated the same as it was
> >
> > (cd /path && git add </path/dirN/>)
> > (cd /path && git status) # Refresh index
> > (cd /path && git diff-index --exit-code --quiet HEAD -- /path/dirN) #
> > Incorrectly reports that there are some changes
> > (cd /path && git commit -m <messageN>) # fails, saying that there is
> > nothing to commit
> >
> > If I insert sleep 10 between git status and git diff-index, the
> > problem goes away.

If adding a sleep makes it work, that sounds like a race condition in git. But from the description of your workflow, it should be easy to make a minimal example:

-- >8 -- #!/bin/sh

random() {
  perl -e 'print int(rand(5))+1, "\n"'
}

rm -rf repo mkdir repo && cd repo && git init

for i in 1 2 3 4 5; do
  mkdir dir$i
  echo initial >dir$i/file
done
git add .
git commit -m initial
while true; do
  for i in 1 2 3 4 5; do
    random >dir$i/file
    git add dir$i
    git update-index --refresh
    if ! git diff-index --exit-code --quiet HEAD -- dir$i; then
      if ! git commit -m foo; then
        echo breakage
        exit 1
      fi
    else
      echo not bothering to commit
    fi
  done
done
-- 8< --

Basically, we generate random data which has a 20% chance of being the same as what's there. When it is, we should get "not bothering to commit", but in your error case, we would try to commit (and get "no changes").

But using that script, I can't replicate your problem. Can you try running it on the same box you're having trouble with? That might at least tell us if it's your environment or something more complex going on.

-Peff
Previous: Alexander GladyshNext: Alexander Gladysh
Message 7 of 12 in “False positives in git diff-index”
  1. Alexander GladyshDec 27, 2010
  2. Alexander GladyshJan 4, 2011
  3. Zenaan HarknessJan 4, 2011
  4. Alexander GladyshJan 4, 2011
  5. Jakub NarebskiJan 4, 2011
  6. Alexander GladyshJan 4, 2011
  7. Jeff KingJan 5, 2011
  8. Alexander GladyshJan 5, 2011
  9. Jeff KingJan 5, 2011
  10. Alexander GladyshJan 5, 2011
  11. Jeff KingJan 5, 2011
  12. Alexander GladyshJan 6, 2011

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.