1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
#!/usr/bin/env sh
#
# Copyright (C) 2024, Daniel Braunwarth <oss@braunwarth.dev>
#
# SPDX-License-Identifier: GPL-2.0-or-later
EXTRA_VERSION=""
# Check if we are in a git repository
if [ -z "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
exit 0
fi
# If we are on an untagged commit, append the short commit hash
if [ -z "$(git describe --tags --exact-match 2>/dev/null)" ]; then
EXTRA_VERSION="${EXTRA_VERSION}-$(git rev-parse --short HEAD)"
fi
# If the working directory is dirty, append -dirty
if [ -n "$(git --no-optional-locks status -uno --porcelain 2>/dev/null)" ]; then
EXTRA_VERSION="${EXTRA_VERSION}-dirty"
fi
printf "%s" "${EXTRA_VERSION#-}"
exit 0
|