{"thread":{"id":"23465","subject":"[PATCH 1/2] (resend) stash bug: stash can lose data in a file removed from the index","startedAt":"2010-04-15T00:24:21Z","lastAt":"2010-04-15T07:38:56Z","messageCount":4,"participants":["Charles Bailey","Thomas Rast","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"139532","messageId":"1271291062-32154-1-git-send-email-charles@hashpling.org","threadId":"23465","inReplyTo":null,"subject":"[PATCH 1/2] (resend) stash bug: stash can lose data in a file removed from the index","fromName":"Charles Bailey","fromEmail":"charles@hashpling.org","sentAt":"2010-04-15T00:24:21Z","receivedAt":"2010-04-15T00:24:21Z","isPatch":true,"sender":{"key":"charles@hashpling.org","avatar":"https://avatars.githubusercontent.com/u/1668475?v=4"},"body":"If a file is removed from the index and then modified in the working\ntree then stash will discard the working tree file with no way to\nrecover the changes.\n\nThis can might be done in one of a number of ways.\n\ngit rm file\nvi file              # edit a new version\ngit stash\n\nor with git mv\n\ngit mv file newfile\nvi file              # make a new file with the old name\ngit stash\n\nSigned-off-by: Charles Bailey <charles@hashpling.org>\n---\n t/t3903-stash.sh |    9 +++++++++\n 1 files changed, 9 insertions(+), 0 deletions(-)\n\ndiff --git a/t/t3903-stash.sh b/t/t3903-stash.sh\nindex 476e5ec..c85bf44 100755\n--- a/t/t3903-stash.sh\n+++ b/t/t3903-stash.sh\n@@ -228,4 +228,13 @@ test_expect_success 'stash --invalid-option' '\n \ttest bar,bar2 = $(cat file),$(cat file2)\n '\n \n+test_expect_failure 'stash git rm' '\n+    git reset --hard &&\n+\tgit rm file &&\n+\techo bar7 > file &&\n+\tgit stash &&\n+\tgit stash apply &&\n+\ttest bar7 = $(cat file)\n+'\n+\n test_done\n-- \n1.7.1.rc1.241.g4e72f\n"},{"id":"139533","messageId":"1271291062-32154-2-git-send-email-charles@hashpling.org","threadId":"23465","inReplyTo":"1271291062-32154-1-git-send-email-charles@hashpling.org","subject":"[PATCH 2/2] (resend) stash: Don't overwrite files that have gone from the index","fromName":"Charles Bailey","fromEmail":"charles@hashpling.org","sentAt":"2010-04-15T00:24:22Z","receivedAt":"2010-04-15T00:24:22Z","isPatch":true,"sender":{"key":"charles@hashpling.org","avatar":"https://avatars.githubusercontent.com/u/1668475?v=4"},"body":"---\n\nThis patch is deliberately not signed off. It feels kludgy and uses a\nnon-portable xargs invocation.\n\nIt is designed as a starting point for discussion, that is all.\n\n git-stash.sh |    2 ++\n 1 files changed, 2 insertions(+), 0 deletions(-)\n\ndiff --git a/git-stash.sh b/git-stash.sh\nindex 908aab2..9efc544 100755\n--- a/git-stash.sh\n+++ b/git-stash.sh\n@@ -87,6 +87,8 @@ create_stash () {\n \t\t\texport GIT_INDEX_FILE &&\n \t\t\tgit read-tree -m $i_tree &&\n \t\t\tgit add -u &&\n+\t\t\t{ git diff --quiet --diff-filter=D --cached ||\n+\t\t\t\tgit diff -z --name-only --diff-filter=D --cached | xargs -0 git add --ignore-errors; } &&\n \t\t\tgit write-tree &&\n \t\t\trm -f \"$TMP-index\"\n \t\t) ) ||\n-- \n1.7.1.rc1.241.g4e72f\n"},{"id":"139560","messageId":"201004150933.41330.trast@student.ethz.ch","threadId":"23465","inReplyTo":"1271291062-32154-2-git-send-email-charles@hashpling.org","subject":"Re: [PATCH 2/2] (resend) stash: Don't overwrite files that have gone from the index","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2010-04-15T07:33:40Z","receivedAt":"2010-04-15T07:33:40Z","isPatch":true,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"Charles Bailey wrote:\n> diff --git a/git-stash.sh b/git-stash.sh\n> index 908aab2..9efc544 100755\n> --- a/git-stash.sh\n> +++ b/git-stash.sh\n> @@ -87,6 +87,8 @@ create_stash () {\n>  \t\t\texport GIT_INDEX_FILE &&\n>  \t\t\tgit read-tree -m $i_tree &&\n>  \t\t\tgit add -u &&\n> +\t\t\t{ git diff --quiet --diff-filter=D --cached ||\n> +\t\t\t\tgit diff -z --name-only --diff-filter=D --cached | xargs -0 git add --ignore-errors; } &&\n\nI think you'll also have to turn it into an 'add -f' invocation since\nthe file in question could conceivably have been ignored-but-tracked,\nand straight 'add' would refuse to re-track it.\n\n(No, I don't have any good ideas on how to get rid of xargs short of\nsome shell loop...)\n\n-- \nThomas Rast\ntrast@{inf,student}.ethz.ch\n"},{"id":"139562","messageId":"20100415073856.GC27542@coredump.intra.peff.net","threadId":"23465","inReplyTo":"201004150933.41330.trast@student.ethz.ch","subject":"Re: [PATCH 2/2] (resend) stash: Don't overwrite files that have gone from the index","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-04-15T07:38:56Z","receivedAt":"2010-04-15T07:38:56Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Apr 15, 2010 at 09:33:40AM +0200, Thomas Rast wrote:\n\n> Charles Bailey wrote:\n> > diff --git a/git-stash.sh b/git-stash.sh\n> > index 908aab2..9efc544 100755\n> > --- a/git-stash.sh\n> > +++ b/git-stash.sh\n> > @@ -87,6 +87,8 @@ create_stash () {\n> >  \t\t\texport GIT_INDEX_FILE &&\n> >  \t\t\tgit read-tree -m $i_tree &&\n> >  \t\t\tgit add -u &&\n> > +\t\t\t{ git diff --quiet --diff-filter=D --cached ||\n> > +\t\t\t\tgit diff -z --name-only --diff-filter=D --cached | xargs -0 git add --ignore-errors; } &&\n> \n> I think you'll also have to turn it into an 'add -f' invocation since\n> the file in question could conceivably have been ignored-but-tracked,\n> and straight 'add' would refuse to re-track it.\n> \n> (No, I don't have any good ideas on how to get rid of xargs short of\n> some shell loop...)\n\nIt should probably use update-index, which has a --stdin mode, and which\ndoesn't care about ignores.\n\n-Peff\n\nPS I have not looked carefully into this issue yet, so I don't know if\n   the patch actually does the right thing or not.\n"}]}