git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Feature request: different exit codes for git stash depending on whether stash was created or not
@ 2019-09-27 12:55 Ian Kemp
  2019-09-27 16:55 ` Eric Sunshine
  2019-09-27 23:07 ` brian m. carlson
  0 siblings, 2 replies; 3+ messages in thread
From: Ian Kemp @ 2019-09-27 12:55 UTC (permalink / raw)
  To: git

Hi,

Currently, git stash's exit code is 0 regardless of whether it
performed a stash operation or not. Third parties invoking git stash
are therefore unable to determine whether a stash was actually made or
not.

It would be helpful if there were different exit codes for the case
when a stash was created (working directory dirty) vs when a stash was
not (working dir clean). git stash create suffers from the same issue.

There are various workarounds for this e.g.
https://stackoverflow.com/a/34116244/70345 but they aren't
particularly pretty or reliable, hence this request.

Regards,
Ian

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

* Re: Feature request: different exit codes for git stash depending on whether stash was created or not
  2019-09-27 12:55 Feature request: different exit codes for git stash depending on whether stash was created or not Ian Kemp
@ 2019-09-27 16:55 ` Eric Sunshine
  2019-09-27 23:07 ` brian m. carlson
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Sunshine @ 2019-09-27 16:55 UTC (permalink / raw)
  To: Ian Kemp; +Cc: Git List

On Fri, Sep 27, 2019 at 8:55 AM Ian Kemp <ian.kemp@gmail.com> wrote:
> Currently, git stash's exit code is 0 regardless of whether it
> performed a stash operation or not. Third parties invoking git stash
> are therefore unable to determine whether a stash was actually made or
> not.
>
> It would be helpful if there were different exit codes for the case
> when a stash was created (working directory dirty) vs when a stash was
> not (working dir clean). git stash create suffers from the same issue.

There was a recent discussion[1] about this which might interest you.

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

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

* Re: Feature request: different exit codes for git stash depending on whether stash was created or not
  2019-09-27 12:55 Feature request: different exit codes for git stash depending on whether stash was created or not Ian Kemp
  2019-09-27 16:55 ` Eric Sunshine
@ 2019-09-27 23:07 ` brian m. carlson
  1 sibling, 0 replies; 3+ messages in thread
From: brian m. carlson @ 2019-09-27 23:07 UTC (permalink / raw)
  To: Ian Kemp; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 1335 bytes --]

On 2019-09-27 at 12:55:27, Ian Kemp wrote:
> Hi,
> 
> Currently, git stash's exit code is 0 regardless of whether it
> performed a stash operation or not. Third parties invoking git stash
> are therefore unable to determine whether a stash was actually made or
> not.
> 
> It would be helpful if there were different exit codes for the case
> when a stash was created (working directory dirty) vs when a stash was
> not (working dir clean). git stash create suffers from the same issue.
> 
> There are various workarounds for this e.g.
> https://stackoverflow.com/a/34116244/70345 but they aren't
> particularly pretty or reliable, hence this request.

Folks have already given you a link to previous discussion, but if you
want to know if there's anything to stash couldn't you use something
like this:

  #!/bin/sh

  if [ -z "$(git status --porcelain)" ]
  then
    CLEAN=1
  fi

  [ -n "$CLEAN" ] || git stash

  # your operation here

  [ -n "$CLEAN" ] || git stash pop

An empty output from git status --porcelain is the definitive way to
know if the working tree is clean, which is what you care about in this
case.  If you want to ignore untracked files, a suitable grep invocation
can do that for you as well.
-- 
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 868 bytes --]

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

end of thread, other threads:[~2019-09-27 23:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-27 12:55 Feature request: different exit codes for git stash depending on whether stash was created or not Ian Kemp
2019-09-27 16:55 ` Eric Sunshine
2019-09-27 23:07 ` brian m. carlson

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