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

Re: GIT_WORK_TREE=dir git ls-files --deleted

From
Jeff King <peff@peff.net>
Date
Mar 17, 2009, 09:03 UTC
Message-ID
<20090317090319.GM18475@coredump.intra.peff.net>
In-Reply-To
<201bac3a0903161841y6bc59fe5iaf0c221c08db5f43@mail.gmail.com>
On Tue, Mar 17, 2009 at 02:41:50AM +0100, Jonas Bernoulli wrote:
Show 8 quoted lines
> git ls-files --deleted seams to be broken when GIT_WORK_TREE is set as
> can be observed below.
> 
> Instead of just showing deleted files it also shows at least unchanged
> and modified files.
> 
> I have observed this behaviour with git.git and do not know if
> released versions are affected.

I don't think it has ever worked correctly. A fix is below, but I'm really unsure if it is right. It seems like we should be able to just refresh the index and see its status, rather than calling the lstat ourselves. But perhaps this is an optimization to avoid refresh (see builtin-ls-files.c, lines 186-202). Junio?

-- >8 --
Subject: [PATCH] ls-files: require worktree when --deleted is given

The code will end up calling lstat() to check whether the file still exists; obviously this doesn't work if we're not in the worktree.

Signed-off-by: Jeff King <peff@peff.net>
---
The version in next has the same bug, but the code is totally different
due to parseopt-ification (but the fix is still a one-liner to set
require_work_tree when show_deleted is set).
 builtin-ls-files.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/builtin-ls-files.c b/builtin-ls-files.c
index 9dec282..ca6f33d 100644
--- a/builtin-ls-files.c
+++ b/builtin-ls-files.c
@@ -419,6 +419,7 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
 		}
 		if (!strcmp(arg, "-d") || !strcmp(arg, "--deleted")) {
 			show_deleted = 1;
+			require_work_tree = 1;
 			continue;
 		}
 		if (!strcmp(arg, "-m") || !strcmp(arg, "--modified")) {
-- 
1.6.2.1.137.gb6aa78
Previous: Jonas Bernoulli
Message 2 of 2 in “GIT_WORK_TREE=dir git ls-files --deleted”
  1. Jonas BernoulliMar 17, 2009
  2. Jeff KingMar 17, 2009

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.