Legoktm has uploaded a new change for review. (
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(-)
git pull
ssh://gerrit.wikimedia.org:29418/integration/commit-message-validator
refs/changes/24/372424/1
diff --git a/commit_message_validator/__init__.py
b/commit_message_validator/__init__.py
index 7641560..b1ccb1e 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
@@ -274,5 +275,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: newchange
Gerrit-Change-Id: I764a203635a4b304b809aa77791cda199211bca0
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