Blob Blame History Raw
From 1db8e2a9c58b9b1630cd7af47d6f11a8b6cb756a Mon Sep 17 00:00:00 2001
From: Jonathan Wright <jonathan@almalinux.org>
Date: Mon, 29 Apr 2024 13:06:37 -0500
Subject: [PATCH] return version even if not using git sources

Downloading the source tarball from GitHub lacks .git structure and the version will be blank.  This fixes it by using the directory name which contains the version.
---
 scripts/version | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/scripts/version b/scripts/version
index ba59e6b6aa..d9204cd1be 100755
--- a/scripts/version
+++ b/scripts/version
@@ -2,12 +2,17 @@
 set -eu
 
 cd "$(dirname "$0")/../"
-test -d .git || exit 1
 
-if git describe --tags --match 'jq-*' >/dev/null 2>&1; then
-  git describe --tags --match 'jq-*' --dirty | sed 's/^jq-//'
+if test -d .git; then
+  if git describe --tags --match 'jq-*' >/dev/null 2>&1; then
+    git describe --tags --match 'jq-*' --dirty | sed 's/^jq-//'
+  else
+    branch=$(git rev-parse --abbrev-ref HEAD)
+    commit=$(git describe --always --dirty)
+    echo "${branch}-${commit}"
+  fi
+elif [[ "$(basename $(pwd))" =~ ^jq-jq-([0-9]+\.[0-9]+(\.[0-9]+)?)$ ]]; then
+  echo ${BASH_REMATCH[1]}
 else
-  branch=$(git rev-parse --abbrev-ref HEAD)
-  commit=$(git describe --always --dirty)
-  echo "${branch}-${commit}"
+  exit 1
 fi