-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-version.sh
executable file
·44 lines (36 loc) · 1.05 KB
/
git-version.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
#!/bin/sh
oldcwd="$(pwd)"
topdir="$(cd "$(dirname "$0")" && pwd)"
gitdir="${topdir}/.git"
version_h="$1"
test "x$version_h" = "x" && exit
cd "$topdir"
git_version="unknown-version"
if test -d "${gitdir}" && test "x$(git rev-parse HEAD)" != "x"; then
if git_version="$(git describe | ${SED-sed} 's/^freemcan-//')"; then
if git diff-files --quiet && git diff-index --cached --quiet HEAD; then
:
else
git_version="${git_version}-dirty"
fi
git_branch="$(git symbolic-ref HEAD 2> /dev/null | sed -n 's,^refs/heads/,,p' )"
if test "x${git_branch}" != "x"; then
git_version="${git_version} (${git_branch} branch)"
else
git_version="${git_version} (HEAD not on branch)"
fi
fi
fi
cd "$oldcwd"
cat>"${version_h}.tmp"<<EOF
/* This file was automatically generated by "$0" */
#ifndef GIT_VERSION_H
#define GIT_VERSION_H
#define GIT_VERSION "${git_version}"
#endif /* GIT_VERSION_H */
EOF
if test -f "${version_h}" && cmp "${version_h}.tmp" "${version_h}"; then
rm -f "${version_h}.tmp"
else
mv -f "${version_h}.tmp" "${version_h}"
fi