File: get-version-number

package info (click to toggle)
erofs-utils 1.8.10-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 1,128 kB
  • sloc: ansic: 20,839; makefile: 164; sh: 33
file content (37 lines) | stat: -rwxr-xr-x 1,186 bytes parent folder | download | duplicates (2)
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
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0

scm_version()
{
	# Check for git and a git repo.
	if test -z "$(git rev-parse --show-cdup 2>/dev/null)" &&
	   head="$(git rev-parse --verify HEAD 2>/dev/null)"; then
		# If we are at a tagged commit, we ignore it.
		if [ -z "$(git describe --exact-match 2>/dev/null)" ]; then
			# Add -g and 8 hex chars.
			printf -- '-g%.8s' "$head"
		fi
		# Check for uncommitted changes.
		# This script must avoid any write attempt to the source tree,
		# which might be read-only.
		# You cannot use 'git describe --dirty' because it tries to
		# create .git/index.lock .
		# First, with git-status, but --no-optional-locks is only
		# supported in git >= 2.14, so fall back to git-diff-index if
		# it fails. Note that git-diff-index does not refresh the
		# index, so it may give misleading results. See
		# git-update-index(1), git-diff-index(1), and git-status(1).
		if {
			git --no-optional-locks status -uno --porcelain 2>/dev/null ||
			git diff-index --name-only HEAD
		} | read dummy; then
			printf '%s' -dirty
		fi
	fi
}

if [ -n "$EROFS_UTILS_VERSION" ]; then
	echo "$EROFS_UTILS_VERSION"
else
	echo $(head -n1 VERSION)$(scm_version)
fi