git stash: avoid data loss when "git stash save" kills a directory
commita73653130edd6a8977106d45a8092c09040f9132
authorPetr Baudis <pasky@ucw.cz>
Fri, 28 Jun 2013 15:05:32 +0000 (28 17:05 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 1 Jul 2013 21:23:24 +0000 (1 14:23 -0700)
treec76de88cc20570b9555b6a41e3429deee29fd247
parent26c986e118523fda4624cec8d14bb8a4a09fdd08
git stash: avoid data loss when "git stash save" kills a directory

"stash save" is about saving the local change to the working tree,
but also about restoring the state of the last commit to the working
tree.  When a local change is to turn a non-directory to a directory,
in order to restore the non-directory, everything in the directory
needs to be removed.

Which is fine when running "git stash save --include-untracked",
but without that option, untracked, newly created files in the
directory will have to be discarded, if the state you are restoring
to has a non-directory at the same path as the directory.

Introduce a safety valve to fail the operation in such case, using
the "ls-files --killed" which was designed for this exact purpose.

The "stash save" is stopped when untracked files need to be
discarded because their leading path ceased to be a directory, and
the user is required to pass --force to really have the data
removed.

Signed-off-by: Petr Baudis <pasky@ucw.cz>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-stash.txt
git-stash.sh
t/t3903-stash.sh