File: get-git-ref

package info (click to toggle)
gdbuspp 3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,116 kB
  • sloc: cpp: 9,462; python: 477; sh: 215; makefile: 5
file content (56 lines) | stat: -rwxr-xr-x 1,334 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
#  GDBus++ - glib2 GDBus C++ wrapper
#
#  SPDX-License-Identifier: AGPL-3.0-only
#
#  Copyright (C)  OpenVPN Inc <sales@openvpn.net>
#  Copyright (C)  David Sommerseth <davids@openvpn.net>
#

PROJECT_ROOT="$(dirname $0)/.."

if [ ! -e "${PROJECT_ROOT}/.git" ]; then
	cat "${PROJECT_ROOT}/version.txt"
	exit 0
fi

if [ "$1" == "--dist" ]; then
	cp -v ${MESON_BUILD_ROOT}/version.txt ${MESON_DIST_ROOT}/version.txt
	exit 0
fi

#
#  Retrieve the version based on the git tree
#
#  If a version tag is found (always prefixed with 'v'), this value
#  is used.  Otherwise compose a version string based on branch name
#  and commit reference

gitcmd()
{
	git --git-dir ${PROJECT_ROOT}/.git $*
}

VERSION="$(gitcmd describe --always --tags 2>/dev/null)"
if [ $? -ne 0 ]; then
	ver_file="$(dirname $0)/../version.txt"
	if [ -r "$ver_file" ]; then
		cat "$ver_file"
	else
		echo "unkown_version"
	fi
	exit 0
fi


#  Only accept explicit tag references, not a reference
#  derived from a tag reference, such as "v3_beta-36-gcd68aee"
echo ${VERSION} | grep -qE "^v[[:digit:]]+(|_[[:alnum:]]+)$"
ec=$?

if [ $ec -ne 0  ]; then
	# Presume not a version tag, so use commit reference
	echo "$(gitcmd rev-parse --symbolic-full-name HEAD | cut -d/ -f3- | sed -e 's@/@_@g')_$(gitcmd rev-parse --short=16 HEAD)"
	exit 0
fi
echo ${VERSION:1}