git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* possible bug of git stash deleting uncommitted files in corner case
@ 2016-04-22 11:46 Daniele Segato
  2016-04-22 11:48 ` Daniele Segato
  0 siblings, 1 reply; 6+ messages in thread
From: Daniele Segato @ 2016-04-22 11:46 UTC (permalink / raw)
  To: git

Hi,

my coworker today claimed git stash deleted his files, I made him
explain me what he did and I think it could actually be a bug even if
happening only in a corner case better explained with code to
reproduce:

git init
echo 'X' > foo
git add foo
git commit -m 'foo file committed'


what follow is the corner case I'm talking about: he deleted the file,
created a directory with THE SAME name and added lot of files in it,
in this example I'll only add one


rm foo
mkdir foo
echo 'B' > foo/bar


at this point the working directory looks like this:

 $ tree
.
└── foo
    └── bar

1 directory, 1 file


but apparently git status does not seem to see foo directory at all:


$ git status
On branch master
Changes not staged for commit:

          deleted:    foo

no changes added to commit (use "git add" and/or "git commit -a")


I expected something more like:


$ git status
On branch master
Changes not staged for commit:

          deleted: foo

Untracked files:

          foo/

no changes added to commit (use "git add" and/or "git commit -a")


Anyway he went on and decided to stash his work:


git stash


at this point stash deleted the "bar" file, in his case all the work
on the previous couple of hours, but he didn't know yet


$ git stash show stash@{0}
foo | 1 -
1 file changed, 1 deletion(-)


the foo directory was gone, replaced by the foo file


git stash pop


did not complained and deleted foo file again


I know my co-worker shouldn't had created a directory with the same
file he was deleting but I also think git shouldn't have allowed him
to stash at all, or should have been cleaver enough to actually stash
the directory with its files.


Regards,
Daniele Segato

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: possible bug of git stash deleting uncommitted files in corner case
  2016-04-22 11:46 possible bug of git stash deleting uncommitted files in corner case Daniele Segato
@ 2016-04-22 11:48 ` Daniele Segato
  2016-04-22 12:29   ` Remi Galan Alfonso
  0 siblings, 1 reply; 6+ messages in thread
From: Daniele Segato @ 2016-04-22 11:48 UTC (permalink / raw)
  To: git

sorry I forgot:

 $ git --version
git version 1.9.1


On Fri, Apr 22, 2016 at 1:46 PM, Daniele Segato
<daniele.segato@gmail.com> wrote:
> Hi,
>
> my coworker today claimed git stash deleted his files, I made him
> explain me what he did and I think it could actually be a bug even if
> happening only in a corner case better explained with code to
> reproduce:
>
> git init
> echo 'X' > foo
> git add foo
> git commit -m 'foo file committed'
>
>
> what follow is the corner case I'm talking about: he deleted the file,
> created a directory with THE SAME name and added lot of files in it,
> in this example I'll only add one
>
>
> rm foo
> mkdir foo
> echo 'B' > foo/bar
>
>
> at this point the working directory looks like this:
>
>  $ tree
> .
> └── foo
>     └── bar
>
> 1 directory, 1 file
>
>
> but apparently git status does not seem to see foo directory at all:
>
>
> $ git status
> On branch master
> Changes not staged for commit:
>
>           deleted:    foo
>
> no changes added to commit (use "git add" and/or "git commit -a")
>
>
> I expected something more like:
>
>
> $ git status
> On branch master
> Changes not staged for commit:
>
>           deleted: foo
>
> Untracked files:
>
>           foo/
>
> no changes added to commit (use "git add" and/or "git commit -a")
>
>
> Anyway he went on and decided to stash his work:
>
>
> git stash
>
>
> at this point stash deleted the "bar" file, in his case all the work
> on the previous couple of hours, but he didn't know yet
>
>
> $ git stash show stash@{0}
> foo | 1 -
> 1 file changed, 1 deletion(-)
>
>
> the foo directory was gone, replaced by the foo file
>
>
> git stash pop
>
>
> did not complained and deleted foo file again
>
>
> I know my co-worker shouldn't had created a directory with the same
> file he was deleting but I also think git shouldn't have allowed him
> to stash at all, or should have been cleaver enough to actually stash
> the directory with its files.
>
>
> Regards,
> Daniele Segato

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: possible bug of git stash deleting uncommitted files in corner case
  2016-04-22 11:48 ` Daniele Segato
