summaryrefslogtreecommitdiff
path: root/git-version-gen
blob: 65e599c39663442e8d9c28253ab6ac692a9e515e (plain)
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/sh

DIRECTORY=$(basename "$(dirname "$(readlink -mn "$0")")")
VERFILE="version"
DEF_VER="$DIRECTORY"
TAG_PREFIX="xf86-input-wacom-"
LF='
'
UPDATE=0
FORCE=0


for ARG in "$@"; do
	if test "${ARG}" = "-u"; then UPDATE=1;
	elif test "${ARG}" = "-f"; then UPDATE=1; FORCE=1;
	fi
done

# First see if we're in a git directory and try git-describe, then
# try the $VERFILE file if present (included in release tarballs),
# and finally the default.
if test -d "${GIT_DIR:-.git}" -o -f .git &&
	VN=$(git describe --match "${TAG_PREFIX}*" --abbrev=7 HEAD 2>/dev/null) &&
	case "${VN}" in
	*${LF}*) (exit 1) ;;
	${TAG_PREFIX}*)
		git update-index -q --refresh
		test -z "$(git diff-index --name-only HEAD --)" ||
		VN="${VN}-dirty" ;;
	esac
then
	VN=$(echo "${VN}" | sed -e "s/${TAG_PREFIX}//");
	VN=$(echo "${VN}" | sed -e 's/-/./g');
elif test -f "${VERFILE}"
then
	VN=$(cat ${VERFILE}) || VN="$DEF_VER"
else
	VN="${DEF_VER}"
fi

VN=$(expr "${VN}" : v*'\(.*\)')

echo ${VN}

if test "${UPDATE}" -ne 0; then
	SAVED_VERSION=""
	if test -f "${VERFILE}"; then
		SAVED_VERSION=$(cat "${VERFILE}")
	fi
	if test "${SAVED_VERSION}" != "${VN}"; then
		FORCE=1
	fi
	if test "${FORCE}" -ne 0; then
		echo "${VN}" > "${VERFILE}"
	fi
fi