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

Re: git ls-files unreliable?

From
Alex Riesen <raa.lkml@gmail.com>
Date
Apr 2, 2010, 20:54 UTC
Message-ID
<n2p81b0412b1004021354z1ca4f6b4sa4400b484d97b46e@mail.gmail.com>
In-Reply-To
<20100402180842.GA5798@twister.home>
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
Show 18 quoted lines
> "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.

Previous: Gabor Gombas
Message 2 of 2 in “git ls-files unreliable?”
  1. Gabor GombasApr 2, 2010
  2. Alex RiesenApr 2, 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.