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

Re: [PATCH] Make stashing nothing exit 1

From
Maksim Odnoletkov <odnoletkov@mail.ru>
Date
May 23, 2019, 09:49 UTC
Message-ID
<CAEYVt4pv1JCZf_tXC4S3-D940MfrohEo0+qst73GScm9+5Rbvg@mail.gmail.com>
In-Reply-To
<30d1e067-4184-30e8-bfd2-6ba8da0fc1f5@kdbg.org>
Show 23 quoted lines
> On 23 May 2019, at 07:14, Johannes Sixt <j6t@kdbg.org> wrote:
>
>> Am 23.05.19 um 01:57 schrieb Maksim Odnoletkov:
>> The problem with current behaviour is it makes it hard to use stash in
>> scripts. A natural stash use case is: wrap some operation requiring a
>> clean working tree with a stash push-pop pair. But that doesn't work
>> properly when working tree is already clean - push silently does nothing
>> and following pop becomes unbalanced. You have to keep that in mind and
>> work around with something like:
>>
>> if ! git diff-index --exit-code --quiet HEAD
>> then
>>    git stash push
>>    trap 'git stash pop' EXIT
>> fi
>>
>> With this change this can be simplified to:
>>
>> git stash push && trap 'git stash pop' EXIT
>
> In a script, shouldn't you better use 'create' + 'store' instead of 'push'?
>
> -- Hannes

Just like 'push' 'create' doesn't error on no-op and doesn't create a stash commit – so you still need to handle this edge case manually.

I was thinking of using create-apply pair for this use case but push-pop has added benefit of preserving a user-accessible stash entry for manual recovery in case stash can't be cleanly applied after the operation.

Previous: Johannes Sixt
Message 10 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.