{"thread":{"id":"47997","subject":"Bug report: git-stash doesn't return correct status code","startedAt":"2018-03-07T12:19:36Z","lastAt":"2018-03-08T14:22:34Z","messageCount":4,"participants":["Vromen, Tomer","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"341197","messageId":"8ED425DE0F8BEC45AADD477A8872875788FB691C@hasmsx109.ger.corp.intel.com","threadId":"47997","inReplyTo":null,"subject":"Bug report: git-stash doesn't return correct status code","fromName":"Vromen, Tomer","fromEmail":"tomer.vromen@intel.com","sentAt":"2018-03-07T12:16:48Z","receivedAt":"2018-03-07T12:19:36Z","isPatch":false,"sender":{"key":"tomer.vromen@intel.com","avatar":null},"body":"Hi all,\n\nI often use this one-liner:\n\n> git stash && git checkout -b new-feature-branch && git stash pop\n\nThis is useful when I realize that I want to open a new branch for my changes (that I haven't committed yet).\nHowever, I might have forgotten to save my changes in the editor, so git-stash will give this error:\n\nNo local changes to save\n\nDespite the error, the command returns status code 0, and so the branch is created and the stash is popped, which was not my intention.\nI think that git-stash should return a non-zero status code if it didn't push a new stash.\n\ngit version: 2.8.4\n\n\nThank you,\nTomer Vromen\n\n---------------------------------------------------------------------\nIntel Israel (74) Limited\n\nThis e-mail and any attachments may contain confidential material for\nthe sole use of the intended recipient(s). Any review or distribution\nby others is strictly prohibited. If you are not the intended\nrecipient, please contact the sender and delete all copies.\n\n"},{"id":"341226","messageId":"xmqqzi3jzp91.fsf@gitster-ct.c.googlers.com","threadId":"47997","inReplyTo":"8ED425DE0F8BEC45AADD477A8872875788FB691C@hasmsx109.ger.corp.intel.com","subject":"Re: Bug report: git-stash doesn't return correct status code","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-03-07T18:58:50Z","receivedAt":"2018-03-07T18:58:59Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Vromen, Tomer\" <tomer.vromen@intel.com> writes:\n\n>> git stash && git checkout -b new-feature-branch && git stash pop\n>\n> This is useful when I realize that I want to open a new branch for my changes (that I haven't committed yet).\n> However, I might have forgotten to save my changes in the editor, so git-stash will give this error:\n>\n> No local changes to save\n\nThis is given with \"say\" and not with \"die\", as this is merely an\ninformational diagnosis.  The command did not find any erroneous\ncondition, the command did not fail to do anything it was supposed\nto do, so the command exited with 0 status.\n\n"},{"id":"341230","messageId":"xmqqina7zji7.fsf@gitster-ct.c.googlers.com","threadId":"47997","inReplyTo":"xmqqzi3jzp91.fsf@gitster-ct.c.googlers.com","subject":"Re: Bug report: git-stash doesn't return correct status code","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-03-07T21:02:56Z","receivedAt":"2018-03-07T21:03:07Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> \"Vromen, Tomer\" <tomer.vromen@intel.com> writes:\n>\n>>> git stash && git checkout -b new-feature-branch && git stash pop\n>>\n>> This is useful when I realize that I want to open a new branch for my changes (that I haven't committed yet).\n>> However, I might have forgotten to save my changes in the editor, so git-stash will give this error:\n>>\n>> No local changes to save\n>\n> This is given with \"say\" and not with \"die\", as this is merely an\n> informational diagnosis.  The command did not find any erroneous\n> condition, the command did not fail to do anything it was supposed\n> to do, so the command exited with 0 status.\n\nI guess that is only half an answer.  If you really want to avoid\ncreating the new branch when the working tree and the index are\nclean, you'd need to check that yourself before that three-command\nsequence.  In our shell script, we use these as such a check:\n\n\tgit update-index --refresh -q --ignore-submodules\n\tgit diff-files --quiet --ignore-submodules &&\n\tgit diff-index --cached --quiet --ignore-submodules HEAD --\n\nBut stepping back a bit, why do you even need stash save/pop around\n\"checkout -b new-feature-branch\" (that implicitly branches at the\ntip) in the first place?  \"checkout -b\" that begins at the current\nHEAD does not touch the index nor the working tree and take the\nlocal changes with you to the new branch, so save/pop around it\nseems totally pointless.\n"},{"id":"341289","messageId":"8ED425DE0F8BEC45AADD477A8872875788FB761D@hasmsx109.ger.corp.intel.com","threadId":"47997","inReplyTo":"xmqqina7zji7.fsf@gitster-ct.c.googlers.com","subject":"RE: Bug report: git-stash doesn't return correct status code","fromName":"Vromen, Tomer","fromEmail":"tomer.vromen@intel.com","sentAt":"2018-03-08T14:22:22Z","receivedAt":"2018-03-08T14:22:34Z","isPatch":false,"sender":{"key":"tomer.vromen@intel.com","avatar":null},"body":"> But stepping back a bit, why do you even need stash save/pop around\n> \"checkout -b new-feature-branch\" (that implicitly branches at the\n> tip) in the first place?  \n\nSorry about that, I meant something like\n\ngit stash && git checkout develop && git pull && git checkout -b new-feature-branch && git stash pop\n\nMy point is that it is the user's expectation that \"git stash\" will push to the stash.\nNot pushing anything should be considered a failure.\n\nTomer.\n\n-----Original Message-----\nFrom: Junio C Hamano [mailto:jch2355@gmail.com] On Behalf Of Junio C Hamano\nSent: Wednesday, March 07, 2018 23:03\nTo: Vromen, Tomer <tomer.vromen@intel.com>\nCc: git@vger.kernel.org\nSubject: Re: Bug report: git-stash doesn't return correct status code\n\nJunio C Hamano <gitster@pobox.com> writes:\n\n> \"Vromen, Tomer\" <tomer.vromen@intel.com> writes:\n>\n>>> git stash && git checkout -b new-feature-branch && git stash pop\n>>\n>> This is useful when I realize that I want to open a new branch for my changes (that I haven't committed yet).\n>> However, I might have forgotten to save my changes in the editor, so git-stash will give this error:\n>>\n>> No local changes to save\n>\n> This is given with \"say\" and not with \"die\", as this is merely an\n> informational diagnosis.  The command did not find any erroneous\n> condition, the command did not fail to do anything it was supposed\n> to do, so the command exited with 0 status.\n\nI guess that is only half an answer.  If you really want to avoid\ncreating the new branch when the working tree and the index are\nclean, you'd need to check that yourself before that three-command\nsequence.  In our shell script, we use these as such a check:\n\n\tgit update-index --refresh -q --ignore-submodules\n\tgit diff-files --quiet --ignore-submodules &&\n\tgit diff-index --cached --quiet --ignore-submodules HEAD --\n\nBut stepping back a bit, why do you even need stash save/pop around\n\"checkout -b new-feature-branch\" (that implicitly branches at the\ntip) in the first place?  \"checkout -b\" that begins at the current\nHEAD does not touch the index nor the working tree and take the\nlocal changes with you to the new branch, so save/pop around it\nseems totally pointless.\n---------------------------------------------------------------------\nIntel Israel (74) Limited\n\nThis e-mail and any attachments may contain confidential material for\nthe sole use of the intended recipient(s). Any review or distribution\nby others is strictly prohibited. If you are not the intended\nrecipient, please contact the sender and delete all copies.\n\n"}]}