pre-upload: allow more tags in cherry picked patches

The pre-upload check generates false positives on cherry picked patches
created by 'git cherry-pick -x', as these patches have more tags than
the "Signed-off-by:" in the lat paragraph.

Those cherry picked patches can be identified by the presence of the
string '(cherry-picked from commit' in the last line.

With this change more tags are accepted in the last paragraph of the
cherry picked patches.

TEST=verified that proper error message is generated for different
      inputs, and that valid tags do not trigger pre-submit errors any

Change-Id: I73b02e582b72b61b8245219d92cbb26cd296d76d
Signed-off-by: Vadim Bendebury <>
Reviewed-by: Guenter Roeck <>
Reviewed-by: Dmitry Torokhov <>
diff --git a/ b/
index 14214a2..d4176a1 100755
--- a/
+++ b/
@@ -938,12 +938,22 @@
   desc = _get_commit_desc(commit)
   m =, desc)
   if not m:
-    return HookFailure('Change-Id must be in last paragraph of description.')
+    return HookFailure('Last paragraph of description must include Change-Id.')
-  # Allow s-o-b tags to follow it, but only those.
+  # S-o-b tags always allowed to follow Change-ID.
+  allowed_tags = ['Signed-off-by']
   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.')
+  if end and end[-1].startswith('(cherry picked from commit'):
+    # Cherry picked patches allow more tags in the last paragraph.
+    allowed_tags += ['Reviewed-on', 'Reviewed-by', 'Commit-Ready', 'Tested-by']
+    end = end[:-1]
+  tag_search = '^(%s): ' % '|'.join(allowed_tags)
+  if [x for x in end if not, x)]:
+    return HookFailure('Only "%s:" tag(s) may follow the Change-Id.' %
+                       ':", "'.join(allowed_tags))
 def _check_commit_message_style(_project, commit):