cfg/bin/git-committerconfig
Knut Ahlers e4cca82e2d
Make sign-off configurable
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2017-11-10 12:47:04 +01:00

44 lines
1.2 KiB
Python
Executable File

#!/usr/bin/env python
# Usage: git setmail
#
# Configuration format:
# [
# {
# "match": ".*",
# "email": "mymail@example.com",
# "gpg-key": "...",
# }
# ]
import sys, re, subprocess, os.path, json
CONFIG=os.path.expanduser('~/.config/git-committerconfig.json')
def main():
try:
repo = [x.split()[1] for x in subprocess.check_output(['git', 'remote', '-v']).split('\n') if re.match('origin.*\(push\)', x)][0]
except:
print 'Could not find origin, not setting email.'
return 0
if os.path.isfile(CONFIG):
combinations = json.loads(open(CONFIG).read())
else:
print 'Config ({}) found.'.format(CONFIG)
return 1
for combi in combinations:
if re.search(combi['match'], repo):
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']])
break
return 0
if __name__ == "__main__":
exit(main())