{"thread":{"id":"22653","subject":"git stash pop not reapplying deletions","startedAt":"2010-02-14T19:45:03Z","lastAt":"2010-02-16T02:17:44Z","messageCount":8,"participants":["Steve Folly","Thomas Rast","Stephen Boyd","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"134565","messageId":"loom.20100214T200110-615@post.gmane.org","threadId":"22653","inReplyTo":null,"subject":"git stash pop not reapplying deletions","fromName":"Steve Folly","fromEmail":"steve@spfweb.co.uk","sentAt":"2010-02-14T19:45:03Z","receivedAt":"2010-02-14T19:45:03Z","isPatch":false,"sender":{"key":"steve@spfweb.co.uk","avatar":null},"body":"Hi,\n\nI'm not sure if I've found a bug in 'git stash' or if I'm using \nit the wrong way? (This is with git 1.6.6):\n\n$ git init stashtest\n$ cd stashtest\n$ mkdir dira\n$ touch dira/a dira/b dira/c\n$ git stage dira\n$ git commit -m \"added dira\"\n$ git mv dira dirb\n$ git status   # correctly shows renames\n\n# On branch master\n# Changes to be committed:\n#   (use \"git reset HEAD <file>...\" to unstage)\n#\n#\trenamed:    dira/a -> dirb/a\n#\trenamed:    dira/b -> dirb/b\n#\trenamed:    dira/c -> dirb/c\n#\n\n$ git stash\n$ git stash pop\n\n# On branch master\n# Changes to be committed:\n#   (use \"git reset HEAD <file>...\" to unstage)\n#\n#\tnew file:   dirb/a\n#\tnew file:   dirb/b\n#\tnew file:   dirb/c\n#\n# Changed but not updated:\n#   (use \"git add/rm <file>...\" to update what will be \ncommitted)\n#   (use \"git checkout -- <file>...\" to discard changes in working directory)\n#\n#\tdeleted:    dira/a\n#\tdeleted:    dira/b\n#\tdeleted:    dira/c\n#\nDropped refs/stash@{0} (cf9efdede3a3ee8e078192b574520fd2ed7f3d9b)\n\nIt's added the new files in dirb but hasn't deleted the old files in dira. Is\nthis right?\n\nRegards,\nSteve\n"},{"id":"134579","messageId":"201002142308.01704.trast@student.ethz.ch","threadId":"22653","inReplyTo":"loom.20100214T200110-615@post.gmane.org","subject":"Re: git stash pop not reapplying deletions","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2010-02-14T22:08:01Z","receivedAt":"2010-02-14T22:08:01Z","isPatch":false,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"On Sunday 14 February 2010 20:45:03 Steve Folly wrote:\n> \n> I'm not sure if I've found a bug in 'git stash' or if I'm using \n> it the wrong way? (This is with git 1.6.6):\n> \n[eliding a lot everywhere to make it clearer]\n> $ git status   # correctly shows renames\n> #\trenamed:    dira/a -> dirb/a\n> #\trenamed:    dira/b -> dirb/b\n> #\trenamed:    dira/c -> dirb/c\n> $ git stash\n> $ git stash pop\n> # Changes to be committed:\n> #\tnew file:   dirb/a\n> #\tnew file:   dirb/b\n> #\tnew file:   dirb/c\n> # Changed but not updated:\n> #\tdeleted:    dira/a\n> #\tdeleted:    dira/b\n> #\tdeleted:    dira/c\n\nThe problem is that you aren't using --index, but still expecting it\nto restore your index.  If you change it to 'git stash pop --index',\neverything will work as expected.\n\nYes, it does stage new files, but that is only to help you: otherwise\nyou could forget them before committing.\n\n-- \nThomas Rast\ntrast@{inf,student}.ethz.ch\n"},{"id":"134643","messageId":"loom.20100215T152932-38@post.gmane.org","threadId":"22653","inReplyTo":"201002142308.01704.trast@student.ethz.ch","subject":"Re: git stash pop not reapplying deletions","fromName":"Steve Folly","fromEmail":"steve@spfweb.co.uk","sentAt":"2010-02-15T14:32:44Z","receivedAt":"2010-02-15T14:32:44Z","isPatch":false,"sender":{"key":"steve@spfweb.co.uk","avatar":null},"body":"Thomas Rast <trast <at> student.ethz.ch> writes:\n\n> \n> On Sunday 14 February 2010 20:45:03 Steve Folly wrote:\n> > \n> > I'm not sure if I've found a bug in 'git stash' or if I'm using \n> > it the wrong way? (This is with git 1.6.6):\n> > \n> [eliding a lot everywhere to make it clearer]\n> > $ git status   # correctly shows renames\n> > #\trenamed:    dira/a -> dirb/a\n> > #\trenamed:    dira/b -> dirb/b\n> > #\trenamed:    dira/c -> dirb/c\n> > $ git stash\n> > $ git stash pop\n> > # Changes to be committed:\n> > #\tnew file:   dirb/a\n> > #\tnew file:   dirb/b\n> > #\tnew file:   dirb/c\n> > # Changed but not updated:\n> > #\tdeleted:    dira/a\n> > #\tdeleted:    dira/b\n> > #\tdeleted:    dira/c\n> \n> The problem is that you aren't using --index, but still expecting it\n> to restore your index.  If you change it to 'git stash pop --index',\n> everything will work as expected.\n\nOK, yep - got it. Thanks.\n \n> Yes, it does stage new files, but that is only to help you: otherwise\n> you could forget them before committing.\n> \n\nBut that's even more confusing - not using --index only \nrestores *some* of the index. To be honest, \nthat's not really helping - I still have to stage deletions \nmanually.\n\nIf not using --index isn't supposed to restore the index, \nthen surely it shouldn't be staging the new files?\n\n\nCheers\nSteve\n"},{"id":"134645","messageId":"201002151641.19694.trast@student.ethz.ch","threadId":"22653","inReplyTo":"loom.20100215T152932-38@post.gmane.org","subject":"Re: git stash pop not reapplying deletions","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2010-02-15T15:41:19Z","receivedAt":"2010-02-15T15:41:19Z","isPatch":false,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"Please don't remove the Cc list, it helps us (among other things) flag\nthe mail that is important.\n\nOn Monday 15 February 2010 15:32:44 Steve Folly wrote:\n> Thomas Rast <trast <at> student.ethz.ch> writes:\n> > Yes, [git stash without --index] does stage new files, but that is\n> > only to help you: otherwise you could forget them before\n> > committing.\n> \n> But that's even more confusing - not using --index only \n> restores *some* of the index. To be honest, \n> that's not really helping - I still have to stage deletions \n> manually.\n> \n> If not using --index isn't supposed to restore the index, \n> then surely it shouldn't be staging the new files?\n\nNot sure.  I personally prefer the behaviour as it is now, as I have\nstatus.showUntrackedFiles = no and would most likely forget about\nthem.  It has been that way since the introduction of git-stash, so\nmaybe Nanako (Cc'd) can enlighten us further.\n\nThat being said, it could probably be made configurable along the\nlines of the patch below, or even with a config option.\n\n\ndiff --git i/git-stash.sh w/git-stash.sh\nindex 3a0685f..fc56e1b 100755\n--- i/git-stash.sh\n+++ w/git-stash.sh\n@@ -222,12 +222,26 @@ show_stash () {\n \n apply_stash () {\n \tunstash_index=\n+\tdont_touch_index=\n \n \twhile test $# != 0\n \tdo\n \t\tcase \"$1\" in\n \t\t--index)\n \t\t\tunstash_index=t\n+\t\t\tdont_touch_index=\n+\t\t\t;;\n+\t\t--index=apply)\n+\t\t\tunstash_index=t\n+\t\t\tdont_touch_index=\n+\t\t\t;;\n+\t\t--index=added-only)\n+\t\t\tunstash_index=\n+\t\t\tdont_touch_index=\n+\t\t\t;;\n+\t\t--index=none)\n+\t\t\tunstash_index=\n+\t\t\tdont_touch_index=t\n \t\t\t;;\n \t\t-q|--quiet)\n \t\t\tGIT_QUIET=t\n@@ -293,7 +307,7 @@ apply_stash () {\n \t\t\ta=\"$TMP-added\" &&\n \t\t\tgit diff-index --cached --name-only --diff-filter=A $c_tree >\"$a\" &&\n \t\t\tgit read-tree --reset $c_tree &&\n-\t\t\tgit update-index --add --stdin <\"$a\" ||\n+\t\t\t(test -n \"$dont_touch_index\" || git update-index --add --stdin <\"$a\") ||\n \t\t\t\tdie \"Cannot unstage modified files\"\n \t\t\trm -f \"$a\"\n \t\tfi\n\n-- \nThomas Rast\ntrast@{inf,student}.ethz.ch\n"},{"id":"134647","messageId":"2927b3dc67ab0b9067d4fe849e85654125706b91.1266249586.git.trast@student.ethz.ch","threadId":"22653","inReplyTo":"201002151641.19694.trast@student.ethz.ch","subject":"[PATCH] stash pop: remove 'apply' options during 'drop' invocation","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2010-02-15T16:01:57Z","receivedAt":"2010-02-15T16:01:57Z","isPatch":true,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"The 'git stash pop' option parsing used to remove the first argument\nin --index mode.  At the time this was implemented, this first\nargument was always --index.  However, since the invention of the -q\noption in fcdd0e9 (stash: teach quiet option, 2009-06-17) 'git stash\npop') you can cause an internal invocation of\n\n  git stash drop --index\n\nby running\n\n  git stash pop -q --index\n\nwhich then of course fails because drop doesn't know --index.\n\nTo handle this, instead let 'git stash apply' decide what the future\nargument to 'drop' should be.\n\nWarning: this means that 'git stash apply' must parse all options that\n'drop' can take, and deal with them in the same way.  This is\ncurrently true for its only option -q.\n\nSigned-off-by: Thomas Rast <trast@student.ethz.ch>\n---\n\nNoticed this while whipping up the draft patch.  I'm trading one\nmaintainability problem (that bit us) for another (that hasn't...\nyet), but I'm scared to try properly filtering the arguments in sh.\n\n\n git-stash.sh     |    7 +++++--\n t/t3903-stash.sh |    9 +++++++++\n 2 files changed, 14 insertions(+), 2 deletions(-)\n\ndiff --git a/git-stash.sh b/git-stash.sh\nindex 3a0685f..2d69196 100755\n--- a/git-stash.sh\n+++ b/git-stash.sh\n@@ -221,6 +221,7 @@ show_stash () {\n }\n \n apply_stash () {\n+\tapplied_stash=\n \tunstash_index=\n \n \twhile test $# != 0\n@@ -242,6 +243,9 @@ apply_stash () {\n \tif test $# = 0\n \tthen\n \t\thave_stash || die 'Nothing to apply'\n+\t\tapplied_stash=\"$ref_stash@{0}\"\n+\telse\n+\t\tapplied_stash=\"$*\"\n \tfi\n \n \t# stash records the work tree, and is a merge between the\n@@ -415,8 +419,7 @@ pop)\n \tshift\n \tif apply_stash \"$@\"\n \tthen\n-\t\ttest -z \"$unstash_index\" || shift\n-\t\tdrop_stash \"$@\"\n+\t\tdrop_stash \"$applied_stash\"\n \tfi\n \t;;\n branch)\ndiff --git a/t/t3903-stash.sh b/t/t3903-stash.sh\nindex 5514f74..476e5ec 100755\n--- a/t/t3903-stash.sh\n+++ b/t/t3903-stash.sh\n@@ -194,6 +194,15 @@ test_expect_success 'pop -q is quiet' '\n \ttest ! -s output.out\n '\n \n+test_expect_success 'pop -q --index works and is quiet' '\n+\techo foo > file &&\n+\tgit add file &&\n+\tgit stash save --quiet &&\n+\tgit stash pop -q --index > output.out 2>&1 &&\n+\ttest foo = \"$(git show :file)\" &&\n+\ttest ! -s output.out\n+'\n+\n test_expect_success 'drop -q is quiet' '\n \tgit stash &&\n \tgit stash drop -q > output.out 2>&1 &&\n-- \n1.7.0.225.g2927b\n"},{"id":"134652","messageId":"4B79968B.7060606@gmail.com","threadId":"22653","inReplyTo":"2927b3dc67ab0b9067d4fe849e85654125706b91.1266249586.git.trast@student.ethz.ch","subject":"Re: [PATCH v2] stash pop: remove 'apply' options during 'drop' invocation","fromName":"Stephen Boyd","fromEmail":"bebarino@gmail.com","sentAt":"2010-02-15T18:46:35Z","receivedAt":"2010-02-15T18:46:35Z","isPatch":true,"sender":{"key":"bebarino@gmail.com","avatar":"https://avatars.githubusercontent.com/u/38832?v=4"},"body":"On 02/15/2010 08:05 AM, Thomas Rast wrote:\n> The 'git stash pop' option parsing used to remove the first argument\n> in --index mode.  At the time this was implemented, this first\n> argument was always --index.  However, since the invention of the -q\n> option in fcdd0e9 (stash: teach quiet option, 2009-06-17) you can\n> cause an internal invocation of\n>\n>   git stash drop --index\n>\n> by running\n>\n>   git stash pop -q --index\n>\n> which then of course fails because drop doesn't know --index.\n>\n> To handle this, instead let 'git stash apply' decide what the future\n> argument to 'drop' should be.\n>\n> Warning: this means that 'git stash apply' must parse all options that\n> 'drop' can take, and deal with them in the same way.  This is\n> currently true for its only option -q.\n>\n> Signed-off-by: Thomas Rast <trast@student.ethz.ch>\n>\n\nAcked-by: Stephen Boyd <bebarino@gmail.com>\n"},{"id":"134664","messageId":"loom.20100215T220806-238@post.gmane.org","threadId":"22653","inReplyTo":"201002151641.19694.trast@student.ethz.ch","subject":"Re: git stash pop not reapplying deletions","fromName":"Steve Folly","fromEmail":"steve@spfweb.co.uk","sentAt":"2010-02-15T21:09:53Z","receivedAt":"2010-02-15T21:09:53Z","isPatch":false,"sender":{"key":"steve@spfweb.co.uk","avatar":null},"body":"Thomas Rast <trast <at> student.ethz.ch> writes:\n\n> \n> Please don't remove the Cc list, it helps us (among other things) flag\n> the mail that is important.\n\nIt's probably happened again, but not my fault - I'm reply via gmane.org, \nnot email.\n\n\nSteve\n"},{"id":"134690","messageId":"7v7hqdrkjb.fsf@alter.siamese.dyndns.org","threadId":"22653","inReplyTo":"201002142308.01704.trast@student.ethz.ch","subject":"Re: git stash pop not reapplying deletions","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-02-16T02:17:44Z","receivedAt":"2010-02-16T02:17:44Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thomas Rast <trast@student.ethz.ch> writes:\n\n> The problem is that you aren't using --index, but still expecting it\n> to restore your index.  If you change it to 'git stash pop --index',\n> everything will work as expected.\n>\n> Yes, it does stage new files, but that is only to help you: otherwise\n> you could forget them before committing.\n\nI think the reason _new_ files are added is simply because ack then there\nwas no other way to make it tracked.\n\nA sane thing to do these days might be to add a newly created file with\nthe \"intent to add\" option, to mimic the way other files in the work tree\nwith changes are unstashed.  They get the full change in the work tree,\nwithout restoring what their corresponding index entry used to have when\nthe stash was made, if you unstash without the --index option.\n"}]}