{"thread":{"id":"46567","subject":"Bug when stashing previously-ignored file plus associated .gitignore change","startedAt":"2017-08-11T15:55:45Z","lastAt":"2017-08-14T07:38:12Z","messageCount":5,"participants":["Sam Partington","Nicolas Morey-Chaisemartin","Junio C Hamano","Kevin Daudt"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"326143","messageId":"CAPuLQgNq_7Kdeio-59cbDjZ5mWC1VRd_1_KK33Gbka9KJ13vfQ@mail.gmail.com","threadId":"46567","inReplyTo":null,"subject":"Bug when stashing previously-ignored file plus associated .gitignore change","fromName":"Sam Partington","fromEmail":"sam@whiteoctober.co.uk","sentAt":"2017-08-11T15:55:38Z","receivedAt":"2017-08-11T15:55:45Z","isPatch":false,"sender":{"key":"sam@whiteoctober.co.uk","avatar":null},"body":"Hi there,\n\nI'm running git 2.7.4 on Ubuntu 16.04.  I've found a couple of\nproblems when \"un-ignoring\" files in tandem with git stash.\n\nHere's how to reproduce:\n\nSay you have a project using git, with a .gitignore file which\ncontains the following line:\n\nbin/*\n\nYou can then see the problems by doing this:\n\n$ touch bin/mynewfile # this file will be ignored at this point\n\nand then updating .gitignore to look like this (adding that second line):\n\nbin/*\n!bin/mynewfile\n\nSo far, so good; the new file is no longer ignored.\n\nBut now, try stashing the changes and including untracked files in the stash:\n\n$ git stash save -u\n\nHere's the first problem, bin/mynewfile is still there:\n\n$ ls bin/mynewfile\nbin/mynewfile\n\nBut you'd expect it to not be there and be in the stash, I think.\nThis is what would normally happen with the untracked-files option for\ngit stash.\n\nThis leads to the second problem - you can't now pop the stash:\n\n$ git stash pop\nbin/mynewfile already exists, no checkout\nCould not restore untracked files from stash\n\nIf you want to apply the stash, you have to remove the file:\n\n$ rm bin/mynewfile\n$ git stash pop # this works, and re-creates bin/mynewfile\n\nThis is quite an unusual edge case, but I have hit it two or three\ntimes now and so thought it worth reporting, but I'll understand if\nit's deemed not worth fixing!\n\nDo let me know if you need any more information from me here.\n\nThanks\nSam\n\nPS Sorry for the lack of formatting - I'm sending this as plain text\nas my original HTML emails was rejected as possible spam by your\nmailserver.\n\nSam Partington\nSenior Developer\n\nwww.whiteoctober.co.uk\nOffice: +44 (0)1865 920 707\n\nThis email message and any attachments are confidential and solely for\nthe use of the intended recipient. If you are not the intended\nrecipient, you have received this message in error. Please notify us\nimmediately and delete the message from your computer. You should not\ndistribute, copy or disclose its contents to any other person. Any\nviews or opinions expressed in this email are solely those of the\nauthor and do not necessarily represent those of White October\nLimited. White October is a private limited company registered in\nEngland & Wales under registration number 3982889. The company’s\nregistered office is at 264 Banbury Road, Oxford, OX2 7DY.\n"},{"id":"326148","messageId":"b87007d1-eb5a-f092-9e03-5c6549044b42@morey-chaisemartin.com","threadId":"46567","inReplyTo":"CAPuLQgNq_7Kdeio-59cbDjZ5mWC1VRd_1_KK33Gbka9KJ13vfQ@mail.gmail.com","subject":"[PATCH] stash: clean untracked files before reset","fromName":"Nicolas Morey-Chaisemartin","fromEmail":"nicolas@morey-chaisemartin.com","sentAt":"2017-08-11T17:14:43Z","receivedAt":"2017-08-11T17:14:50Z","isPatch":true,"sender":{"key":"devel-git@morey-chaisemartin.com","avatar":"https://avatars.githubusercontent.com/u/108326?v=4"},"body":"If calling git stash -u on a repo that contains a file that is not\nignored any more due to a current modification of the gitignore file,\nthis file is stashed but not remove from the working tree.\nThis is due to git-stash first doing a reset --hard which clears the\n.gitignore file modification and the call git clean, leaving the file\nuntouched.\nThis causes git stash pop to fail due to the file existing.\n\nThis patch simply switches the order between cleaning and resetting\nand adds a test for this usecase.\n\nSigned-off-by: Nicolas Morey-Chaisemartin <nicolas@morey-chaisemartin.com>\nReported-by: Sam Partington <sam@whiteoctober.co.uk>\n---\n git-stash.sh                       | 11 ++++++-----\n t/t3905-stash-include-untracked.sh | 18 ++++++++++++++++++\n 2 files changed, 24 insertions(+), 5 deletions(-)\n\ndiff --git a/git-stash.sh b/git-stash.sh\nindex 9b6c2da7b..39083b4d9 100755\n--- a/git-stash.sh\n+++ b/git-stash.sh\n@@ -300,6 +300,12 @@ push_stash () {\n \n \tif test -z \"$patch_mode\"\n \tthen\n+\t\ttest \"$untracked\" = \"all\" && CLEAN_X_OPTION=-x || CLEAN_X_OPTION=\n+\t\tif test -n \"$untracked\"\n+\t\tthen\n+\t\t\tgit clean --force --quiet -d $CLEAN_X_OPTION -- \"$@\"\n+\t\tfi\n+\n \t\tif test $# != 0\n \t\tthen\n \t\t\tgit reset -q -- \"$@\"\n@@ -309,11 +315,6 @@ push_stash () {\n \t\telse\n \t\t\tgit reset --hard -q\n \t\tfi\n-\t\ttest \"$untracked\" = \"all\" && CLEAN_X_OPTION=-x || CLEAN_X_OPTION=\n-\t\tif test -n \"$untracked\"\n-\t\tthen\n-\t\t\tgit clean --force --quiet -d $CLEAN_X_OPTION -- \"$@\"\n-\t\tfi\n \n \t\tif test \"$keep_index\" = \"t\" && test -n \"$i_tree\"\n \t\tthen\ndiff --git a/t/t3905-stash-include-untracked.sh b/t/t3905-stash-include-untracked.sh\nindex 193adc7b6..c1f84d3d5 100755\n--- a/t/t3905-stash-include-untracked.sh\n+++ b/t/t3905-stash-include-untracked.sh\n@@ -211,4 +211,22 @@ test_expect_success 'stash push with $IFS character' '\n \ttest_path_is_file bar\n '\n \n+cat > .gitignore <<EOF\n+ignored\n+ignored.d/*\n+EOF\n+\n+test_expect_success 'stash previously ignored file' '\n+which git &&\n+\tgit reset HEAD &&\n+\tgit add .gitignore &&\n+\tgit commit -m \"Add .gitignore\" && \n+\t>ignored.d/foo &&\n+\techo \"!ignored.d/foo\" >> .gitignore &&\n+\tgit stash save --include-untracked &&\n+\ttest_path_is_missing ignored.d/foo &&\n+\tgit stash pop &&\n+\ttest_path_is_file ignored.d/foo\n+'\n+\n test_done\n-- \n2.14.0.1.gd9597ce13\n\n"},{"id":"326173","messageId":"xmqq60dtzrel.fsf@gitster.mtv.corp.google.com","threadId":"46567","inReplyTo":"b87007d1-eb5a-f092-9e03-5c6549044b42@morey-chaisemartin.com","subject":"Re: [PATCH] stash: clean untracked files before reset","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-08-11T22:11:14Z","receivedAt":"2017-08-11T22:11:22Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nicolas Morey-Chaisemartin <nicolas@morey-chaisemartin.com> writes:\n\n> If calling git stash -u on a repo that contains a file that is not\n> ignored any more due to a current modification of the gitignore file,\n> this file is stashed but not remove from the working tree.\n> This is due to git-stash first doing a reset --hard which clears the\n> .gitignore file modification and the call git clean, leaving the file\n> untouched.\n> This causes git stash pop to fail due to the file existing.\n>\n> This patch simply switches the order between cleaning and resetting\n> and adds a test for this usecase.\n>\n> Signed-off-by: Nicolas Morey-Chaisemartin <nicolas@morey-chaisemartin.com>\n> Reported-by: Sam Partington <sam@whiteoctober.co.uk>\n\nThese two lines are the other way around; a report/finding was made\nand then you wrote a fix, which is signed-off by you.\n\nI tried to think of a scenario where it is more desirable to use the\ncontents of the .gitignore file before modification gets stash away,\nbut I came up empty, so let's hope that this change will not make\n50% people happier while making the other 50% sadder.\n\n> ---\n>  git-stash.sh                       | 11 ++++++-----\n>  t/t3905-stash-include-untracked.sh | 18 ++++++++++++++++++\n>  2 files changed, 24 insertions(+), 5 deletions(-)\n>\n> diff --git a/git-stash.sh b/git-stash.sh\n> index 9b6c2da7b..39083b4d9 100755\n> --- a/git-stash.sh\n> +++ b/git-stash.sh\n> @@ -300,6 +300,12 @@ push_stash () {\n>  \n>  \tif test -z \"$patch_mode\"\n>  \tthen\n> +\t\ttest \"$untracked\" = \"all\" && CLEAN_X_OPTION=-x || CLEAN_X_OPTION=\n> +\t\tif test -n \"$untracked\"\n> +\t\tthen\n> +\t\t\tgit clean --force --quiet -d $CLEAN_X_OPTION -- \"$@\"\n> +\t\tfi\n> +\n>  \t\tif test $# != 0\n>  \t\tthen\n>  \t\t\tgit reset -q -- \"$@\"\n> @@ -309,11 +315,6 @@ push_stash () {\n>  \t\telse\n>  \t\t\tgit reset --hard -q\n>  \t\tfi\n> -\t\ttest \"$untracked\" = \"all\" && CLEAN_X_OPTION=-x || CLEAN_X_OPTION=\n> -\t\tif test -n \"$untracked\"\n> -\t\tthen\n> -\t\t\tgit clean --force --quiet -d $CLEAN_X_OPTION -- \"$@\"\n> -\t\tfi\n>  \n>  \t\tif test \"$keep_index\" = \"t\" && test -n \"$i_tree\"\n>  \t\tthen\n> diff --git a/t/t3905-stash-include-untracked.sh b/t/t3905-stash-include-untracked.sh\n> index 193adc7b6..c1f84d3d5 100755\n> --- a/t/t3905-stash-include-untracked.sh\n> +++ b/t/t3905-stash-include-untracked.sh\n> @@ -211,4 +211,22 @@ test_expect_success 'stash push with $IFS character' '\n>  \ttest_path_is_file bar\n>  '\n>  \n> +cat > .gitignore <<EOF\n> +ignored\n> +ignored.d/*\n> +EOF\n> +\n> +test_expect_success 'stash previously ignored file' '\n> +which git &&\n\nI will remove this line while queuing, though.\n\n> +\tgit reset HEAD &&\n> +\tgit add .gitignore &&\n> +\tgit commit -m \"Add .gitignore\" && \n> +\t>ignored.d/foo &&\n> +\techo \"!ignored.d/foo\" >> .gitignore &&\n> +\tgit stash save --include-untracked &&\n> +\ttest_path_is_missing ignored.d/foo &&\n> +\tgit stash pop &&\n> +\ttest_path_is_file ignored.d/foo\n> +'\n> +\n>  test_done\n\nWill queue.  Thanks.\n\n"},{"id":"326259","messageId":"20170814044756.GA8587@alpha.vpn.ikke.info","threadId":"46567","inReplyTo":"CAPuLQgNq_7Kdeio-59cbDjZ5mWC1VRd_1_KK33Gbka9KJ13vfQ@mail.gmail.com","subject":"Re: Bug when stashing previously-ignored file plus associated .gitignore change","fromName":"Kevin Daudt","fromEmail":"me@ikke.info","sentAt":"2017-08-14T04:47:56Z","receivedAt":"2017-08-14T04:48:03Z","isPatch":false,"sender":{"key":"me@ikke.info","avatar":"https://avatars.githubusercontent.com/u/135698?v=4"},"body":"On Fri, Aug 11, 2017 at 04:55:38PM +0100, Sam Partington wrote:\n> Hi there,\n> \n> I'm running git 2.7.4 on Ubuntu 16.04.  I've found a couple of\n> problems when \"un-ignoring\" files in tandem with git stash.\n> \n> Here's how to reproduce:\n> \n> Say you have a project using git, with a .gitignore file which\n> contains the following line:\n> \n> bin/*\n> \n> You can then see the problems by doing this:\n> \n> $ touch bin/mynewfile # this file will be ignored at this point > \n> and then updating .gitignore to look like this (adding that second line):\n> \n> bin/*\n> !bin/mynewfile\n> \n> So far, so good; the new file is no longer ignored.\n> \n> But now, try stashing the changes and including untracked files in the stash:\n> \n> $ git stash save -u\n> \n> Here's the first problem, bin/mynewfile is still there:\n> \n> $ ls bin/mynewfile\n> bin/mynewfile\n> \n> But you'd expect it to not be there and be in the stash, I think.\n> This is what would normally happen with the untracked-files option for\n> git stash.\n> \n> This leads to the second problem - you can't now pop the stash:\n> \n> $ git stash pop\n> bin/mynewfile already exists, no checkout\n> Could not restore untracked files from stash\n> \n> If you want to apply the stash, you have to remove the file:\n> \n> $ rm bin/mynewfile\n> $ git stash pop # this works, and re-creates bin/mynewfile\n> \n> This is quite an unusual edge case, but I have hit it two or three\n> times now and so thought it worth reporting, but I'll understand if\n> it's deemed not worth fixing!\n> \n> Do let me know if you need any more information from me here.\n> \n> Thanks\n> Sam\n> \n> PS Sorry for the lack of formatting - I'm sending this as plain text\n> as my original HTML emails was rejected as possible spam by your\n> mailserver.\n> \n> Sam Partington\n> Senior Developer\n> \n\nHello Sam,\n\nIs it the case that you did not commit the addition of '!bin/mynewfile'\nyet? I suspect that by running git stash save -u, you also are stashing\nthis addition to the .gitigore file. Can you confirm this?\n\nKevin\n"},{"id":"326262","messageId":"CAPuLQgPt=NPtd=14BLZ+q8zJyFGOdxNZQX7F1OCdhGrgkFB1+A@mail.gmail.com","threadId":"46567","inReplyTo":"20170814044756.GA8587@alpha.vpn.ikke.info","subject":"Re: Bug when stashing previously-ignored file plus associated .gitignore change","fromName":"Sam Partington","fromEmail":"sam@whiteoctober.co.uk","sentAt":"2017-08-14T07:38:05Z","receivedAt":"2017-08-14T07:38:12Z","isPatch":false,"sender":{"key":"sam@whiteoctober.co.uk","avatar":null},"body":"Hello Kevin,\n\nYes, you're right - I didn't commit the change to the .gitignore file,\nso that addition is also being stashed.\n\nThanks\nSam\nSam Partington\nSenior Developer\n\n\n\nwww.whiteoctober.co.uk\nOffice: +44 (0)1865 920 707\n\nThis email message and any attachments are confidential and solely for\nthe use of the intended recipient. If you are not the intended\nrecipient, you have received this message in error. Please notify us\nimmediately and delete the message from your computer. You should not\ndistribute, copy or disclose its contents to any other person. Any\nviews or opinions expressed in this email are solely those of the\nauthor and do not necessarily represent those of White October\nLimited. White October is a private limited company registered in\nEngland & Wales under registration number 3982889. The company’s\nregistered office is at 264 Banbury Road, Oxford, OX2 7DY.\n\n\nOn 14 August 2017 at 05:47, Kevin Daudt <me@ikke.info> wrote:\n> On Fri, Aug 11, 2017 at 04:55:38PM +0100, Sam Partington wrote:\n>> Hi there,\n>>\n>> I'm running git 2.7.4 on Ubuntu 16.04.  I've found a couple of\n>> problems when \"un-ignoring\" files in tandem with git stash.\n>>\n>> Here's how to reproduce:\n>>\n>> Say you have a project using git, with a .gitignore file which\n>> contains the following line:\n>>\n>> bin/*\n>>\n>> You can then see the problems by doing this:\n>>\n>> $ touch bin/mynewfile # this file will be ignored at this point >\n>> and then updating .gitignore to look like this (adding that second line):\n>>\n>> bin/*\n>> !bin/mynewfile\n>>\n>> So far, so good; the new file is no longer ignored.\n>>\n>> But now, try stashing the changes and including untracked files in the stash:\n>>\n>> $ git stash save -u\n>>\n>> Here's the first problem, bin/mynewfile is still there:\n>>\n>> $ ls bin/mynewfile\n>> bin/mynewfile\n>>\n>> But you'd expect it to not be there and be in the stash, I think.\n>> This is what would normally happen with the untracked-files option for\n>> git stash.\n>>\n>> This leads to the second problem - you can't now pop the stash:\n>>\n>> $ git stash pop\n>> bin/mynewfile already exists, no checkout\n>> Could not restore untracked files from stash\n>>\n>> If you want to apply the stash, you have to remove the file:\n>>\n>> $ rm bin/mynewfile\n>> $ git stash pop # this works, and re-creates bin/mynewfile\n>>\n>> This is quite an unusual edge case, but I have hit it two or three\n>> times now and so thought it worth reporting, but I'll understand if\n>> it's deemed not worth fixing!\n>>\n>> Do let me know if you need any more information from me here.\n>>\n>> Thanks\n>> Sam\n>>\n>> PS Sorry for the lack of formatting - I'm sending this as plain text\n>> as my original HTML emails was rejected as possible spam by your\n>> mailserver.\n>>\n>> Sam Partington\n>> Senior Developer\n>>\n>\n> Hello Sam,\n>\n> Is it the case that you did not commit the addition of '!bin/mynewfile'\n> yet? I suspect that by running git stash save -u, you also are stashing\n> this addition to the .gitigore file. Can you confirm this?\n>\n> Kevin\n"}]}