Run git reset --hard in case of git error.

In case of git error, there could be uncommitted changes.
Then, checkout will fail.
To avoid such a situation, run "git reset --hard" before
checkout.

BUG=None
TEST=Ran on bots.

Change-Id: Id9cbd76c7e66c2abc3eaae9dab7287b25a144dd4
Reviewed-on: https://chromium-review.googlesource.com/625600
Commit-Ready: Hidehiko Abe <hidehiko@chromium.org>
Tested-by: Hidehiko Abe <hidehiko@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
diff --git a/scripts/upload_prebuilts.py b/scripts/upload_prebuilts.py
index 41a50f7..57f3906 100644
--- a/scripts/upload_prebuilts.py
+++ b/scripts/upload_prebuilts.py
@@ -170,6 +170,11 @@
     git.RunGit(cwd, ['commit', '-m', description])
     git.PushWithRetry(prebuilt_branch, cwd, dryrun=dryrun, retries=retries)
   finally:
+    # We reset the index and the working tree state in case there are any
+    # uncommitted or pending changes, but we don't change any existing commits.
+    git.RunGit(cwd, ['reset', '--hard'])
+
+    # Check out the last good commit as a sanity fallback.
     git.RunGit(cwd, ['checkout', commit])