unixorn/git-extra-commands

View on GitHub
bin/git-credit

Summary

Maintainability
Test Coverage
#!/usr/bin/env bash
#
# A very slightly quicker way to credit an author on the latest commit.
#
# $1 - The full name of the author.
# $2 - The email address of the author.
#
# Examples
#
#   git credit "Zach Holman" zach@example.com
#

set -o pipefail
if [[ -n "$DEBUG" ]]; then
  set -x
fi

fail() {
  printf '%s\n' "$1" >&2  ## Send message to stderr. Exclude >&2 if you don't want it that way.
  exit "${2-1}"  ## Return a code specified by $2 or 1 by default.
}

function has() {
  which "$@" > /dev/null 2>&1
}

if [[ $# -lt 2 ]]; then
  myname=$(basename "$0")
  fail "Usage: $myname AUTHORS_FULL_NAME AUTHORS_EMAIL_ADDRESS"
fi

exec git commit --amend --author "$1 <$2>" -C HEAD