git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Bug report: git-stash doesn't return correct status code

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 7, 2018, 21:02 UTC
Message-ID
<xmqqina7zji7.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<xmqqzi3jzp91.fsf@gitster-ct.c.googlers.com>
Junio C Hamano <gitster@pobox.com> writes:
Show 13 quoted lines
> "Vromen, Tomer" <tomer.vromen@intel.com> writes:
>
>>> git stash && git checkout -b new-feature-branch && git stash pop
>>
>> This is useful when I realize that I want to open a new branch for my changes (that I haven't committed yet).
>> However, I might have forgotten to save my changes in the editor, so git-stash will give this error:
>>
>> No local changes to save
>
> This is given with "say" and not with "die", as this is merely an
> informational diagnosis.  The command did not find any erroneous
> condition, the command did not fail to do anything it was supposed
> to do, so the command exited with 0 status.

I guess that is only half an answer. If you really want to avoid creating the new branch when the working tree and the index are clean, you'd need to check that yourself before that three-command sequence. In our shell script, we use these as such a check:

	git update-index --refresh -q --ignore-submodules
	git diff-files --quiet --ignore-submodules &&
	git diff-index --cached --quiet --ignore-submodules HEAD --

But stepping back a bit, why do you even need stash save/pop around "checkout -b new-feature-branch" (that implicitly branches at the tip) in the first place? "checkout -b" that begins at the current HEAD does not touch the index nor the working tree and take the local changes with you to the new branch, so save/pop around it seems totally pointless.

Previous: Junio C HamanoNext: Vromen, Tomer
Message 3 of 4 in “Bug report: git-stash doesn't return correct status code”
  1. Vromen, TomerMar 7, 2018
  2. Junio C HamanoMar 7, 2018
  3. Junio C HamanoMar 7, 2018
  4. Vromen, TomerMar 8, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.