pre-upload: permit s-o-b tags to follow Change-Id

The git commit -s flag will often append the signed-off-by tag.  Allow
that only to follow Change-Id to keep things simple for devs.

BUG=None
TEST=`./pre-upload_unittest.py` passes

Change-Id: I0f47dc395b8ea453789a004f08339e6a342bb215
Reviewed-on: https://chromium-review.googlesource.com/231244
Reviewed-by: Julius Werner <jwerner@chromium.org>
Commit-Queue: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
diff --git a/pre-upload.py b/pre-upload.py
index fa964fb..1d1ab0d 100755
--- a/pre-upload.py
+++ b/pre-upload.py
@@ -710,9 +710,14 @@
   CHANGE_ID_RE = r'\nChange-Id: I[a-f0-9]+\n'
   desc = _get_commit_desc(commit)
   m = re.search(CHANGE_ID_RE, desc)
-  if not m or desc[m.end():].strip():
+  if not m:
     return HookFailure('Change-Id must be in last paragraph of description.')
 
+  # Allow s-o-b tags to follow it, but only those.
+  end = desc[m.end():].strip().splitlines()
+  if [x for x in end if not x.startswith('Signed-off-by: ')]:
+    return HookFailure('Only "Signed-off-by:" tags may follow the Change-Id.')
+
 
 def _check_commit_message_style(_project, commit):
   """Verify that the commit message matches our style.
diff --git a/pre-upload_unittest.py b/pre-upload_unittest.py
index 815308f..00a098e 100755
--- a/pre-upload_unittest.py
+++ b/pre-upload_unittest.py
@@ -641,6 +641,10 @@
     """Reject Change-Id's that are not last."""
     self.assertMessageRejected('\nChange-Id: I1234\nbar\n')
 
+  def testSobTag(self):
+    """Permit s-o-b tags to follow the Change-Id."""
+    self.assertMessageAccepted('foo\n\nChange-Id: I1234\nSigned-off-by: Hi\n')
+
 
 class CheckCommitMessageStyle(CommitMessageTestCase):
   """Tests for _check_commit_message_style."""