summaryrefslogtreecommitdiffstats
path: root/scripts/repo-info.sh
diff options
context:
space:
mode:
authorJohn Stebbins <[email protected]>2015-08-25 09:48:14 -0700
committerJohn Stebbins <[email protected]>2015-08-25 14:17:11 -0700
commit4889bc95883dd2cb0eb679d381d15385b930bcfa (patch)
tree7a20ea87161e790b84b7f1cd4b0d10010201f995 /scripts/repo-info.sh
parentd4d9555eca3048d281d510bd51267ce67142acd6 (diff)
build: use git version info instead of svn
Migrate from svn to git. Since our build system automatically generates version info from the svn repo, this needs to change when we move the repo to git.
Diffstat (limited to 'scripts/repo-info.sh')
-rwxr-xr-xscripts/repo-info.sh67
1 files changed, 67 insertions, 0 deletions
diff --git a/scripts/repo-info.sh b/scripts/repo-info.sh
new file mode 100755
index 000000000..72d974d04
--- /dev/null
+++ b/scripts/repo-info.sh
@@ -0,0 +1,67 @@
+#! /bin/bash
+#
+# Retrieves git repository info for directory ${1} using command ${2}
+
+# Args
+REPO_DIR='.'
+if [[ ${1} ]]; then
+ REPO_DIR=${1}
+fi
+GIT_EXE='git'
+if [[ ${2} ]]; then
+ GIT_EXE=${2}
+fi
+
+# Switch to working directory
+if ! cd ${REPO_DIR} 2>/dev/null; then
+ echo "Invalid directory ${REPO_DIR}." 1>&2
+ exit 1
+fi
+
+# Check whether we have git
+if ! hash ${GIT_EXE} 2>/dev/null; then
+ echo "Command '${GIT_EXE}' not found." 1>&2
+ exit 1
+fi
+
+# Check if there is a valid git repo here
+HASH=$(${GIT_EXE} rev-parse HEAD)
+ERR=$?
+if [[ ${ERR} -ne 0 ]]; then
+ echo "Not a valid repository." 1>&2
+ exit ${ERR}
+elif [[ -z ${HASH} ]]; then
+ echo "Not a valid repository." 1>&2
+ exit 1
+fi
+
+# Retrieve info
+URL=$(${GIT_EXE} config remote.origin.url)
+TAG=$(${GIT_EXE} describe --abbrev=0)
+if [[ ${TAG} ]]; then
+ REV=$(${GIT_EXE} rev-list ${TAG}.. --count)
+else
+ TAG=$(${GIT_EXE} describe $(${GIT_EXE} rev-list --tags --max-count=1))
+ if [[ ${TAG} ]]; then
+ REV=$(${GIT_EXE} rev-list $(${GIT_EXE} merge-base 0.10.2 HEAD).. --count)
+ else
+ REV=$(${GIT_EXE} rev-list HEAD --count)
+ fi
+fi
+BRANCH=$(${GIT_EXE} symbolic-ref -q --short HEAD)
+REMOTE="${URL}"
+UPSTREAM=$(${GIT_EXE} config branch.${BRANCH}.remote)
+if [[ ${UPSTREAM} ]]; then
+ REMOTE="${UPSTREAM}"
+fi
+DATE=$(${GIT_EXE} log -1 --format="format:%ai")
+
+# Output
+# Only write tag and rev if they exist. A fresh clone currently has no tags.
+echo "URL=${URL}"
+echo "HASH=${HASH}"
+if [[ ${TAG} ]]; then echo "TAG=${TAG}"; fi
+if [[ ${REV} ]]; then echo "REV=${REV}"; fi
+echo "BRANCH=${BRANCH}"
+echo "REMOTE=${REMOTE}"
+echo "DATE=${DATE}"