Debian Codegraph @

scripts/get-git-ref

raw
1 #!/bin/bash
2 # GDBus++ - glib2 GDBus C++ wrapper
3 #
4 # SPDX-License-Identifier: AGPL-3.0-only
5 #
6 # Copyright (C) OpenVPN Inc <[email protected]>
7 # Copyright (C) David Sommerseth <[email protected]>
8 #
9
10 PROJECT_ROOT="$(dirname $0)/.."
11
12 if [ ! -e "${PROJECT_ROOT}/.git" ]; then
13 cat "${PROJECT_ROOT}/version.txt"
14 exit 0
15 fi
16
17 if [ "$1" == "--dist" ]; then
18 cp -v ${MESON_BUILD_ROOT}/version.txt ${MESON_DIST_ROOT}/version.txt
19 exit 0
20 fi
21
22 #
23 # Retrieve the version based on the git tree
24 #
25 # If a version tag is found (always prefixed with 'v'), this value
26 # is used. Otherwise compose a version string based on branch name
27 # and commit reference
28
29 gitcmd()
30 {
31 git --git-dir ${PROJECT_ROOT}/.git $*
32 }
33
34 VERSION="$(gitcmd describe --always --tags 2>/dev/null)"
35 if [ $? -ne 0 ]; then
36 ver_file="$(dirname $0)/../version.txt"
37 if [ -r "$ver_file" ]; then
38 cat "$ver_file"
39 else
40 echo "unkown_version"
41 fi
42 exit 0
43 fi
44
45
46 # Only accept explicit tag references, not a reference
47 # derived from a tag reference, such as "v3_beta-36-gcd68aee"
48 echo ${VERSION} | grep -qE "^v[[:digit:]]+(|_[[:alnum:]]+)$"
49 ec=$?
50
51 if [ $ec -ne 0 ]; then
52 # Presume not a version tag, so use commit reference
53 echo "$(gitcmd rev-parse --symbolic-full-name HEAD | cut -d/ -f3- | sed -e 's@/@_@g')_$(gitcmd rev-parse --short=16 HEAD)"
54 exit 0
55 fi
56 echo ${VERSION:1}