2016-10-24 06:25:20 +00:00
|
|
|
#!/usr/bin/env python
|
2016-10-19 15:20:54 +00:00
|
|
|
|
2017-12-14 10:18:00 +00:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2016-10-19 15:55:36 +00:00
|
|
|
# Usage: git setmail
|
2016-10-19 15:20:54 +00:00
|
|
|
#
|
2016-10-19 15:55:36 +00:00
|
|
|
# Configuration format:
|
|
|
|
# [
|
|
|
|
# {
|
|
|
|
# "match": ".*",
|
|
|
|
# "email": "mymail@example.com",
|
|
|
|
# "gpg-key": "...",
|
|
|
|
# }
|
|
|
|
# ]
|
2016-10-19 15:20:54 +00:00
|
|
|
|
2016-10-19 15:55:36 +00:00
|
|
|
import sys, re, subprocess, os.path, json
|
2016-10-19 15:20:54 +00:00
|
|
|
|
2017-11-10 11:44:57 +00:00
|
|
|
CONFIG=os.path.expanduser('~/.config/git-committerconfig.json')
|
2016-10-19 15:20:54 +00:00
|
|
|
|
|
|
|
def main():
|
|
|
|
try:
|
2016-10-24 06:25:20 +00:00
|
|
|
repo = [x.split()[1] for x in subprocess.check_output(['git', 'remote', '-v']).split('\n') if re.match('origin.*\(push\)', x)][0]
|
2016-10-19 15:20:54 +00:00
|
|
|
except:
|
2017-12-14 10:18:00 +00:00
|
|
|
print('Could not find origin, not setting email.')
|
2016-10-28 00:01:58 +00:00
|
|
|
return 0
|
2016-10-19 15:20:54 +00:00
|
|
|
|
2016-10-19 15:55:36 +00:00
|
|
|
if os.path.isfile(CONFIG):
|
|
|
|
combinations = json.loads(open(CONFIG).read())
|
|
|
|
else:
|
2017-12-14 10:18:00 +00:00
|
|
|
print('Config ({}) found.'.format(CONFIG))
|
2016-10-19 15:55:36 +00:00
|
|
|
return 1
|
2016-10-19 15:20:54 +00:00
|
|
|
|
|
|
|
for combi in combinations:
|
2016-10-19 15:55:36 +00:00
|
|
|
if re.search(combi['match'], repo):
|
2017-11-10 11:44:57 +00:00
|
|
|
subprocess.check_call(['git', 'config', '--local', 'user.email', combi['email']])
|
|
|
|
if 'gpg-key' in combi and combi['gpg-key'] != '':
|
|
|
|
subprocess.check_call(['git', 'config', '--local', 'user.signingkey', combi['gpg-key']])
|
|
|
|
if 'commit-opts' in combi:
|
|
|
|
subprocess.check_call(['git', 'config', '--local', 'commit.cliopts', combi['commit-opts']])
|
2016-10-19 15:20:54 +00:00
|
|
|
break
|
|
|
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
exit(main())
|