.vim: vim-plug @d80f495
[dotfiles.git] / bin / git-amend
index 9101a67588329a264aaa646bc38f2f5e47a7a97b..7369128973d9262c8aea5400c2555e9979d55a69 100755 (executable)
@@ -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" || {