#!/bin/sh

# Change directory to the root of the Git repository
cd "$(git rev-parse --show-toplevel)"

# Get the version from Git tags if not provided
if [ -z "$V" ]; then
    V=$(git describe --tags | sed -E -e 's/-[^-]+$//')
fi

# Create a temporary file
T=$(mktemp)

echo '"""Package version."""' > ${T}
echo '' >> ${T}
echo "VERSION = \"${V}\"" >> ${T}

cmp "$T" pyprland/version.py >/dev/null || {
    cp "$T" pyprland/version.py
    echo "Version updated to ${V}"
}

# Remove the temporary file
rm "$T"
