git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Bug report: git-stash doesn't return correct status code
@ 2018-03-07 12:16 Vromen, Tomer
  2018-03-07 18:58 ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Vromen, Tomer @ 2018-03-07 12:16 UTC (permalink / raw)
  To: git@vger.kernel.org

Hi all,

I often use this one-liner:

> 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

Despite the error, the command returns status code 0, and so the branch is created and the stash is popped, which was not my intention.
I think that git-stash should return a non-zero status code if it didn't push a new stash.

git version: 2.8.4


Thank you,
Tomer Vromen

---------------------------------------------------------------------
Intel Israel (74) Limited

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Bug report: git-stash doesn't return correct status code
  2018-03-07 12:16 Bug report: git-stash doesn't return correct status code Vromen, Tomer
@ 2018-03-07 18:58 ` Junio C Hamano
  2018-03-07 21:02   ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2018-03-07 18:58 UTC (permalink / raw)
  To: Vromen, Tomer; +Cc: git@vger.kernel.org

"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.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Bug report: git-stash doesn't return correct status code
  2018-03-07 18:58 ` Junio C Hamano
@ 2018-03-07 21:02   ` Junio C Hamano
  2018-03-08 14:22     ` Vromen, Tomer
  0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2018-03-07 21:02 UTC (permalink / raw)
  To: Vromen, Tomer; +Cc: git@vger.kernel.org

Junio C Hamano <gitster@pobox.com> writes:

> "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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: Bug report: git-stash doesn't return correct status code
  2018-03-07 21:02   ` Junio C Hamano
@ 2018-03-08 14:22     ` Vromen, Tomer
  0 siblings, 0 replies; 4+ messages in thread
From: Vromen, Tomer @ 2018-03-08 14:22 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git@vger.kernel.org

> 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?  

Sorry about that, I meant something like

git stash && git checkout develop && git pull && git checkout -b new-feature-branch && git stash pop

My point is that it is the user's expectation that "git stash" will push to the stash.
Not pushing anything should be considered a failure.

Tomer.

-----Original Message-----
From: Junio C Hamano [mailto:jch2355@gmail.com] On Behalf Of Junio C Hamano
Sent: Wednesday, March 07, 2018 23:03
To: Vromen, Tomer <tomer.vromen@intel.com>
Cc: git@vger.kernel.org
Subject: Re: Bug report: git-stash doesn't return correct status code

Junio C Hamano <gitster@pobox.com> writes:

> "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.
---------------------------------------------------------------------
Intel Israel (74) Limited

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-03-08 14:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-07 12:16 Bug report: git-stash doesn't return correct status code Vromen, Tomer
2018-03-07 18:58 ` Junio C Hamano
2018-03-07 21:02   ` Junio C Hamano
2018-03-08 14:22     ` Vromen, Tomer

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).