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
|
### Commit
|
||||||
|
|
||||||
step "Loading passphrase for GPG key..."
|
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..."
|
step "Issuing commit..."
|
||||||
git commit -S -v "$@"
|
git commit -S -v "$@"
|
||||||
|
|
|
@ -1,12 +1,19 @@
|
||||||
#!/usr/bin/env python3
|
#!/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():
|
def main():
|
||||||
try:
|
try:
|
||||||
|
@ -15,22 +22,21 @@ def main():
|
||||||
print('Could not find origin, not setting email.')
|
print('Could not find origin, not setting email.')
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
combinations = sys.argv[1:]
|
if os.path.isfile(CONFIG):
|
||||||
if len(combinations) == 0:
|
combinations = json.loads(open(CONFIG).read())
|
||||||
if os.path.isfile(CONFIG):
|
else:
|
||||||
combinations = open(CONFIG).read().split('\n')
|
print('Config ({}) found.'.format(CONFIG))
|
||||||
else:
|
return 1
|
||||||
print('Neither CLI arguments nor config ({}) found.'.format(CONFIG))
|
|
||||||
return 1
|
|
||||||
|
|
||||||
for combi in combinations:
|
for combi in combinations:
|
||||||
email, match = combi.split(':', 1)
|
if re.search(combi['match'], repo):
|
||||||
if re.search(match, repo):
|
if combi['email'] == subprocess.check_output(['git', 'config', 'user.email'], universal_newlines=True).strip():
|
||||||
if email == subprocess.check_output(['git', 'config', 'user.email'], universal_newlines=True).strip():
|
print('Email correctly set to "{}", not modifying.'.format(combi['email']))
|
||||||
print('Email correctly set to "{}", not modifying.'.format(email))
|
|
||||||
else:
|
else:
|
||||||
print('Found repo "{}", setting email to "{}"...'.format(repo, email))
|
print('Found repo "{}", setting email to "{}"...'.format(repo, combi['email']))
|
||||||
subprocess.check_call(['git', 'config', 'user.email', 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
|
break
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
Loading…
Reference in a new issue