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

Re: [PATCH] Make stashing nothing exit 1

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Mar 25, 2019, 15:29 UTC
Message-ID
<nycvar.QRO.7.76.6.1903251625250.41@tvgsbejvaqbjf.bet>
In-Reply-To
<CAPig+cT99t1y8kMdGLF_GU0cvaVm=GKMRJ+xRcgS80rRgdQZDQ@mail.gmail.com>
Hi Eric,
On Sat, 23 Mar 2019, Eric Sunshine wrote:
Show 22 quoted lines
> On Sat, Mar 23, 2019 at 3:54 AM Ævar Arnfjörð Bjarmason
> <avarab@gmail.com> wrote:
> > On Sat, Mar 23 2019, Keith Smiley wrote:
> > > In the case there are no files to stash, but the user asked to stash, we
> > > should exit 1 since the stashing failed.
> > > ---
> > > diff --git a/git-stash.sh b/git-stash.sh
> > > @@ -318,7 +318,7 @@ push_stash () {
> > >       if no_changes "$@"
> > >       then
> > >               say "$(gettext "No local changes to save")"
> > > -             exit 0
> > > +             exit 1
> > >       fi
> >
> >  * Shouldn't we do this consistently across all the other sub-commands?
> >    Trying some of them seems 'push' may be the odd one out, but maybe
> >    I've missed some (and this would/should be covered by
> >    tests). I.e. some single test that does a bunch of ops with no
> >    entries / nothing to stash and asserts exit codes.
>
> A bigger question is why is this change desirable?

Indeed. When I run `git stash`, my intention is to make sure that I can get back whatever edits I had made, but right now, I want a clean worktree.

So for me, `git stash` does *the exact right thing*.

I could see, however, that other users might think that it is more like a "uh oh, I have modifications that I do not want to commit right now! Please, Git, put all my local changes into a stash", and when there are not even any changes to stash, they want the command to fail.

However, I think that this is not only a change in behavior, but probably a minor use case compared to what I feel *my* use case is ;-)

As such, the new behavior should be hidden behind an option (say, `--fail-if-clean`).

Show 7 quoted lines
> What is the justification for turning this into an error and possibly
> breaking existing automation scripts? Arguing that this case should be
> an "error" is difficult considering that there are many other commands
> (inside and outside of Git) which exit with 0 when they have nothing to
> do. I can't find the message in the archive right now, but I recall a
> few months ago Junio shooting down an analogous change to some other
> command, so the justification needs to be a strong one.

Indeed, the commit message should make a case for the change. Otherwise, it will be less convincing...

Ciao, Johannes

>
> Also, your Signed-off-by: is missing. See
> Documentation/SubmittingPatches.  Thanks.
>
Previous: Eric SunshineNext: Maxim Mazurok
Message 4 of 10 in “Make stashing nothing exit 1”
  1. Make stashing nothing exit 1Keith Smiley, Mar 22, 2019
  2. Ævar Arnfjörð BjarmasonMar 23, 2019
  3. Eric SunshineMar 24, 2019
  4. Johannes SchindelinMar 25, 2019
  5. Maxim MazurokApr 12, 2020
  6. Junio C HamanoMar 24, 2019
  7. Maksim OdnoletkovMay 22, 2019
  8. Ævar Arnfjörð BjarmasonMay 23, 2019
  9. Johannes SixtMay 23, 2019
  10. Maksim OdnoletkovMay 23, 2019

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.