Legoktm has uploaded a new change for review.

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

Change subject: Find proper commit when HEAD is a merge commit
......................................................................

Find proper commit when HEAD is a merge commit

If HEAD is a merge commit, find the commit that was most recently merged
in by getting the list of merged commits, and using the right-most one.

Bug: T142453
Change-Id: I2c44d687a971f29ee442f20c8879c53d9f445ba9
---
M commit_message_validator/__init__.py
1 file changed, 17 insertions(+), 0 deletions(-)


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

diff --git a/commit_message_validator/__init__.py 
b/commit_message_validator/__init__.py
index 22db917..f4e23dc 100755
--- a/commit_message_validator/__init__.py
+++ b/commit_message_validator/__init__.py
@@ -168,6 +168,23 @@
     """Validate the current HEAD commit message."""
     commit = subprocess.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 = subprocess.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 = subprocess.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.
     # last line is always an empty line
     lines = commit.splitlines()[:-1]
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2c44d687a971f29ee442f20c8879c53d9f445ba9
Gerrit-PatchSet: 1
Gerrit-Project: integration/commit-message-validator
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to