#!/usr/bin/env bash
# SPDX-License-Identifier: AGPL-3.0-only
# Provenance-includes-location: https://github.com/cortexproject/cortex/blob/master/tools/image-tag
# Provenance-includes-license: Apache-2.0
# Provenance-includes-copyright: The Cortex Authors.

set -o errexit
set -o nounset
set -o pipefail

# Append -WIP when there are tracked, uncommitted changes (staged or unstaged),
# ignoring untracked files.
WORKING_SUFFIX=$(if [ -n "$(git status --porcelain --untracked-files=no)" ]; then echo "-WIP"; else echo ""; fi)
BRANCH_PREFIX=$(git rev-parse --abbrev-ref HEAD)
echo "${BRANCH_PREFIX//\//-}-$(git rev-parse --short=8 HEAD)$WORKING_SUFFIX"
