version.sh: fix empty result when git describe fails

fixes an error in travis, which makes a shallow clone of 50 commits.
if the last tag is older than 50 commits, we get:
"fatal: No names found, cannot describe anything."

this caused a premature exit due to an assert error in safe_write()
on this line: assert (count > 0);

because the version variable in tinyproxy was empty.
This commit is contained in:
rofl0r 2020-09-06 19:58:21 +01:00
parent 0d26fab317
commit f1a6d063b0

View File

@ -5,8 +5,12 @@ GIT_DIR="${SCRIPT_DIR}/../.git"
if test -d "${GIT_DIR}" ; then
if type git >/dev/null 2>&1 ; then
git describe --match '[0-9]*.[0-9]*.[0-9]*' 2>/dev/null \
| sed -e 's/-/-git-/'
gitstr=$(git describe --match '[0-9]*.[0-9]*.[0-9]*' 2>/dev/null)
if test "x$?" != x0 ; then
sed 's/$/-git/' < VERSION
else
printf "%s\n" "$gitstr" | sed -e 's/-/-git-/'
fi
else
sed 's/$/-git/' < VERSION
fi