jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/372424 )

Change subject: Add "commit-message-validator install" command
......................................................................


Add "commit-message-validator install" command

This command makes it extremely easy to install the post-commit git hook
without needing to manually edit files in hidden directories.

Change-Id: I764a203635a4b304b809aa77791cda199211bca0
---
M commit_message_validator/__init__.py
1 file changed, 30 insertions(+), 1 deletion(-)

Approvals:
  Legoktm: Looks good to me, approved
  jenkins-bot: Verified
  XZise: Looks good to me, but someone else must approve



diff --git a/commit_message_validator/__init__.py 
b/commit_message_validator/__init__.py
index 43e228a..7dfd41a 100644
--- a/commit_message_validator/__init__.py
+++ b/commit_message_validator/__init__.py
@@ -23,6 +23,7 @@
 """
 from __future__ import print_function
 
+import os
 import re
 import subprocess
 import sys
@@ -279,5 +280,33 @@
     return check_message(lines)
 
 
+def install():
+    """Install post-commit git hook."""
+    cmd = sys.executable + ' ' + __file__
+    print('Will install a git hook that runs: %s' % cmd)
+    git_dir = check_output(['git', 'rev-parse', '--git-dir']).strip()
+    path = os.path.join(git_dir, 'hooks', 'post-commit')
+    if os.path.exists(path):
+        # Check to see if it's already installed
+        with open(path) as f:
+            contents = f.read()
+        if 'commit-message-validator' in contents or 
'commit_message_validator' in contents:
+            print('commit-message-validator git hook is already installed')
+            return 1
+        # Not installed, but hook already exists.
+        with open(path, 'a') as f:
+            f.write('\n' + cmd + '\n')
+        print('Installed commit-message-validator in %s' % path)
+        return 0
+    # Doesn't exist, we need to create a hook and make it +x
+    with open(path, 'w') as f:
+        f.write(cmd + '\n')
+    subprocess.check_call(['chmod', '+x', path])
+    return 0
+
+
 if __name__ == '__main__':
-    sys.exit(main())
+    if sys.argv[-1] == 'install':
+        sys.exit(install())
+    else:
+        sys.exit(main())

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I764a203635a4b304b809aa77791cda199211bca0
Gerrit-PatchSet: 3
Gerrit-Project: integration/commit-message-validator
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
Gerrit-Reviewer: BryanDavis <[email protected]>
Gerrit-Reviewer: Hashar <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Paladox <[email protected]>
Gerrit-Reviewer: XZise <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to