blob: fb7d459bca2a5e6c38290ee30878333455ef4584 (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
#!/bin/sh

# Writes a "CGIT_VERSION = ..." line to the output file (default: VERSION),
# for the build to include. Run from the project root so `git describe` acts
# on cgit rather than the bundled Git submodule.
#
# Usage: gen-version.sh <fallback-version> [output-file]

V=$1
OUT=${2:-VERSION}

# Prefer `git describe` when run at the top of the cgit working tree,
# keeping the fallback when it fails, as in a shallow tagless clone.
if test "$(git rev-parse --git-dir 2>/dev/null)" = '.git'
then
	D=$(git describe --abbrev=4 HEAD 2>/dev/null)
	test -n "$D" && V=$D
fi

new="CGIT_VERSION = $V"
old=$(cat "$OUT" 2>/dev/null)

# Exit if the version is already up to date.
test "$old" = "$new" && exit 0

echo "$new" > "$OUT"
cat "$OUT"