1
0
mirror of https://github.com/openshift/installer.git synced 2026-02-06 18:47:19 +01:00
Files
installer/git-version
Geoff Greer e20541a5b5 Clean up git-version script.
- bash doesn't always exist in /bin
- Use $() instead of backticks
- Wrap string in double-quotes to prevent globbing/splitting. (see https://github.com/koalaman/shellcheck/wiki/SC2086)
2017-05-01 11:06:52 -07:00

24 lines
504 B
Bash
Executable File

#!/usr/bin/env bash
set -e
# pull the current git commit hash
COMMIT=$(git rev-parse HEAD)
# check if the current commit has a matching tag
TAG=$(git describe --exact-match --abbrev=0 --tags ${COMMIT} 2> /dev/null || true)
# use the matching tag as the version, if available
if [ -z "$TAG" ]; then
VERSION=$COMMIT
else
VERSION=$TAG
fi
# check for changed files (not untracked files)
if [ -n "$(git diff --shortstat 2> /dev/null | tail -n1)" ]; then
VERSION="${VERSION}_dirty"
fi
echo "$VERSION"