xref: /netbsd-src/external/gpl2/dtc/dist/scripts/setlocalversion (revision cc7d2833ecf67da5a5ddc470841931eb9f6723e4)
1b8ae3907Smacallan#!/bin/sh
2*cc7d2833Sskrll# SPDX-License-Identifier: GPL-2.0-or-later
3b8ae3907Smacallan# Print additional version information for non-release trees.
4b8ae3907Smacallan
5b8ae3907Smacallanusage() {
6b8ae3907Smacallan	echo "Usage: $0 [srctree]" >&2
7b8ae3907Smacallan	exit 1
8b8ae3907Smacallan}
9b8ae3907Smacallan
10b8ae3907Smacallancd "${1:-.}" || usage
11b8ae3907Smacallan
12b8ae3907Smacallan# Check for git and a git repo.
13b8ae3907Smacallanif head=`git rev-parse --verify HEAD 2>/dev/null`; then
14b8ae3907Smacallan	# Do we have an untagged version?
15b8ae3907Smacallan	if git name-rev --tags HEAD | grep -E '^HEAD[[:space:]]+(.*~[0-9]*|undefined)$' > /dev/null; then
16b8ae3907Smacallan		printf '%s%s' -g `echo "$head" | cut -c1-8`
17b8ae3907Smacallan	fi
18b8ae3907Smacallan
19b8ae3907Smacallan	# Are there uncommitted changes?
20b8ae3907Smacallan	if git diff-index HEAD | read dummy; then
21b8ae3907Smacallan		printf '%s' -dirty
22b8ae3907Smacallan	fi
23b8ae3907Smacallanfi
24