{"thread":{"id":"23305","subject":"git ls-files unreliable?","startedAt":"2010-04-02T18:08:43Z","lastAt":"2010-04-02T20:54:28Z","messageCount":2,"participants":["Gabor Gombas","Alex Riesen"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"138446","messageId":"20100402180842.GA5798@twister.home","threadId":"23305","inReplyTo":null,"subject":"git ls-files unreliable?","fromName":"Gabor Gombas","fromEmail":"gombasg@digikabel.hu","sentAt":"2010-04-02T18:08:43Z","receivedAt":"2010-04-02T18:08:43Z","isPatch":false,"sender":{"key":"gombasg@digikabel.hu","avatar":null},"body":"Hi,\n\nI want to verify from a script that the working directory is clean. Some\ntime ago Linus suggested to use \"git diff --quiet --cached\" followed by\n\"git ls-files --exclude-standard -o -d -m -u\". But:\n\n$ git status\n# On branch git_workdir_check\n# Your branch is ahead of 'origin/master' by 1 commit.\n#\n# Changes to be committed:\n#   (use \"git reset HEAD <file>...\" to unstage)\n#\n#       modified:   ../../../test\n#\n# Changed but not updated:\n#   (use \"git add <file>...\" to update what will be committed)\n#   (use \"git checkout -- <file>...\" to discard changes in working\n#   directory)\n#\n#       modified:   ../../../test\n#\n$ git ls-files --exclude-standard -o -d -m -u\n$ echo $?\n0\n\nSo there _were_ uncommitted changes, \"git status\" showed them, but \"git\nls-files\" did not. Unstaging the staged changes did not help, changing a\ndifferent file did not help. Tried git versions 1.5.4.2 and 1.7.0-rc2,\nboth showed the same behavior.\n\nWhen I did a \"commit\" and changed a file after that, then ls-files\nstarted to take notice. I don't know how to reproduce the state shown\nabove. But this means that I cannot rely on \"git ls-files\" to check if\nthe working directory is clean; so what should I use instead?\nRestriction: any solutions must work with git versions as old as 1.5.4.\n\nGabor\n"},{"id":"138461","messageId":"n2p81b0412b1004021354z1ca4f6b4sa4400b484d97b46e@mail.gmail.com","threadId":"23305","inReplyTo":"20100402180842.GA5798@twister.home","subject":"Re: git ls-files unreliable?","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2010-04-02T20:54:28Z","receivedAt":"2010-04-02T20:54:28Z","isPatch":false,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"On Fri, Apr 2, 2010 at 20:08, Gabor Gombas <gombasg@digikabel.hu> wrote:\n> Hi,\n>\n> I want to verify from a script that the working directory is clean. Some\n> time ago Linus suggested to use \"git diff --quiet --cached\" followed by\n\nIn your script, you seem to have missed the \"diff\" part\n\n> \"git ls-files --exclude-standard -o -d -m -u\". But:\n>\n> $ git status\n> # On branch git_workdir_check\n> # Your branch is ahead of 'origin/master' by 1 commit.\n> #\n> # Changes to be committed:\n> #   (use \"git reset HEAD <file>...\" to unstage)\n> #\n> #       modified:   ../../../test\n> #\n> # Changed but not updated:\n> #   (use \"git add <file>...\" to update what will be committed)\n> #   (use \"git checkout -- <file>...\" to discard changes in working\n> #   directory)\n> #\n> #       modified:   ../../../test\n> #\n\nHere. Were is your call to \"git diff --cached\"?\n\n> $ git ls-files --exclude-standard -o -d -m -u\n> $ echo $?\n> 0\n\nThis is correct.\n\n> So there _were_ uncommitted changes, \"git status\" showed them, but \"git\n> ls-files\" did not.\n\nBecause it is not supposed to. The command \"git ls-files\" just shows\nthe files not known to git. You have to parse the output. Not that it\nis complicated in this particular case: you consider the workdir unclean\non any output.\n\n> Restriction: any solutions must work with git versions as old as 1.5.4.\n\nIt probably will, but please check \"git diff --cached\" exit code.\nIt may be always 0, in which case you'll have to fallback to\noutput parsing here too.\n"}]}