From: Tony Duckles Date: Sun, 31 Dec 2017 16:32:27 +0000 (-0600) Subject: bin/git-amend: Smarter 'git stash' handling X-Git-Url: http://git.nynim.org/dotfiles.git/commitdiff_plain/4155e551d3086224820400bebdcc6e9c5577c856 bin/git-amend: Smarter 'git stash' handling - Fix 'stash pop' handling to always restore back to the stashed changes afterwards. - Only stash if there are local modifications. --- diff --git a/bin/git-amend b/bin/git-amend index 9101a67..7369128 100755 --- a/bin/git-amend +++ b/bin/git-amend @@ -23,12 +23,15 @@ test -z "$TARGET" && { exit 1 } -# stash off work tree modifications leaving the -# index for amending to the target commit -git stash save -q --keep-index git-amend - +# if there are local work tree modifications, stash those off leaving +# the index for amending to the target commit +DIRTY=0 +if ! git diff-files --quiet --ignore-submodules --; then + DIRTY=1 +fi +test $DIRTY -eq 1 && git stash save -q --keep-index git-amend # always restore from stash before exiting -trap 'git stash pop -q stash@{git-amend} 2>/dev/null' EXIT +test $DIRTY -eq 1 && trap 'git stash pop -q stash@{0} 2>/dev/null' EXIT # go back in history git checkout -q "$TARGET" || {