diff options
author | Petr Baudis <pasky@ucw.cz> | 2013-06-28 17:05:32 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2013-07-01 14:23:24 -0700 |
commit | a73653130edd6a8977106d45a8092c09040f9132 (patch) | |
tree | c76de88cc20570b9555b6a41e3429deee29fd247 /t/t3903-stash.sh | |
parent | 26c986e118523fda4624cec8d14bb8a4a09fdd08 (diff) | |
download | git-a73653130edd6a8977106d45a8092c09040f9132.tar.gz |
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>
Diffstat (limited to 't/t3903-stash.sh')
-rwxr-xr-x | t/t3903-stash.sh | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh index debda7a678..5d22f17ca2 100755 --- a/t/t3903-stash.sh +++ b/t/t3903-stash.sh @@ -673,4 +673,22 @@ test_expect_success 'store updates stash ref and reflog' ' grep quux bazzy ' +test_expect_success 'stash a change to turn a non-directory to a directory' ' + git reset --hard && + >testfile && + git add testfile && + git commit -m "add testfile as a regular file" && + rm testfile && + mkdir testfile && + >testfile/file && + test_must_fail git stash save "recover regular file" && + test -f testfile/file +' + +test_expect_success 'stash a change to turn a non-directory to a directory (forced)' ' + git stash save --force "recover regular file (forced)" && + ! test -f testfile/file && + test -f testfile +' + test_done |