Skip to content

Instantly share code, notes, and snippets.

@hoffm
Created May 15, 2023 15:48
Show Gist options
  • Save hoffm/4068c9fbf2b2da10e4cf1e6c299d8ef0 to your computer and use it in GitHub Desktop.
Save hoffm/4068c9fbf2b2da10e4cf1e6c299d8ef0 to your computer and use it in GitHub Desktop.
Script for automating co-authored commit messages to facilitate pair programming
#!/usr/bin/env bash
# Based on https://github.com/spinningarrow/git-coauthors/
# Runs "git commit" and initializes the commit editor with a co-authorship trailer
# matching the argument you provided. Will only search past commiters to the current
# repo and branch.
#
# $ pair-commit melba
# -> Opens up commit editor populated with the following trailer:
# "Co-authored-by: Melba Roy Mouton <mrmoulton@nasa.gov>"
#
# You can pass the "-s" flag to output the trailer without starting a commit.
#
# $ pair-commit -s melba
# -> Returns "Co-authored-by: Melba Roy Mouton <mrmoulton@nasa.gov>"
search_term=${!#}
trailer=$(git shortlog -sne | cut -f2- | awk '{ print "Co-authored-by: " $0; }' | grep -i $search_term)
command="git commit --trailer"
while getopts 's' opt; do
case $opt in
s) command="echo" ;;
esac
done
$command "$trailer"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment