From: Johannes Sixt Date: Thu, 23 May 2019 06:14:03 GMT Subject: Re: [PATCH] Make stashing nothing exit 1 Message-ID: <30d1e067-4184-30e8-bfd2-6ba8da0fc1f5@kdbg.org> In-Reply-To: <20190522235705.68452-1-odnoletkov@mail.ru> 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