# git stash push/save/create all return exit code 0, even if no object was created

3 messages from 2020-03-22 to 2020-03-22. Participants: Σταύρος Ντέντος, Junio C Hamano.
Thread: https://gitlist.dev/t/53058

## Σταύρος Ντέντος, 2020-03-22 15:09

Subject: git stash push/save/create all return exit code 0, even if no object was created
Message-ID: <CAHMHMxW=muHe5qqndtdzR_md6KFQqwEonko-2gXC_q973JgB5w@mail.gmail.com>
URL: https://gitlist.dev/e/CAHMHMxW%3DmuHe5qqndtdzR_md6KFQqwEonko-2gXC_q973JgB5w%40mail.gmail.com

```
Hello there,

I am trying to run a `git checkout` command on a repository, without
the possibility of getting any error message about files interfering
with the checkout process.
I thought a safe way to do this was to run `git-stash`, similarly to
`rebase.autoStash = true`

However, I find two issues with those:
1) Exit code is 0, even if no object/stash was created.

It feels weird to parse stdout/stderr to decide "what happened".

2) `git stash create` (which sounds more like what I need), does not
clear what it was stored.
I can "take the pain" of printing the object-sha1 to be traceable if
something happens (even though I would prefer more if it was
"securely" stored in `refs/stash` i.e. `git stash push`), but then
`git stash` won't clean what it just stored.
Is the solution to also run `git reset --hard` there?

With regards,
Ntentos Stavros

```

## Junio C Hamano, 2020-03-22 15:50

Subject: Re: git stash push/save/create all return exit code 0, even if no object was created
Message-ID: <xmqq8sjs8k3k.fsf@gitster.c.googlers.com>
URL: https://gitlist.dev/e/xmqq8sjs8k3k.fsf%40gitster.c.googlers.com
In-Reply-To: <CAHMHMxW=muHe5qqndtdzR_md6KFQqwEonko-2gXC_q973JgB5w@mail.gmail.com>

```
This has been asked and answered recently at least twice, I think.

https://lore.kernel.org/git/01020169a7ad6af3-ad50e2d1-19fb-46eb-b397-759f8d579e8b-000000@eu-west-1.amazonses.com/

https://lore.kernel.org/git/CADZUK1cjvifbFYk9w6+vE95jgEBuwjoOi_1QfZHoPFBXuXHCCg@mail.gmail.com/

I think these previous ones wanted something more relevant to "git
stash", in the sense that they wanted to be able to

	git stash
	do some other things
	do many other things
	if earlier "git stash" produced an entry
		git stash pop

and the answer to that may be "use stash create upfront, save it
away yourself in a variable or something, then use that to restore"

But to me your use case does not look like it has much to "git
stash".  If a user wants to ask "is my working tree and the index
dirty (iow, have I made any changes)?", wouldn't "git status" be the
right tool for the job?  It even has an option to produce output
designed to be machine readable.

```

## Σταύρος Ντέντος, 2020-03-22 16:15

Subject: Re: git stash push/save/create all return exit code 0, even if no object was created
Message-ID: <CAHMHMxVKXsBRFt7L5BSFZmW02SvisQa-9g7ibn1Dd6cXh1Nefg@mail.gmail.com>
URL: https://gitlist.dev/e/CAHMHMxVKXsBRFt7L5BSFZmW02SvisQa-9g7ibn1Dd6cXh1Nefg%40mail.gmail.com
In-Reply-To: <xmqq8sjs8k3k.fsf@gitster.c.googlers.com>

```
On Sun, 22 Mar 2020 at 17:50, Junio C Hamano <gitster@pobox.com> wrote:
>
> This has been asked and answered recently at least twice, I think.
>
> https://lore.kernel.org/git/01020169a7ad6af3-ad50e2d1-19fb-46eb-b397-759f8d579e8b-000000@eu-west-1.amazonses.com/
>
> https://lore.kernel.org/git/CADZUK1cjvifbFYk9w6+vE95jgEBuwjoOi_1QfZHoPFBXuXHCCg@mail.gmail.com/
>
> I think these previous ones wanted something more relevant to "git
> stash", in the sense that they wanted to be able to
>
>         git stash
>         do some other things
>         do many other things
>         if earlier "git stash" produced an entry
>                 git stash pop
>
> and the answer to that may be "use stash create upfront, save it
> away yourself in a variable or something, then use that to restore"

I guess I was too much into my stuff, and couldn't think straight on
how to search for this. Apologies, and thank you! :-)

Maybe I find https://public-inbox.org/git/20190927230747.yjdeaen34nnpcchy@camp.crustytoothpaste.net/
| grep -vP '^??' (or git-status-filtering equivalent; I'm in a rush to
commit this e-mail) somehow useful in my case

> But to me your use case does not look like it has much to "git
> stash".  If a user wants to ask "is my working tree and the index
> dirty (iow, have I made any changes)?", wouldn't "git status" be the
> right tool for the job?  It even has an option to produce output
> designed to be machine readable.

I tried to minimize the message, and left that important part out. I
am also part of the first case.

Then my fear/question remains:
* Wouldn't it be safer if it was "securely" stored in `refs/stash`
(i.e. `git stash push`) instead of `sha1="$(git stash create)"; echo
"Created autostash: ${sha1}"`?
  How is `rebase.autoStash = true` protected from "stuff" happening?
  A tin-foil hat example that I'm thinking is terminal output lost for
some reason and git rebase ancestor is killed -9.
  Or is there is "not much" to protect against?
* ... then `git stash` won't clean what it just stored. Is the
solution to also run `git reset --hard` here?
--
With regards,
Ntentos Stavros

```
