git-commit: try to clean up on a commit failure
authorDenis Ovsienko <denis@ovsienko.info>
Sun, 13 Jan 2019 22:02:58 +0000 (22:02 +0000)
committerDenis Ovsienko <denis@ovsienko.info>
Sun, 13 Jan 2019 22:03:52 +0000 (22:03 +0000)
[skip ci]

gateways/git-commit

index bbfc88f..9aa7cc9 100755 (executable)
@@ -174,7 +174,15 @@ git_commit_or_exit()
                        ${COMMITDATE:+--date="$COMMITDATE"} \
                        -- "$FILEPATH" || \
                {
-                       print_error "failed to run 'git commit'"
+                       print_error "failed to run 'git commit', trying to roll back."
+                       git reset --quiet -- "$FILEPATH" || {
+                               print_error "failed to run 'git reset'"
+                               exit 13
+                       }
+                       git checkout --quiet -- "$FILEPATH" || {
+                               print_error "failed to run 'git checkout'"
+                               exit 14
+                       }
                        exit 10
                }
                [ "$1" = "and_push" ] && git_push_or_exit