#!/usr/bin/env zsh

doc="usage: $(basename $0) [-h]

Output the last commit id of the git repository. If not a git repository and
\${GIT_COMMIT_ID} is set, output the value of \${GIT_COMMIT_ID}. Otherwise,
output nothing and exit with 1.

optional arguments:
  -h, --help         show this help message and exit
"

zparseopts -D -E -F - h=help -help=help
if (( ${#help} > 0 )); then
    echo ${doc}
    exit 0
fi

{
    git rev-parse --short head 2>/dev/null
} || if [[ -v GIT_COMMIT_ID ]] {
    echo ${GIT_COMMIT_ID}
} else {
    exit 1
}
