summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Kuzminsky <seb@highlab.com>2011-09-21 14:39:10 -0600
committerSebastian Kuzminsky <seb@highlab.com>2011-09-21 15:32:26 -0600
commit528d4ef0496f0293dab9f12ba3de15844b09d968 (patch)
tree61914db2d5b099c617f138764430bede1b0a7d9a
parent3e89caec26f7a97ce86cb3fd0c90b2c95e44ad46 (diff)
downloadlinuxcnc-528d4ef0496f0293dab9f12ba3de15844b09d968.tar.gz
linuxcnc-528d4ef0496f0293dab9f12ba3de15844b09d968.zip
packaging: add some scripts for working with git
This commit does these things: * Add a small shell library called githelper.sh, which reads a bunch of info from git and makes it available as environment variables in the caller. * Add a script called version-is-release, which checks to see if the current version (HEAD) has a signed release tag pointing to it. * Update update-dch-from-git and get-version-from-git to use the new githelper library, for consistency.
-rwxr-xr-xdebian/update-dch-from-git16
-rwxr-xr-xscripts/get-version-from-git24
-rw-r--r--scripts/githelper.sh40
-rwxr-xr-xscripts/version-is-release38
4 files changed, 94 insertions, 24 deletions
diff --git a/debian/update-dch-from-git b/debian/update-dch-from-git
index 6644510e6..26ba5a108 100755
--- a/debian/update-dch-from-git
+++ b/debian/update-dch-from-git
@@ -5,16 +5,12 @@ if [ ! -d debian -o ! -d src ]; then
exit 1
fi
-if [ -z "$1" ]; then
- GIT_BRANCH=$(git branch | egrep '^\*' | cut -d ' ' -f 2)
- if [ "$GIT_BRANCH" = "(no" ]; then
- echo "'git branch' says we're not on a branch, pass one in as an argument"
- exit 1
- fi
-else
- GIT_BRANCH="$1"
-fi
+source scripts/githelper.sh
+githelper $1
+if [ -z "$GIT_TAG" ]; then
+ exit 1
+fi
GIT_VERSION=$(scripts/get-version-from-git $GIT_BRANCH)
if [ $? -ne 0 ]; then
@@ -22,8 +18,6 @@ if [ $? -ne 0 ]; then
exit 1
fi
-GIT_TAG=`echo $GIT_VERSION | sed -r 's/^(.*)-[^-]+-[^-]+$/\1/'`
-
DEB_VERSION=`git show HEAD:debian/changelog | head -1 | sed 's/.*(\(.*\)).*/\1/'`
NEW_DEB_VERSION="${GIT_VERSION/-pre/~pre}"
diff --git a/scripts/get-version-from-git b/scripts/get-version-from-git
index 007ee0c98..56610af6b 100755
--- a/scripts/get-version-from-git
+++ b/scripts/get-version-from-git
@@ -1,21 +1,19 @@
#!/bin/bash
-if [ -z "$1" ]; then
- GIT_BRANCH=$(git branch | egrep '^\*' | cut -d ' ' -f 2)
- if [ "$GIT_BRANCH" = "(no" ]; then
- echo "'git branch' says we're not on a branch, pass one in as an argument"
+if [ ! -z "$EMC2_HOME" ]; then
+ source $EMC2_HOME/scripts/githelper.sh
+else
+ if [ ! -d debian -o ! -d src ]; then
+ echo "this script must be run from the root of the source tree (the directory with debian and src in it)"
exit 1
fi
-else
- GIT_BRANCH="$1"
+ source scripts/githelper.sh
fi
-case $GIT_BRANCH in
- master) TAG_GLOB="v2.6*";;
- v2.5_branch) TAG_GLOB="v2.5*";;
- v2.4_branch) TAG_GLOB="v2.4*";;
- *) TAG_GLOB="*";;
-esac
+githelper $1
+if [ -z "$GIT_TAG" ]; then
+ exit 1
+fi
-git describe --match "$TAG_GLOB"
+git describe --match "$GIT_TAG"
diff --git a/scripts/githelper.sh b/scripts/githelper.sh
new file mode 100644
index 000000000..8d4bb4c52
--- /dev/null
+++ b/scripts/githelper.sh
@@ -0,0 +1,40 @@
+
+#
+# This is a bash shell fragment, intended to be sourced by scripts that
+# want to work with git in the emc2 repo.
+#
+# Sets GIT_BRANCH to the passed in branch name; if none is passed in it
+# attempts to detect the current branch (this will fail if the repo is in a
+# detached HEAD state).
+#
+# Sets GIT_TAG to the most recent signed tag (this will remain unset if no
+# signed tag is found).
+#
+
+
+function githelper() {
+ if [ -z "$1" ]; then
+ GIT_BRANCH=$(git branch | egrep '^\*' | cut -d ' ' -f 2)
+ if [ "$GIT_BRANCH" = "(no" ]; then
+ echo "'git branch' says we're not on a branch, pass one in as an argument"
+ return
+ fi
+ else
+ GIT_BRANCH="$1"
+ fi
+
+ case $GIT_BRANCH in
+ master) GIT_TAG_GLOB="v2.6*";;
+ v2.5_branch) GIT_TAG_GLOB="v2.5*";;
+ v2.4_branch) GIT_TAG_GLOB="v2.4*";;
+ *) GIT_TAG_GLOB="*";;
+ esac
+
+ for TAG in $(git tag -l "$GIT_TAG_GLOB" | sort -r); do
+ if git tag -v "$TAG" > /dev/null 2> /dev/null; then
+ GIT_TAG="$TAG"
+ break
+ fi
+ done
+}
+
diff --git a/scripts/version-is-release b/scripts/version-is-release
new file mode 100755
index 000000000..febbcd3a4
--- /dev/null
+++ b/scripts/version-is-release
@@ -0,0 +1,38 @@
+#!/bin/bash
+#
+# This script checks if the current version (HEAD) is an official release.
+# If so, the program returns with an exit code of 0 (True). If it is not a
+# release, the program returns an exit code other than 0 (False).
+#
+# HEAD is an official release if there exists a tag that points to it and
+# that is signed by the release manager's key.
+#
+
+if [ ! -z "$EMC2_HOME" ]; then
+ source $EMC2_HOME/scripts/githelper.sh
+else
+ if [ ! -d debian -o ! -d src ]; then
+ echo "this script must be run from the root of the source tree (the directory with debian and src in it)"
+ exit 1
+ fi
+ source scripts/githelper.sh
+fi
+
+githelper $1
+if [ -z "$GIT_TAG" ]; then
+ # no signed tags found
+ echo "no"
+ exit 1
+fi
+
+TAGGED_REV=$(git rev-parse $GIT_TAG^{commit})
+HEAD_REV=$(git rev-parse HEAD)
+
+if [ "$TAGGED_REV" == "$HEAD_REV" ]; then
+ echo "yes"
+ exit 0
+fi
+
+echo "no"
+exit 1
+