xref: /dflybsd-src/tools/gitrev.sh (revision ee48961f69795d85deef944236be3fb4ee65874f)
17f1cdf2dSSimon Schubert#!/bin/sh
27f1cdf2dSSimon Schubert
3ea9c9026SSimon Schubert# We might be run during buildkernel/world, where PATH is
4ea9c9026SSimon Schubert# limited.  To reach git, we need to add the directories
5ea9c9026SSimon Schubert# git might be located in.  Not a very nice solution, but
6ea9c9026SSimon Schubert# it works well enough.
7*ee48961fSSascha WildnerPATH=$PATH:/usr/local/bin:/usr/pkg/bin
8ea9c9026SSimon Schubert
9f5a0be59SSimon Schubertsrcdir=${1:-$(dirname $0)}
10f5a0be59SSimon Schubert
11f5a0be59SSimon Schubert[ -n "$srcdir" ] && cd "$srcdir"
12f5a0be59SSimon Schubert
13ea9c9026SSimon Schubertif ! git version >/dev/null 2>&1 ||
147f1cdf2dSSimon Schubert	! cd "$(dirname "$0")" ||
157f1cdf2dSSimon Schubert	! git rev-parse --git-dir >/dev/null 2>&1
167f1cdf2dSSimon Schubertthen
177f1cdf2dSSimon Schubert	exit 0
187f1cdf2dSSimon Schubertfi
197f1cdf2dSSimon Schubert
20ea9c9026SSimon Schubertv=$(git describe --abbrev=5 2>/dev/null || git rev-parse --short HEAD)
21ea9c9026SSimon Schubertv=$(echo "$v" | sed -e 'y/-/./')
229b10ce04SSimon Schubert
239b10ce04SSimon Schubert# Takes too long when running over NFS
249b10ce04SSimon Schubert#git update-index -q --refresh
259b10ce04SSimon Schubert#[ -z "$(git diff-index --name-only HEAD --)" ] || v="$v*"
267f1cdf2dSSimon Schubert
277f1cdf2dSSimon Schubertecho "$v"
287f1cdf2dSSimon Schubertexit 0
29