yambar/generate-version.sh
Daniel Eklöf d68785eb2b
generate-version: check for .git directory in *src* dir
Instead of trying to run `git --rev-parse --is-inside-work-tree`,
check if there's a .git directory under the source directory.

This should fix an issue where we incorrectly decided we where in a
foot git clone when we're just a subdirectory under another
repository.
2020-03-06 22:16:33 +01:00

38 lines
875 B
Bash
Executable file

#!/bin/sh
set -e
default_version=${1}
src_dir=${2}
out_file=${3}
# echo "default version: ${default_version}"
# echo "source directory: ${src_dir}"
# echo "output file: ${out_file}"
if [ -d "${src_dir}/.git" ] && command -v git > /dev/null; then
workdir=$(pwd)
cd "${src_dir}"
git_version=$(git describe --always --tags)
git_branch=$(git rev-parse --abbrev-ref HEAD)
cd "${workdir}"
new_version="${git_version} ($(env LC_TIME=C date "+%b %d %Y"), branch '${git_branch}')"
else
new_version="${default_version}"
fi
new_version="#define YAMBAR_VERSION \"${new_version}\""
if [ -f "${out_file}" ]; then
old_version=$(cat "${out_file}")
else
old_version=""
fi
# echo "old version: ${old_version}"
# echo "new version: ${new_version}"
if [ "${old_version}" != "${new_version}" ]; then
echo "${new_version}" > "${out_file}"
fi