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

Inconsistent result from git diff --quiet after untar'ing repo+working dir

From
GWGreg Ward <greg@gerg.ca>
Date
Sep 13, 2010, 01:24 UTC
Message-ID
<AANLkTikqrn0MKLFAt2D71fNyFkG1T3ncrrHx-LoSZLAH@mail.gmail.com>
Hi all --

I'm writing some automated tests that need a tiny git repo [1]. So I have a shell script create the repo + working dir and tar it up, then each test case untars the repo and does stuff inside it. The working dir deliberately has uncommitted changes and an untracked file.

Some of the test cases involve running "git diff --quiet", and I'm getting inconsistent results. Specifically, the first run after untar'ing the repo+working dir incorrectly reports no changes (exit status 0). Subsequent runs correctly report changes (exit status 1). Morever, if I run "git status" or regular non-quiet "git diff" first, then "git diff --quiet" correctly reports changes.

Here's my shell script to create the tiny test repo:

""" #!/bin/sh

# Output is git-repo.tar, which can be unpacked for each test -- that # way tests can modify the repo and/or working dir without harming # other tests.

set -ex rm -rf git-repo git init git-repo cd git-repo

# two files tracked by git echo a > a echo b > b git add -A git commit -m"add a, b"

# uncommitted change to b echo foo >> b

# some ignored files echo "*.o" > .git/info/exclude touch a.o

# an unknown file ("other" in git-speak) touch junk

cd .. tar -cf git-repo.tar git-repo rm -rf git-repo """

If you run that in a temp dir, you'll get git-repo.tar.  To reproduce the bug:
  $  tar -xf git-repo.tar
  $ cd git-repo
  $ git diff --quiet && echo "no changes" || echo "changes"
  no changes                    # WRONG
  $ git diff --quiet && echo "no changes" || echo "changes"
  changes                         # CORRECT
Or at least, that's what I'm getting running git 1.7.2.3 on Arch Linux x86_64.
Do I totally misunderstand things, or is there a bug here?
Thanks --
Greg

[1] this is for my vcprompt project, which prints info about the working dir for hg, git, svn, cvs, and bzr working dirs for use in your shell prompt: see http://hg.gerg.ca/vcprompt/ .

Message 1 of 1 in “Inconsistent result from git diff --quiet after untar'ing repo+working dir”
  1. Greg WardSep 13, 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.