]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
git-version-gen: Support git-archive tarballs.
authorSimon Josefsson <simon@josefsson.org>
Fri, 27 Dec 2024 09:44:16 +0000 (10:44 +0100)
committerSimon Josefsson <simon@josefsson.org>
Fri, 27 Dec 2024 11:32:51 +0000 (12:32 +0100)
* build-aux/git-version-gen: Use .tarball-version-git as final guess.

build-aux/git-version-gen

index 780b7e99f73275226e1aeca60ba4cffa5cad25b0..8076685df493a705a9c3f4cbd600c3189bf2d8cf 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/sh
 # Print a version string.
-scriptversion=2024-07-04.10; # UTC
+scriptversion=2024-12-27.09; # UTC
 
 # Copyright (C) 2007-2024 Free Software Foundation, Inc.
 #
@@ -18,13 +18,20 @@ scriptversion=2024-07-04.10; # UTC
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
 # This script is derived from GIT-VERSION-GEN from GIT: https://git-scm.com/.
-# It may be run two ways:
+
+# It may be run in the following ways, presuming the script is invoked
+# like "./git-version-gen .tarball-version":
+#
 # - from a git repository in which the "git describe" command below
 #   produces useful output (thus requiring at least one signed tag)
-# - from a non-git-repo directory containing a .tarball-version file, which
-#   presumes this script is invoked like "./git-version-gen .tarball-version".
+#
+# - from a "make dist" non-git-repo directory containing a
+#   .tarball-version file
+#
+# - from a "git archive" non-git-repo directory containing a
+#   .tarball-version-git file
 
-# In order to use intra-version strings in your project, you will need two
+# In order to use intra-version strings in your project, you will need some
 # separate generated version string files:
 #
 # .tarball-version - present only in a distribution tarball, and not in
@@ -37,6 +44,12 @@ scriptversion=2024-07-04.10; # UTC
 #   hooks to force a reconfigure at distribution time to get the value
 #   correct, without penalizing normal development with extra reconfigures.
 #
+# .tarball-version-git - a file committed to git containing a single
+#   line with the string $Format:%(describe)$ and that the file is
+#   marked in .gitattributes with ".tarball-version-git export-subst".
+#   If the file doesn't exist or the export-subst keyword wasn't
+#   effective, the file is ignored.
+#
 # .version - present in a checked-out repository and in a distribution
 #   tarball.  Usable in dependencies, particularly for files that don't
 #   want to depend on config.h but do want to track version changes.
@@ -69,7 +82,12 @@ scriptversion=2024-07-04.10; # UTC
 #      mv $@-t $@
 # dist-hook:
 #      echo '$(VERSION)' > $(distdir)/.tarball-version
-
+#
+# To setup support for "git archive" tarballs, use the following:
+#
+# echo '$Format:%(describe)$' > .tarball-version-git
+# echo '.tarball-version-git export-subst' >> .gitattributes
+# git commit -a -m "Add .tarball-version-git for git-version-gen."
 
 me=$0
 
@@ -195,6 +213,13 @@ else
     v=$fallback
 fi
 
+if test "x$v" = xUNKNOWN \
+        && test -f ${tarball_version_file}-git \
+        && head -1 ${tarball_version_file}-git \
+            | grep -v '^$Format' > /dev/null 2>&1; then
+    v=$(head -1 ${tarball_version_file}-git)
+fi
+
 v=`echo "$v" |sed "s/^$prefix//"`
 
 # Test whether to append the "-dirty" suffix only if the version