{"thread":{"id":"51935","subject":"Feature request: different exit codes for git stash depending on whether stash was created or not","startedAt":"2019-09-27T12:55:42Z","lastAt":"2019-09-27T23:07:55Z","messageCount":3,"participants":["Ian Kemp","Eric Sunshine","brian m. carlson"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"383063","messageId":"CADZUK1cjvifbFYk9w6+vE95jgEBuwjoOi_1QfZHoPFBXuXHCCg@mail.gmail.com","threadId":"51935","inReplyTo":null,"subject":"Feature request: different exit codes for git stash depending on whether stash was created or not","fromName":"Ian Kemp","fromEmail":"ian.kemp@gmail.com","sentAt":"2019-09-27T12:55:27Z","receivedAt":"2019-09-27T12:55:42Z","isPatch":false,"sender":{"key":"ian.kemp@gmail.com","avatar":null},"body":"Hi,\n\nCurrently, git stash's exit code is 0 regardless of whether it\nperformed a stash operation or not. Third parties invoking git stash\nare therefore unable to determine whether a stash was actually made or\nnot.\n\nIt would be helpful if there were different exit codes for the case\nwhen a stash was created (working directory dirty) vs when a stash was\nnot (working dir clean). git stash create suffers from the same issue.\n\nThere are various workarounds for this e.g.\nhttps://stackoverflow.com/a/34116244/70345 but they aren't\nparticularly pretty or reliable, hence this request.\n\nRegards,\nIan\n"},{"id":"383069","messageId":"CAPig+cSsSHCNK9yogRUq+gRv+yb5JdPO5ECW0FKZgbW-RXGw8A@mail.gmail.com","threadId":"51935","inReplyTo":"CADZUK1cjvifbFYk9w6+vE95jgEBuwjoOi_1QfZHoPFBXuXHCCg@mail.gmail.com","subject":"Re: Feature request: different exit codes for git stash depending on whether stash was created or not","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2019-09-27T16:55:18Z","receivedAt":"2019-09-27T16:55:34Z","isPatch":false,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Fri, Sep 27, 2019 at 8:55 AM Ian Kemp <ian.kemp@gmail.com> wrote:\n> Currently, git stash's exit code is 0 regardless of whether it\n> performed a stash operation or not. Third parties invoking git stash\n> are therefore unable to determine whether a stash was actually made or\n> not.\n>\n> It would be helpful if there were different exit codes for the case\n> when a stash was created (working directory dirty) vs when a stash was\n> not (working dir clean). git stash create suffers from the same issue.\n\nThere was a recent discussion[1] about this which might interest you.\n\n[1]: https://public-inbox.org/git/01020169a7ad6af3-ad50e2d1-19fb-46eb-b397-759f8d579e8b-000000@eu-west-1.amazonses.com/\n"},{"id":"383075","messageId":"20190927230747.yjdeaen34nnpcchy@camp.crustytoothpaste.net","threadId":"51935","inReplyTo":"CADZUK1cjvifbFYk9w6+vE95jgEBuwjoOi_1QfZHoPFBXuXHCCg@mail.gmail.com","subject":"Re: Feature request: different exit codes for git stash depending on whether stash was created or not","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2019-09-27T23:07:48Z","receivedAt":"2019-09-27T23:07:55Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2019-09-27 at 12:55:27, Ian Kemp wrote:\n> Hi,\n> \n> Currently, git stash's exit code is 0 regardless of whether it\n> performed a stash operation or not. Third parties invoking git stash\n> are therefore unable to determine whether a stash was actually made or\n> not.\n> \n> It would be helpful if there were different exit codes for the case\n> when a stash was created (working directory dirty) vs when a stash was\n> not (working dir clean). git stash create suffers from the same issue.\n> \n> There are various workarounds for this e.g.\n> https://stackoverflow.com/a/34116244/70345 but they aren't\n> particularly pretty or reliable, hence this request.\n\nFolks have already given you a link to previous discussion, but if you\nwant to know if there's anything to stash couldn't you use something\nlike this:\n\n  #!/bin/sh\n\n  if [ -z \"$(git status --porcelain)\" ]\n  then\n    CLEAN=1\n  fi\n\n  [ -n \"$CLEAN\" ] || git stash\n\n  # your operation here\n\n  [ -n \"$CLEAN\" ] || git stash pop\n\nAn empty output from git status --porcelain is the definitive way to\nknow if the working tree is clean, which is what you care about in this\ncase.  If you want to ignore untracked files, a suitable grep invocation\ncan do that for you as well.\n-- \nbrian m. carlson: Houston, Texas, US\nOpenPGP: https://keybase.io/bk2204\n"}]}