-
Notifications
You must be signed in to change notification settings - Fork 1
/
get-revision.sh
executable file
·91 lines (74 loc) · 2.09 KB
/
get-revision.sh
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash
GITCMD=git
# First, check if git is available at all...
type $GITCMD > /dev/null 2>&1
DIFFCODE=$?
if [[ "$DIFFCODE" -ne 0 ]]
then
echo "ERROR: Git not found."
exit 1
fi
# Run git diff to check for local changes.
# Return code 0 indicates no changes, 1 indicates changes are present.
# Exit code 129 is an error when not inside a Git repo.
# Use code 129 to avoid errors for the describe and log commands.
$GITCMD diff --quiet 2> /dev/null
DIFFCODE=$?
if [[ "$DIFFCODE" -ne 129 ]]
then
FULLHASH=`$GITCMD rev-parse HEAD`
DESC=`$GITCMD describe --always --tag`
BRANCH=`$GITCMD rev-parse --abbrev-ref HEAD | tr '\n' ' ' | sed -e 's/ *$//'`
LOCALCHANGED=${DIFFCODE}
LOCALCHANGES=`$GITCMD diff --stat`
else
FULLHASH="unknown"
DESC="exported"
BRANCH="exported"
LOCALCHANGED=-1
LOCALCHANGES=""
fi
echo "// Written in the D programming language."
echo
echo "/**"
echo " Immutable variables that hold git revision information."
echo " This file has been automatically generated by \$(D $0)."
echo
# Code for revision.d
read -d '' DVARS <<EOF
Copyright: Stefan Frijters 2011-2015
License: \$(HTTP www.gnu.org/licenses/gpl-3.0.txt, GNU General Public License, version 3 (GPL-3.0)).
Authors: Stefan Frijters
*/
module dlbc.revision;
static immutable {
/**
Full hash of the git revision: \$(D git rev-parse HEAD).
*/
string revisionHash = \"$FULLHASH\";
/**
Short description of the git revision: \$(D git describe --always --tag).
*/
string revisionDesc = \"$DESC\";
/**
Git branch: \$(D git rev-parse --abbrev-ref HEAD).
*/
string revisionBranch = \"$BRANCH\";
/**
Exit code of \$(D git diff).
*/
int revisionChanged = $LOCALCHANGED;
/**
List of changed files compared to HEAD: \$(D git diff --stat)
*/
string revisionChanges = \"$LOCALCHANGES\";
/**
This string exists as a string literal to be able to use
the 'strings' command to retrieve the version of the executable,
even when it cannot be run on the current platform:
\$(D strings dlbc | grep "DLBC VERSION")
*/
string revisionString = \"DLBC VERSION $DESC $BRANCH $LOCALCHANGED\";
}
EOF
echo "$DVARS"