#!/usr/bin/env bash
#
# git-contributors - gets a newline-delimited list of committer names
# can optionally specify ref constraints
#
# usage: git contributors v1.0.0...HEAD

if [ "$#" -eq 0 ]; then
  git log --format=format:"%an" | sort | uniq -c | sort -rn
else
  # shellcheck disable=SC2016
  git shortlog --summary --numbered "$1" \
    | cut -d ' ' -f2- \
    | ruby -e 'puts $stdin.read.split("\n").sort.uniq.join(", ")'
fi
