{"thread":{"id":"61988","subject":"\"git stash push\" behaves weirdly when files is added in index and removed (and the other way around)","startedAt":"2024-08-21T19:09:22Z","lastAt":"2024-08-21T19:09:22Z","messageCount":1,"participants":["Piotr Siupa"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"501457","messageId":"CAPM0=yBx4LiL+5vhCGgm30ThtsN99-zWeeQ7qhtwRR-N-2DmHw@mail.gmail.com","threadId":"61988","inReplyTo":null,"subject":"\"git stash push\" behaves weirdly when files is added in index and removed (and the other way around)","fromName":"Piotr Siupa","fromEmail":"piotrsiupa@gmail.com","sentAt":"2024-08-21T19:09:05Z","receivedAt":"2024-08-21T19:09:22Z","isPatch":false,"sender":{"key":"piotrsiupa@gmail.com","avatar":"https://gravatar.com/avatar/5970da465a147bda2b821a29e966ed328cca93067a42d05cf33ee38aac4acd6f?d=mp&s=160"},"body":"I'm writing a script that is based on \"git stash\" and I test it\nextensively, which leads to finding a lot of weird corner cases in the\nbehavior of \"git stash\".\n\nI've reported one bug already and now I've found two \"inconsistencies\"\nthat I'm less sure about. (and that may be related to each other,\nwhich is why I write about them in the same email)\n\nOK, the first one occurs when a file (that existed in the previous\ncommits) is removed in index but after that re-added without informing\nGit about it. (So it's untracked.)\n    git rm file\n    echo content >file\n    git stash push\nThe untracked file is pushed to the stash despite the flag\n\"--include-untracked\" not being set. It even works like that with\n\"--no-include-untracked\".\nThis looks like a bug for sure but I found a test \"stash rm then\nrecreate\" in \"t/t3903-stash.sh\", which test for this scenario, so\napparently it isn't for some reason? (Just in case, I'm asking for\nconfirmation that it's intended. Also, is there a way to disable this\nbehavior so my script won't trip over it?)\n\nThe second scenario is the exact opposite in the sense that a file\n(that hasn't existed before) is added in the index and removed in the\nworkspace.\n    echo content >file\n    git add file\n    rm file\n    git stash push\nAfter that, the information about the file deletion is lost. The stash\ncontains the file both in stash@{0} and in stash@{0}^1 and the\nworkspace is clean after the operation (the file is restored).\nThis, I'm quite sure, is a real bug and not an intended behavior\n(although, I have a tiny doubt after finding the test for the other\nsituation).\nI went ahead and tried to fix it on my own but I don't understand the\nintricacies of Git's code well enough so I failed. I did write a test\ncase, though, which I'll send in the next email (because if I\nunderstand it right, patches are supposed to not have any added text\nin their email messages).\n\nPiotr\n"}]}