Created
May 15, 2023 15:48
-
-
Save hoffm/4068c9fbf2b2da10e4cf1e6c299d8ef0 to your computer and use it in GitHub Desktop.
Script for automating co-authored commit messages to facilitate pair programming
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
#!/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 <[email protected]>" | |
# | |
# 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 <[email protected]>" | |
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