tj.git-extras/bin/git-coauthor
2019-12-20 18:22:06 +08:00

18 lines
452 B
Bash
Executable file

#!/usr/bin/env bash
set -e -o pipefail
coauthor=$1
email=$2
test -z "$coauthor" && echo "co-author required." 1>&2 && exit 1
test -z "$email" && echo "co-author email required." 1>&2 && exit 1
old_message="$(git log --format=%B -n1)"
if [[ "$old_message" == *"Co-authored-by:"* ]]; then
git commit --amend -m "$old_message
Co-authored-by: $coauthor <$email>"
else
git commit --amend -m "$old_message" -m "Co-authored-by: $coauthor <$email>"
fi