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

Re: possible bug of git stash deleting uncommitted files in corner case

From
Jeff King <peff@peff.net>
Date
Apr 23, 2016, 03:53 UTC
Message-ID
<20160423035312.GB15994@sigill.intra.peff.net>
In-Reply-To
<754076461.4029096.1461351865455.JavaMail.zimbra@ensimag.grenoble-inp.fr>
On Fri, Apr 22, 2016 at 09:04:25PM +0200, Remi Galan Alfonso wrote:
Show 24 quoted lines
> For this bug it doesn't seem to be specifically linked to git stash,
> since 'git status' doesn't display correct informations in the first
> place (it doesn't show foo/bar as an untracked file).
> 
> I tried something quickly, based on Daniele's case:
>     git init
>     echo 'X' >foo
>     git add foo
>     git commit -m "Added foo"
>     rm foo
>     mkdir foo
>     echo 'B' >foo/bar
> 
>     git status # foo/bar not shown in Untracked files
> 
>     git add foo/bar
> 
> git status then shows as expected:
> # On branch master
> # Changes to be committed:
> #   (use "git reset HEAD <file>..." to unstage)
> # 
> # 	deleted:    foo
> # 	new file:   foo/bar

Before you "git add foo/bar", try "git status -uall", which asks git to descend into directories when looking for untracked files. It _does_ show foo/bar as untracked.

So I think what is happening is that in the case without "-uall", we see "foo" as an untracked file, but then check that with the index to say "ah, it is not untracked, there is an entry in the index". But of course the earlier mention in "not staged for commit" will not say anything about the new directory "foo", because we only diff actual files there.

Likewise, if you ask "ls-files -o", it mentions "foo/bar".

So I think the bug is in the way dir.c handles DIR_SHOW_OTHER_DIRECTORIES, or possibly in the way that wt_status_collect_untracked handles its results.

It may be that the latter needs to special-case its cache_name_is_other() check, and make sure we mention an "other" file we found that is a directory, even if it has an index entry.

> However git stash fails this time:
> # error: foo: is a directory - add individual files instead
> # fatal: Unable to process path foo
> # Cannot save the current worktree state

I suspect the actual stash bug is separate from the bug above. It just looks like update-index is not smart enough to realize that a file being replaced with a directory is effectively an index deletion of that entry. That's just a guess, though.

-Peff
Previous: Remi Galan Alfonso
Message 6 of 6 in “possible bug of git stash deleting uncommitted files in corner case”
  1. Daniele SegatoApr 22, 2016
  2. Daniele SegatoApr 22, 2016
  3. Remi Galan AlfonsoApr 22, 2016
  4. Junio C HamanoApr 22, 2016
  5. Remi Galan AlfonsoApr 22, 2016
  6. Jeff KingApr 23, 2016

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.