> On 23 May 2019, at 07:14, Johannes Sixt <j6t@xxxxxxxx> 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.