fromupstream: pause again if a conflict isn't resolved

Typically this happens when the user forgets to run `git am --continue`
or similar, like so:

    $ fromupstream pw://12345 --bug chromium:123 --test "not really"
    ...
    Please resolve the conflicts and restart the shell job when done. …
    $ (fix the conflicts)
    $ git add foo.be
    $ fg

Previously, this would add TEST=, BUG=, etc. to whatever was at HEAD
before, which is quite annoying and not immediately obvious. Now it'll
show an error and pause the script again.

BUG=None
TEST=`fromupstream msgid://20190420112217.27590-15-hdegoede@redhat.com --buganizer 14987353 --test TODO`
     then `fg` immediately (multiple times if you like). Then run `git
     am --continue` and run `fg` one last time; it should then succeed.

Change-Id: Iaf28883ef4fbd58db812ffc7ce7ed4c7158dd1dc
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/dev-util/+/2067942
Commit-Queue: Harry Cutts <hcutts@chromium.org>
Tested-by: Harry Cutts <hcutts@chromium.org>
Reviewed-by: Douglas Anderson <dianders@chromium.org>
diff --git a/contrib/fromupstream.py b/contrib/fromupstream.py
index f235d24..b5b89f1 100755
--- a/contrib/fromupstream.py
+++ b/contrib/fromupstream.py
@@ -109,6 +109,7 @@
     """Pause and go in the background till user resolves the conflicts."""
 
     git_root = _git(['rev-parse', '--show-toplevel'])
+    previous_head_hash = _git(['rev-parse', 'HEAD'])
 
     paths = (
         os.path.join(git_root, '.git', 'rebase-apply'),
@@ -122,9 +123,15 @@
                      'shell job when done. Kill this job if you '
                      'aborted the conflict.')
             os.kill(os.getpid(), signal.SIGTSTP)
-    # TODO: figure out what the state is after the merging, and go based on
-    # that (should we abort? skip? continue?)
-    # Perhaps check last commit message to see if it's the one we were using.
+
+    # Check the conflicts actually got resolved. Otherwise we'll end up
+    # modifying the wrong commit message and probably confusing people.
+    while previous_head_hash == _git(['rev-parse', 'HEAD']):
+        errprint('Error: no new commit has been made. Did you forget to run '
+                 '`git am --continue` or `git cherry-pick --continue`?')
+        errprint('Please create a new commit and restart the shell job (or kill'
+                 ' it if you aborted the conflict).')
+        os.kill(os.getpid(), signal.SIGTSTP)
 
 def _get_pw_url(project):
     """Retrieve the patchwork server URL from .pwclientrc.