version.sh 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #!/bin/sh
  2. # SPDX-FileCopyrightText: (C) 2024 Oswald Buddenhagen <ossi@users.sf.net>
  3. # SPDX-License-Identifier: GPL-2.0-or-later
  4. cd $(dirname $0)
  5. test -e .git || exit
  6. mb=$(git merge-base HEAD "@{upstream}" 2> /dev/null)
  7. if test -z "$mb"; then
  8. # we presume that a failure to find a merge base means no upstream.
  9. # and no upstream may mean detached head in the middle of a rebase
  10. br=$(git branch | sed -n -e 's/^\* (no branch, rebasing \([^\)]*\))$/\1/p')
  11. if test -n "$br"; then
  12. mb=$(git merge-base HEAD "$br@{upstream}" 2> /dev/null)
  13. fi
  14. fi
  15. if test -z "$mb"; then
  16. # still no upstream, so just describe HEAD as-is.
  17. gver=$(git describe --tags HEAD)
  18. else
  19. # find out whether we have local work, and if so, collapse it into
  20. # a single suffix. otherwise, we'd cause pointless rebuilds during
  21. # development.
  22. gver=$(git describe --tags $mb)
  23. lcl=$(git rev-list -n 1 $mb..HEAD)
  24. if test -n "$lcl"; then
  25. gver="$gver-plus"
  26. fi
  27. fi
  28. gver=${gver#v}
  29. pgver=$(cat VERSION 2> /dev/null)
  30. if [ "x$gver" != "x$pgver" ]; then
  31. echo "$gver" > VERSION
  32. fi