1:255.16-alt1
[systemd_ALT.git] / tools / meson-vcs-tag.sh
blob4a8dc89ab2c21a34b467b5e1d95afab5c6f58c7f
1 #!/usr/bin/env bash
2 # SPDX-License-Identifier: LGPL-2.1-or-later
4 set -u
5 set -o pipefail
7 dir="${1:?}"
8 fallback="${2:?}"
9 version_tag="${3:-}"
11 if [ -n "${version_tag}" ]; then
12 # If -Dversion_tag= was used, just use that without further changes.
13 echo "${version_tag}"
14 else
15 # Check that we have either .git/ (a normal clone) or a .git file (a work-tree)
16 # and that we don't get confused if a tarball is extracted in a higher-level
17 # git repository.
19 # If the working tree has no tags (CI builds), the first git-describe will fail
20 # and we fall back to project_version-commitid instead.
22 c=''
23 if [ -e "${dir}/.git" ]; then
24 c="$(git -C "$dir" describe --abbrev=7 --dirty=^ 2>/dev/null)"
25 if [ -z "$c" ]; then
26 # This call might still fail with permission issues
27 suffix="$(git -C "$dir" describe --always --abbrev=7 --dirty=^ 2>/dev/null)"
28 [ -n "$suffix" ] && c="${fallback}-${suffix}"
31 [ -z "$c" ] && c="${fallback}"
32 echo "$c" | sed 's/^v//; s/-rc/~rc/'