git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* git ls-files unreliable?
@ 2010-04-02 18:08 Gabor Gombas
  2010-04-02 20:54 ` Alex Riesen
  0 siblings, 1 reply; 2+ messages in thread
From: Gabor Gombas @ 2010-04-02 18:08 UTC (permalink / raw)
  To: git

Hi,

I want to verify from a script that the working directory is clean. Some
time ago Linus suggested to use "git diff --quiet --cached" followed by
"git ls-files --exclude-standard -o -d -m -u". But:

$ git status
# On branch git_workdir_check
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   ../../../test
#
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working
#   directory)
#
#       modified:   ../../../test
#
$ git ls-files --exclude-standard -o -d -m -u
$ echo $?
0

So there _were_ uncommitted changes, "git status" showed them, but "git
ls-files" did not. Unstaging the staged changes did not help, changing a
different file did not help. Tried git versions 1.5.4.2 and 1.7.0-rc2,
both showed the same behavior.

When I did a "commit" and changed a file after that, then ls-files
started to take notice. I don't know how to reproduce the state shown
above. But this means that I cannot rely on "git ls-files" to check if
the working directory is clean; so what should I use instead?
Restriction: any solutions must work with git versions as old as 1.5.4.

Gabor

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: git ls-files unreliable?
  2010-04-02 18:08 git ls-files unreliable? Gabor Gombas
@ 2010-04-02 20:54 ` Alex Riesen
  0 siblings, 0 replies; 2+ messages in thread
From: Alex Riesen @ 2010-04-02 20:54 UTC (permalink / raw)
  To: git

On Fri, Apr 2, 2010 at 20:08, Gabor Gombas <gombasg@digikabel.hu> wrote:
> Hi,
>
> I want to verify from a script that the working directory is clean. Some
> time ago Linus suggested to use "git diff --quiet --cached" followed by

In your script, you seem to have missed the "diff" part

> "git ls-files --exclude-standard -o -d -m -u". But:
>
> $ git status
> # On branch git_workdir_check
> # Your branch is ahead of 'origin/master' by 1 commit.
> #
> # Changes to be committed:
> #   (use "git reset HEAD <file>..." to unstage)
> #
> #       modified:   ../../../test
> #
> # Changed but not updated:
> #   (use "git add <file>..." to update what will be committed)
> #   (use "git checkout -- <file>..." to discard changes in working
> #   directory)
> #
> #       modified:   ../../../test
> #

Here. Were is your call to "git diff --cached"?

> $ git ls-files --exclude-standard -o -d -m -u
> $ echo $?
> 0

This is correct.

> So there _were_ uncommitted changes, "git status" showed them, but "git
> ls-files" did not.

Because it is not supposed to. The command "git ls-files" just shows
the files not known to git. You have to parse the output. Not that it
is complicated in this particular case: you consider the workdir unclean
on any output.

> Restriction: any solutions must work with git versions as old as 1.5.4.

It probably will, but please check "git diff --cached" exit code.
It may be always 0, in which case you'll have to fallback to
output parsing here too.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-04-02 20:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-02 18:08 git ls-files unreliable? Gabor Gombas
2010-04-02 20:54 ` Alex Riesen

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 NNTP newsgroup(s).