Skip to content

Instantly share code, notes, and snippets.

@radditude
Last active February 15, 2019 01:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save radditude/534ef5d48aaac74f6b66269fbe9bf9a8 to your computer and use it in GitHub Desktop.
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
# 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 <jsmith@fakeemail.test>"
elif match $1 jane; then echo "Jane Doe <janedoe@fakeemail.test>"
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