pre-upload: reject BRANCH tags by default

These make sense in a few specific repos, but not the majority.
Start rejecting them so people stop adding them everywhere.

BUG=None
TEST=upload still works

Change-Id: Ic33c7861e3973b6902a2649579b18eb936da8db9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/repohooks/+/1894703
Tested-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Michael Mortensen <mmortensen@google.com>
Commit-Queue: Mike Frysinger <vapier@chromium.org>
diff --git a/pre-upload.py b/pre-upload.py
index 8bf85e9..4ccdc3a 100755
--- a/pre-upload.py
+++ b/pre-upload.py
@@ -1569,6 +1569,18 @@
   return None
 
 
+def _check_change_has_no_branch_field(_project, commit):
+  """Verify 'BRANCH=' field does not exist in the commit message."""
+  if commit == PRE_SUBMIT:
+    return None
+  BRANCH_RE = r'\nBRANCH=\S+'
+
+  if re.search(BRANCH_RE, _get_commit_desc(commit)):
+    msg = 'This checkout does not use BRANCH= fields.  Delete them.'
+    return HookFailure(msg)
+  return None
+
+
 def _check_change_has_signoff_field(_project, commit):
   """Check for a non-empty 'Signed-off-by:' field in the commit message."""
   if commit == PRE_SUBMIT:
@@ -1891,6 +1903,10 @@
 
   enabled_hooks = set(hooks[x] for x in enable_flags)
   disabled_hooks = set(hooks[x] for x in disable_flags)
+
+  if _check_change_has_branch_field not in enabled_hooks:
+    enabled_hooks.add(_check_change_has_no_branch_field)
+
   return enabled_hooks, disabled_hooks