@ 2016-04-22 12:29   ` Remi Galan Alfonso
  2016-04-22 17:37     ` Junio C Hamano
  0 siblings, 1 reply; 6+ messages in thread
From: Remi Galan Alfonso @ 2016-04-22 12:29 UTC (permalink / raw)
  To: Daniele Segato; +Cc: git

Daniele Segato <daniele.segato@gmail.com> wrote:
> git init
> echo 'X' > foo
> git add foo
> git commit -m 'foo file committed'
> 
> rm foo
> mkdir foo
> echo 'B' > foo/bar
> 
> # git status
> 
> git stash
> 
> at this point stash deleted the "bar" file, in his case all the work
> on the previous couple of hours, but he didn't know yet
> 
> the foo directory was gone, replaced by the foo file
> 
> git stash pop
> 
> did not complained and deleted foo file again
> 
> I know my co-worker shouldn't had created a directory with the same
> file he was deleting but I also think git shouldn't have allowed him
> to stash at all, or should have been clever enough to actually stash
> the directory with its files.

AFAIK it is a bug.
Without even going to the stash command,
    git init
    echo 'X' >foo
    git add foo
    git commit -m "Adding foo"
    rm foo
    mkdir foo
    echo 'B' >foo/bar
    git status
At this point the state is incorrect, the file foo/bar isn't there, as
you mentionned.

>  $ git --version
> git version 1.9.1

Contrary to what I expected, this seems to still be the case with:
  $ git --version
  git version 2.8.0.rc2

Being at $daywork right now, I am unable to test this any further.

Thanks,
Rémi

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: possible bug of git stash deleting uncommitted files in corner case
  2016-04-22 12:29   ` Remi Galan Alfonso
@ 2016-04-22 17:37     ` Junio C Hamano
  2016-04-22 19:04       ` Remi Galan Alfonso
  0 siblings, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2016-04-22 17:37 UTC (permalink / raw)
  To: Remi Galan Alfonso; +Cc: Daniele Segato, git

Remi Galan Alfonso <remi.galan-alfonso@ensimag.grenoble-inp.fr>
writes:

> Daniele Segato <daniele.segato@gmail.com> wrote:
> ...
>> git version 1.9.1
>
> Contrary to what I expected, this seems to still be the case with:
>   $ git --version
>   git version 2.8.0.rc2

I do not think "git stash" has been updated in any major way to
address correctness (including its corner case behaviour) ever since
it was originally written, so it is very likely that any bug you see
would be with it since the very old days.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: possible bug of git stash deleting uncommitted files in corner case
  2016-04-22 17:37     ` Junio C Hamano
@ 2016-04-22 19:04       ` Remi Galan Alfonso
  2016-04-23  3:53         ` Jeff King
  0 siblings, 1 reply; 6+ messages in thread
From: Remi Galan Alfonso @ 2016-04-22 19:04 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Daniele Segato, git

Junio C Hamano <gitster@pobox.com> writes:
> Remi Galan Alfonso <remi.galan-alfonso@ensimag.grenoble-inp.fr>
> writes:
> 
> > Daniele Segato <daniele.segato@gmail.com> wrote:
> > ...
> >> git version 1.9.1
> >
> > Contrary to what I expected, this seems to still be the case with:
> >   $ git --version
> >   git version 2.8.0.rc2
> 
> I do not think "git stash" has been updated in any major way to
> address correctness (including its corner case behaviour) ever since
> it was originally written, so it is very likely that any bug you see
> would be with it since the very old days.

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

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 am not sure what should be the correct behaviour here.
This however might be one of the corner cases you mentionned.

Thanks,
Rémi

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: possible bug of git stash deleting uncommitted files in corner case
  2016-04-22 19:04       ` Remi Galan Alfonso
@ 2016-04-23  3:53         ` Jeff King
  0 siblings, 0 replies; 6+ messages in thread
From: Jeff King @ 2016-04-23  3:53 UTC (permalink / raw)
  To: Remi Galan Alfonso; +Cc: Junio C Hamano, Daniele Segato, git

On Fri, Apr 22, 2016 at 09:04:25PM +0200, Remi Galan Alfonso wrote:

> 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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-04-23  3:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-22 11:46 possible bug of git stash deleting uncommitted files in corner case Daniele Segato
2016-04-22 11:48 ` Daniele Segato
2016-04-22 12:29   ` Remi Galan Alfonso
2016-04-22 17:37     ` Junio C Hamano
2016-04-22 19:04       ` Remi Galan Alfonso
2016-04-23  3:53         ` Jeff King

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).