• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
3
4scm_version()
5{
6	# Check for git and a git repo.
7	if test -z "$(git rev-parse --show-cdup 2>/dev/null)" &&
8	   head="$(git rev-parse --verify HEAD 2>/dev/null)"; then
9		# If we are at a tagged commit, we ignore it.
10		if [ -z "$(git describe --exact-match 2>/dev/null)" ]; then
11			# Add -g and 8 hex chars.
12			printf -- '-g%.8s' "$head"
13		fi
14		# Check for uncommitted changes.
15		# This script must avoid any write attempt to the source tree,
16		# which might be read-only.
17		# You cannot use 'git describe --dirty' because it tries to
18		# create .git/index.lock .
19		# First, with git-status, but --no-optional-locks is only
20		# supported in git >= 2.14, so fall back to git-diff-index if
21		# it fails. Note that git-diff-index does not refresh the
22		# index, so it may give misleading results. See
23		# git-update-index(1), git-diff-index(1), and git-status(1).
24		if {
25			git --no-optional-locks status -uno --porcelain 2>/dev/null ||
26			git diff-index --name-only HEAD
27		} | read dummy; then
28			printf '%s' -dirty
29		fi
30	fi
31}
32
33if [ -n "$EROFS_UTILS_VERSION" ]; then
34	echo "$EROFS_UTILS_VERSION"
35else
36	echo $(head -n1 VERSION)$(scm_version)
37fi
38