#!/bin/sh
set -eu

commit=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
remote=https://github.com/runxhq/runx.git
branch=refs/heads/fix/442-operator-first
state=${RUNX_ISSUE_TO_PR_GIT_STATE:-.runx/issue-to-pr-fixture-ref}

case "$*" in
  "-c core.fsmonitor=false rev-parse --verify ${commit}^{commit}")
    printf '%s\n' "$commit"
    ;;
  "-c core.fsmonitor=false ls-remote --refs ${remote} ${branch}")
    if [ -f "$state" ]; then
      printf '%s\t%s\n' "$commit" "$branch"
    fi
    ;;
  "-c core.fsmonitor=false push --porcelain ${remote} ${commit}:${branch}")
    /bin/mkdir -p "$(/usr/bin/dirname "$state")"
    : > "$state"
    printf '%s\n' "To ${remote}"
    ;;
  *)
    printf '%s\n' "unexpected fixture git invocation: $*" >&2
    exit 2
    ;;
esac
