#!/usr/bin/env sh

set -eu

usage() {
    printf %s "\
$(basename "$0") [branchname]

  Handy for copy/pasting into a pull request.
  Print list of commit hashes and titles on the current branch
  that are not on the given branch.

arguments:
  [branchname]  - Falls back to [develop > main > master].
"
  exit 1
}

if [ "$#" -eq 0 ] || [ "$1" = "-h"  ] || [ "$1" = "--help" ]; then
  usage
fi
BRANCH=""
if [ "$#" -eq 1 ]; then
  BRANCH="$1"
elif git show-ref --quiet refs/heads/develop; then
  BRANCH=develop
elif git show-ref --quiet refs/heads/main; then
  BRANCH=main
elif git show-ref --quiet refs/heads/master; then
  BRANCH=master
fi

# shellcheck disable=SC2086
git log --pretty=format:'- (%h) %s' --abbrev-commit --reverse ${BRANCH}..
