#!/bin/sh -e
#
# git-stub - stub git commits (touch a file, stage file, commit file) for demo
#
# usage:
#   git stub A
#   git stub B
#   git stub foo bar baz
#   git stub
#   git stub
#   git stub
#
# if invoked without arguments it will start a counter and generate unique,
# alphabetically sequential commits.

while test "${#}" -gt 0; do
  # shellcheck disable=SC2249
  case "$1" in
    -h)
      awk 'NR == 1 { next } /^$/ { exit } { print substr($0, 3) }' "$0"
      exit 0
      ;;
    -x)
      set -x
      ;;
  esac
done
shift "$((OPTIND - 1))"

if [ "$#" -eq 0 ]; then
  # shellcheck disable=SC2312
  set -- "$(git counter | alphaindex)"
fi

for f in "$@"; do
  test -e "${f}" && exit 1

  printf 'File %s.\n' "${f}" >"${f}"
  git add "${f}"
  git commit --message="Add-${f}"
done
