Created
August 3, 2018 08:44
-
-
Save toschneck/d702abce1c783d08cd9d53a6a2a5ac39 to your computer and use it in GitHub Desktop.
signed git committs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# add this to your bash env | |
# Set git user and signing key | |
function git-set-user() { | |
if [ "$#" -lt "1" ] | |
then | |
echo "Missing required arguments" >&2 | |
echo "Usage: $0 EMAIL [PATH_TO_GIT_REPO]" >&2 | |
exit 65 | |
fi | |
USER_EMAIL="$1" | |
USER_KEY=`gpg --with-colons -K "$USER_EMAIL" 2>/dev/null | awk -F: '$1 =="fpr" {print $10; exit}'` | |
if [ -z "$USER_KEY" ] | |
then | |
echo "Unable to retrieve GPG key for $USER_EMAIL" >&2 | |
exit 1 | |
fi | |
if [ -n "$2" ] | |
then | |
WORKING_DIR="$2" | |
else | |
WORKING_DIR="`pwd`" | |
fi | |
if [ ! -e "$WORKING_DIR/.git" ] | |
then | |
echo "Error: $WORKING_DIR is not a Git repository" >&2 | |
exit 1 | |
fi | |
set -x | |
git config --local user.email "$USER_EMAIL" | |
git config --local user.signingkey "$USER_KEY" | |
git config --local commit.gpgsign true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment