Last active
February 15, 2019 01:20
-
-
Save radditude/534ef5d48aaac74f6b66269fbe9bf9a8 to your computer and use it in GitHub Desktop.
Bash helper for committing with a co-author when pairing, with fuzzy matching for names
This file contains hidden or 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
# usage: git-commit-with jane "adding the thing" --amend | |
match(){ | |
echo "$2" | grep -q "$1" | |
} | |
commit-info () { | |
if match $1 john; then echo "John Smith <[email protected]>" | |
elif match $1 jane; then echo "Jane Doe <[email protected]>" | |
else | |
echo "No match!" | |
return 1 | |
fi | |
} | |
git-commit-with () { | |
USAGE="Usage: git-commit-with <person> <message> <opts>" | |
PERSON="$(commit-info $1)" | |
if [[ ! "$1" || ! "$2" ]]; then | |
echo "Something's missing" | |
echo $USAGE | |
return 1 | |
elif [[ "$PERSON" == "No match!" ]]; then | |
echo "Couldn't match $1 - you may need to add them to commit-info" | |
return 1 | |
elif [[ "$1" == "help" ]]; then | |
echo $USAGE | |
return 1 | |
fi | |
MESSAGE=$2 | |
OPTS=$3 | |
FULL_BODY=$(echo -e "$MESSAGE\n\n\nCo-authored-by: $PERSON") | |
git commit $OPTS -m $FULL_BODY | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment