Files
orca/server/build/git-hash.sh
Zheng Kai 1b107ed035 up
2023-03-29 17:55:21 +08:00

27 lines
485 B
Bash
Executable File

#!/bin/bash
HASH=$(git rev-parse --short HEAD 2>/dev/null || :)
if [ -z "$HASH" ]; then
echo "empty"
exit
fi
TAG=$(git describe --exact-match "$HASH" 2>/dev/null | head -n 1)
if [ -n "$TAG" ]; then
HASH="$TAG"
fi
ST=$(git status -s -u | head -n 1)
if [ -n "$ST" ]; then
HASH="${HASH}-dirty"
fi
BRANCH=$(git branch --no-color 2>/dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1/")
if [[ "$BRANCH" == *"("* ]]; then
BRANCH=''
else
BRANCH="${BRANCH}:"
fi
echo "${BRANCH}${HASH}"