{"thread":{"id":"53058","subject":"git stash push/save/create all return exit code 0, even if no object was created","startedAt":"2020-03-22T15:11:33Z","lastAt":"2020-03-22T16:15:45Z","messageCount":3,"participants":["Σταύρος Ντέντος","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"393716","messageId":"CAHMHMxW=muHe5qqndtdzR_md6KFQqwEonko-2gXC_q973JgB5w@mail.gmail.com","threadId":"53058","inReplyTo":null,"subject":"git stash push/save/create all return exit code 0, even if no object was created","fromName":"Σταύρος Ντέντος","fromEmail":"stdedos@gmail.com","sentAt":"2020-03-22T15:09:57Z","receivedAt":"2020-03-22T15:11:33Z","isPatch":false,"sender":{"key":"stdedos@gmail.com","avatar":null},"body":"Hello there,\n\nI am trying to run a `git checkout` command on a repository, without\nthe possibility of getting any error message about files interfering\nwith the checkout process.\nI thought a safe way to do this was to run `git-stash`, similarly to\n`rebase.autoStash = true`\n\nHowever, I find two issues with those:\n1) Exit code is 0, even if no object/stash was created.\n\nIt feels weird to parse stdout/stderr to decide \"what happened\".\n\n2) `git stash create` (which sounds more like what I need), does not\nclear what it was stored.\nI can \"take the pain\" of printing the object-sha1 to be traceable if\nsomething happens (even though I would prefer more if it was\n\"securely\" stored in `refs/stash` i.e. `git stash push`), but then\n`git stash` won't clean what it just stored.\nIs the solution to also run `git reset --hard` there?\n\nWith regards,\nNtentos Stavros\n"},{"id":"393719","messageId":"xmqq8sjs8k3k.fsf@gitster.c.googlers.com","threadId":"53058","inReplyTo":"CAHMHMxW=muHe5qqndtdzR_md6KFQqwEonko-2gXC_q973JgB5w@mail.gmail.com","subject":"Re: git stash push/save/create all return exit code 0, even if no object was created","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-03-22T15:50:23Z","receivedAt":"2020-03-22T15:50:32Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"This has been asked and answered recently at least twice, I think.\n\nhttps://lore.kernel.org/git/01020169a7ad6af3-ad50e2d1-19fb-46eb-b397-759f8d579e8b-000000@eu-west-1.amazonses.com/\n\nhttps://lore.kernel.org/git/CADZUK1cjvifbFYk9w6+vE95jgEBuwjoOi_1QfZHoPFBXuXHCCg@mail.gmail.com/\n\nI think these previous ones wanted something more relevant to \"git\nstash\", in the sense that they wanted to be able to\n\n\tgit stash\n\tdo some other things\n\tdo many other things\n\tif earlier \"git stash\" produced an entry\n\t\tgit stash pop\n\nand the answer to that may be \"use stash create upfront, save it\naway yourself in a variable or something, then use that to restore\"\n\nBut to me your use case does not look like it has much to \"git\nstash\".  If a user wants to ask \"is my working tree and the index\ndirty (iow, have I made any changes)?\", wouldn't \"git status\" be the\nright tool for the job?  It even has an option to produce output\ndesigned to be machine readable.\n"},{"id":"393722","messageId":"CAHMHMxVKXsBRFt7L5BSFZmW02SvisQa-9g7ibn1Dd6cXh1Nefg@mail.gmail.com","threadId":"53058","inReplyTo":"xmqq8sjs8k3k.fsf@gitster.c.googlers.com","subject":"Re: git stash push/save/create all return exit code 0, even if no object was created","fromName":"Σταύρος Ντέντος","fromEmail":"stdedos@gmail.com","sentAt":"2020-03-22T16:15:06Z","receivedAt":"2020-03-22T16:15:45Z","isPatch":false,"sender":{"key":"stdedos@gmail.com","avatar":null},"body":"On Sun, 22 Mar 2020 at 17:50, Junio C Hamano <gitster@pobox.com> wrote:\n>\n> This has been asked and answered recently at least twice, I think.\n>\n> https://lore.kernel.org/git/01020169a7ad6af3-ad50e2d1-19fb-46eb-b397-759f8d579e8b-000000@eu-west-1.amazonses.com/\n>\n> https://lore.kernel.org/git/CADZUK1cjvifbFYk9w6+vE95jgEBuwjoOi_1QfZHoPFBXuXHCCg@mail.gmail.com/\n>\n> I think these previous ones wanted something more relevant to \"git\n> stash\", in the sense that they wanted to be able to\n>\n>         git stash\n>         do some other things\n>         do many other things\n>         if earlier \"git stash\" produced an entry\n>                 git stash pop\n>\n> and the answer to that may be \"use stash create upfront, save it\n> away yourself in a variable or something, then use that to restore\"\n\nI guess I was too much into my stuff, and couldn't think straight on\nhow to search for this. Apologies, and thank you! :-)\n\nMaybe I find https://public-inbox.org/git/20190927230747.yjdeaen34nnpcchy@camp.crustytoothpaste.net/\n| grep -vP '^??' (or git-status-filtering equivalent; I'm in a rush to\ncommit this e-mail) somehow useful in my case\n\n> But to me your use case does not look like it has much to \"git\n> stash\".  If a user wants to ask \"is my working tree and the index\n> dirty (iow, have I made any changes)?\", wouldn't \"git status\" be the\n> right tool for the job?  It even has an option to produce output\n> designed to be machine readable.\n\nI tried to minimize the message, and left that important part out. I\nam also part of the first case.\n\nThen my fear/question remains:\n* Wouldn't it be safer if it was \"securely\" stored in `refs/stash`\n(i.e. `git stash push`) instead of `sha1=\"$(git stash create)\"; echo\n\"Created autostash: ${sha1}\"`?\n  How is `rebase.autoStash = true` protected from \"stuff\" happening?\n  A tin-foil hat example that I'm thinking is terminal output lost for\nsome reason and git rebase ancestor is killed -9.\n  Or is there is \"not much\" to protect against?\n* ... then `git stash` won't clean what it just stored. Is the\nsolution to also run `git reset --hard` here?\n--\nWith regards,\nNtentos Stavros\n"}]}