Legoktm has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/303977

Change subject: Improve and fix detection of merge commits
......................................................................

Improve and fix detection of merge commits

Instead of guessing based on the commit message which didn't always
work, see if there are multiple parents for the commit. If so, it's a
merge commit and we should use the right-most one. Otherwise, we can use
HEAD.

Change-Id: I99c20ac0d3e3d0296ceda7a3e635c8387f7a6400
---
M commit_message_validator/__init__.py
1 file changed, 13 insertions(+), 19 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/integration/commit-message-validator 
refs/changes/77/303977/1

diff --git a/commit_message_validator/__init__.py 
b/commit_message_validator/__init__.py
index 3e6ee1d..57b5473 100755
--- a/commit_message_validator/__init__.py
+++ b/commit_message_validator/__init__.py
@@ -25,7 +25,7 @@
 import re
 import subprocess
 
-__version__ = '0.3.0'
+__version__ = '0.3.1'
 
 
 def line_errors(lineno, line):
@@ -179,25 +179,19 @@
 
 def main():
     """Validate the current HEAD commit message."""
+    # First, we need to check if HEAD is a merge commit
+    # We do this by telling if it has multiple parents
+    parents = check_output(
+        ['git', 'log', '--format=%P', 'HEAD', '-n1']
+    ).strip().split(' ')
+    if len(parents) > 1:
+        # Use the right-most parent
+        commit_id = parents[-1]
+    else:
+        commit_id = 'HEAD'
+
     commit = check_output(
-        ['git', 'log', '--format=%B', '--no-color', '-n1'])
-    # Is this reliable enough? Probably.
-    if commit.startswith('Merge "'):
-        # Merge commit, find the actual commit:
-        merge_info = check_output(
-            ['git', 'log', '--no-color', '-n1']
-        )
-        for line in merge_info.splitlines():
-            if line.startswith('Merge:'):
-                # Example: "Merge: 1fe8271 818c6e4"
-                # We want the right-most commit
-                commit_id = line.split(' ')[-1]
-                commit = check_output(
-                    ['git', 'log', '--format=%B', '--no-color',
-                     '-n1', commit_id]
-                )
-                # And if we don't find the Merge header,
-                # we'll fall back to the merge commit.
+        ['git', 'log', '--format=%B', '--no-color', commit_id, '-n1'])
     # last line is always an empty line
     lines = commit.splitlines()[:-1]
 

-- 
To view, visit https://gerrit.wikimedia.org/r/303977
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I99c20ac0d3e3d0296ceda7a3e635c8387f7a6400
Gerrit-PatchSet: 1
Gerrit-Project: integration/commit-message-validator
Gerrit-Branch: master
Gerrit-Owner: Legoktm <legoktm.wikipe...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to