{"thread":{"id":"18336","subject":"GIT_WORK_TREE=dir git ls-files --deleted","startedAt":"2009-03-17T01:41:50Z","lastAt":"2009-03-17T09:03:19Z","messageCount":2,"participants":["Jonas Bernoulli","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"108171","messageId":"201bac3a0903161841y6bc59fe5iaf0c221c08db5f43@mail.gmail.com","threadId":"18336","inReplyTo":null,"subject":"GIT_WORK_TREE=dir git ls-files --deleted","fromName":"Jonas Bernoulli","fromEmail":"jonas@bernoul.li","sentAt":"2009-03-17T01:41:50Z","receivedAt":"2009-03-17T01:41:50Z","isPatch":false,"sender":{"key":"jonas@bernoul.li","avatar":"https://gravatar.com/avatar/67252b2d3a6aacebe15776a6c0cb26c78b475dedc8410caa8765f1f4953222aa?d=mp&s=160"},"body":"Hello\n\ngit ls-files --deleted seams to be broken when GIT_WORK_TREE is set as\ncan be observed below.\n\nInstead of just showing deleted files it also shows at least unchanged\nand modified files.\n\nI have observed this behaviour with git.git and do not know if\nreleased versions are affected.\n\n#### setup\n\n$ mkdir -p base/worktree\n$ cd base/\n$ export GIT_DIR=/tmp/base/.git\n$ export GIT_WORK_TREE=/tmp/base/worktree\n$ git init\nInitialized empty Git repository in /tmp/base/.git/\n$ touch worktree/deleted worktree/modified worktree/unchanged\n$ git add .\n$ git commit -m init\n[master (root-commit) f4e1bd3] init\n 0 files changed, 0 insertions(+), 0 deletions(-)\n create mode 100644 deleted\n create mode 100644 modified\n create mode 100644 unchanged\n$ rm worktree/deleted\n$ echo modified > worktree/modified\n\n#### expected result\n\n$ git ls-files --deleted\ndeleted\n\n#### actual result\n\n$ git ls-files --deleted\ndeleted\nmodified\nunchanged\n\n#### untracked and out-of-worktree seam to be fine\n\n$ touch worktree/untracked\n$ touch not-in-worktree\n$ git ls-files --deleted\ndeleted\nmodified\nunchanged\n\n#### related options / commands seam to be fine\n\n$ git ls-files --modified\ndeleted\nmodified\n$ git ls-files --others\n$ git ls-files --cached\ndeleted\nmodified\nunchanged\n$ git status\n# On branch master\n# Changed but not updated:\n#   (use \"git add/rm <file>...\" to update what will be committed)\n#   (use \"git checkout -- <file>...\" to discard changes in working directory)\n#\n#       deleted:    deleted\n#       modified:   modified\n#\nno changes added to commit (use \"git add\" and/or \"git commit -a\")\n\nBest regards,\n\n-- Jonas Bernoulli\n\nPs: Is there a way to show modified files excluding deleted files\nother than this?\n( git ls-files --deleted; git ls-files --modified ) | uniq --unique\nPps: The description of --others is ambitious, what is \"other files\"?\n"},{"id":"108200","messageId":"20090317090319.GM18475@coredump.intra.peff.net","threadId":"18336","inReplyTo":"201bac3a0903161841y6bc59fe5iaf0c221c08db5f43@mail.gmail.com","subject":"Re: GIT_WORK_TREE=dir git ls-files --deleted","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-03-17T09:03:19Z","receivedAt":"2009-03-17T09:03:19Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Mar 17, 2009 at 02:41:50AM +0100, Jonas Bernoulli wrote:\n\n> git ls-files --deleted seams to be broken when GIT_WORK_TREE is set as\n> can be observed below.\n> \n> Instead of just showing deleted files it also shows at least unchanged\n> and modified files.\n> \n> I have observed this behaviour with git.git and do not know if\n> released versions are affected.\n\nI don't think it has ever worked correctly. A fix is below, but I'm\nreally unsure if it is right. It seems like we should be able to just\nrefresh the index and see its status, rather than calling the lstat\nourselves. But perhaps this is an optimization to avoid refresh (see\nbuiltin-ls-files.c, lines 186-202). Junio?\n\n-- >8 --\nSubject: [PATCH] ls-files: require worktree when --deleted is given\n\nThe code will end up calling lstat() to check whether the\nfile still exists; obviously this doesn't work if we're not\nin the worktree.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\nThe version in next has the same bug, but the code is totally different\ndue to parseopt-ification (but the fix is still a one-liner to set\nrequire_work_tree when show_deleted is set).\n\n builtin-ls-files.c |    1 +\n 1 files changed, 1 insertions(+), 0 deletions(-)\n\ndiff --git a/builtin-ls-files.c b/builtin-ls-files.c\nindex 9dec282..ca6f33d 100644\n--- a/builtin-ls-files.c\n+++ b/builtin-ls-files.c\n@@ -419,6 +419,7 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)\n \t\t}\n \t\tif (!strcmp(arg, \"-d\") || !strcmp(arg, \"--deleted\")) {\n \t\t\tshow_deleted = 1;\n+\t\t\trequire_work_tree = 1;\n \t\t\tcontinue;\n \t\t}\n \t\tif (!strcmp(arg, \"-m\") || !strcmp(arg, \"--modified\")) {\n-- \n1.6.2.1.137.gb6aa78\n"}]}