Set email based on git remotes
This commit is contained in:
parent
b7feb889fe
commit
1f31c9a6cc
2 changed files with 47 additions and 0 deletions
|
@ -1,8 +1,16 @@
|
|||
#!/bin/bash -e
|
||||
|
||||
### Fix committer email by repo
|
||||
|
||||
git setmail >/dev/null
|
||||
|
||||
### Commit
|
||||
|
||||
vault-gpg $(grep default-key ~/.gnupg/gpg.conf | cut -d ' ' -f 2)
|
||||
git commit -S -v "$@"
|
||||
|
||||
### Count productivity habit
|
||||
|
||||
PROD_TASK=$(habitica https://habitica.com/api/v3/tasks/user | jq -r '.data | map(select(.text=="productivity").id)[0]')
|
||||
|
||||
if ! ( habitica -sS -o /dev/null -X POST https://habitica.com/api/v3/tasks/${PROD_TASK}/score/up ); then
|
||||
|
|
39
bin/git-setmail
Executable file
39
bin/git-setmail
Executable file
|
@ -0,0 +1,39 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
# Usage: git setmail myemail@example.com:"github.com:myprefix" myothermail@example.com:".*"
|
||||
#
|
||||
# Configuration format: One combination per line `<email>:<match regex>`
|
||||
|
||||
import sys, re, subprocess, os.path
|
||||
|
||||
CONFIG=os.path.expanduser('~/.config/git-setmail.conf')
|
||||
|
||||
def main():
|
||||
try:
|
||||
repo = [x.split()[1] for x in subprocess.check_output(['git', 'remote', '-v'], universal_newlines=True).split('\n') if re.match('origin.*\(push\)', x)][0]
|
||||
except:
|
||||
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
|
||||
|
||||
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))
|
||||
else:
|
||||
print('Found repo "{}", setting email to "{}"...'.format(repo, email))
|
||||
subprocess.check_call(['git', 'config', 'user.email', email])
|
||||
break
|
||||
|
||||
return 0
|
||||
|
||||
if __name__ == "__main__":
|
||||
exit(main())
|
Loading…
Reference in a new issue