Update git-c and git-setmail to manage GPG keys
This commit is contained in:
parent
99692c978a
commit
3837d733d9
2 changed files with 24 additions and 18 deletions
|
@ -15,7 +15,7 @@ git setmail
|
|||
### Commit
|
||||
|
||||
step "Loading passphrase for GPG key..."
|
||||
vault-gpg $(grep default-key ~/.gnupg/gpg.conf | cut -d ' ' -f 2)
|
||||
vault-gpg $(git config user.signingkey)
|
||||
|
||||
step "Issuing commit..."
|
||||
git commit -S -v "$@"
|
||||
|
|
|
@ -1,12 +1,19 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
# Usage: git setmail myemail@example.com:"github.com:myprefix" myothermail@example.com:".*"
|
||||
# Usage: git setmail
|
||||
#
|
||||
# Configuration format: One combination per line `<email>:<match regex>`
|
||||
# Configuration format:
|
||||
# [
|
||||
# {
|
||||
# "match": ".*",
|
||||
# "email": "mymail@example.com",
|
||||
# "gpg-key": "...",
|
||||
# }
|
||||
# ]
|
||||
|
||||
import sys, re, subprocess, os.path
|
||||
import sys, re, subprocess, os.path, json
|
||||
|
||||
CONFIG=os.path.expanduser('~/.config/git-setmail.conf')
|
||||
CONFIG=os.path.expanduser('~/.config/git-setmail.json')
|
||||
|
||||
def main():
|
||||
try:
|
||||
|
@ -15,22 +22,21 @@ def main():
|
|||
print('Could not find origin, not setting email.')
|
||||
return 1
|
||||
|
||||
combinations = sys.argv[1:]
|
||||
if len(combinations) == 0:
|
||||
if os.path.isfile(CONFIG):
|
||||
combinations = open(CONFIG).read().split('\n')
|
||||
else:
|
||||
print('Neither CLI arguments nor config ({}) found.'.format(CONFIG))
|
||||
return 1
|
||||
if os.path.isfile(CONFIG):
|
||||
combinations = json.loads(open(CONFIG).read())
|
||||
else:
|
||||
print('Config ({}) found.'.format(CONFIG))
|
||||
return 1
|
||||
|
||||
for combi in combinations:
|
||||
email, match = combi.split(':', 1)
|
||||
if re.search(match, repo):
|
||||
if email == subprocess.check_output(['git', 'config', 'user.email'], universal_newlines=True).strip():
|
||||
print('Email correctly set to "{}", not modifying.'.format(email))
|
||||
if re.search(combi['match'], repo):
|
||||
if combi['email'] == subprocess.check_output(['git', 'config', 'user.email'], universal_newlines=True).strip():
|
||||
print('Email correctly set to "{}", not modifying.'.format(combi['email']))
|
||||
else:
|
||||
print('Found repo "{}", setting email to "{}"...'.format(repo, email))
|
||||
subprocess.check_call(['git', 'config', 'user.email', email])
|
||||
print('Found repo "{}", setting email to "{}"...'.format(repo, combi['email']))
|
||||
subprocess.check_call(['git', 'config', 'user.email', combi['email']])
|
||||
if 'gpg-key' in combi and combi['gpg-key'] != '':
|
||||
subprocess.check_call(['git', 'config', 'user.signingkey', combi['gpg-key']])
|
||||
break
|
||||
|
||||
return 0
|
||||
|
|
Loading…
Reference in a new issue