summaryrefslogtreecommitdiff
path: root/.private
diff options
context:
space:
mode:
authorPete Batard <pete@akeo.ie>2012-04-11 23:12:21 +0100
committerPete Batard <pete@akeo.ie>2012-04-11 23:45:37 +0100
commitb9e3a9b74cb78302b19652b44114f2e491dd24f2 (patch)
treeee463def302506d7361ec853f0d97b7815c533bc /.private
parentff19395ca935d5c1bd658e4b3e5b5a9240c074a9 (diff)
downloadlibusb-b9e3a9b74cb78302b19652b44114f2e491dd24f2.tar.gz
Git: add pre-commit and post-rewrite hooks for versioning
* Also adds the maintainer-only .private directory
Diffstat (limited to '.private')
-rw-r--r--.private/README.txt5
-rwxr-xr-x.private/post-rewrite.sh28
-rwxr-xr-x.private/pre-commit.sh50
3 files changed, 83 insertions, 0 deletions
diff --git a/.private/README.txt b/.private/README.txt
new file mode 100644
index 0000000..579f25a
--- /dev/null
+++ b/.private/README.txt
@@ -0,0 +1,5 @@
+This directory contains private internal scripts used by the libusbx
+project project maintainers.
+
+These scripts are not intended for general usage and will not be
+exported when producing release archives. \ No newline at end of file
diff --git a/.private/post-rewrite.sh b/.private/post-rewrite.sh
new file mode 100755
index 0000000..b5fff07
--- /dev/null
+++ b/.private/post-rewrite.sh
@@ -0,0 +1,28 @@
+#!/bin/sh
+#
+# Detect amended commits and warn user if .amend is missing
+#
+# To have git run this script on commit, create a "post-rewrite" text file in
+# .git/hooks/ with the following content:
+# #!/bin/sh
+# if [ -x .private/post-rewrite.sh ]; then
+# source .private/post-rewrite.sh
+# fi
+#
+# NOTE: These versioning hooks are intended to be used *INTERNALLY* by the
+# libusbx development team and are NOT intended to solve versioning for any
+# derivative branch, such as one you would create for private development.
+#
+
+case "$1" in
+ amend)
+ # Check if a .amend exists. If none, create one and warn user to re-commit.
+ if [ -f .amend ]; then
+ rm .amend
+ else
+ echo "Amend commit detected, but no .amend file - One has now been created."
+ echo "Please re-commit as is (amend), so that the version number is correct."
+ touch .amend
+ fi ;;
+ *) ;;
+esac
diff --git a/.private/pre-commit.sh b/.private/pre-commit.sh
new file mode 100755
index 0000000..c62fb35
--- /dev/null
+++ b/.private/pre-commit.sh
@@ -0,0 +1,50 @@
+#!/bin/sh
+#
+# Sets the nano version according to the number of commits on this branch, as
+# well as the branch offset.
+#
+# To have git run this script on commit, first make sure you change
+# BRANCH_OFFSET to 60000 or higher, then create a "pre-commit" text file in
+# .git/hooks/ with the following content:
+# #!/bin/sh
+# if [ -x .private/pre-commit.sh ]; then
+# source .private/pre-commit.sh
+# fi
+#
+# NOTE: These versioning hooks are intended to be used *INTERNALLY* by the
+# libusbx development team and are NOT intended to solve versioning for any
+# derivative branch, such as one you would create for private development.
+#
+# Should you wish to reuse these scripts for your own versioning, in your own
+# private branch, we kindly ask you to first set BRANCH_OFFSET to 60000, or
+# higher, as any offset below below 60000 is *RESERVED* for libusbx official
+# usage.
+
+################################################################################
+## YOU *MUST* SET THE FOLLOWING TO 60000 OR HIGHER IF YOU REUSE THIS SCRIPT ##
+################################################################################
+BRANCH_OFFSET=10000
+################################################################################
+
+type -P sed &>/dev/null || { echo "sed command not found. Aborting." >&2; exit 1; }
+type -P git &>/dev/null || { echo "git command not found. Aborting." >&2; exit 1; }
+
+# The -b option of sed, which we use to prevent CRLF conversions on Windows
+# was only introduced recently, and Linux distros may not have it
+SED_CMD='sed -b'
+$SED_CMD --version > /dev/null 2>&1 || SED_CMD='sed'
+
+NANO=`git log --oneline | wc -l`
+NANO=`expr $NANO + $BRANCH_OFFSET`
+# Amended commits need to have the nano corrected. Current versions of git hooks
+# only allow detection of amending post commit, so we require a .amend file,
+# which will be created post commit with a user warning if none exists when an
+# amend is detected.
+if [ -f .amend ]; then
+ NANO=`expr $NANO - 1`
+fi
+echo "setting nano to $NANO"
+# -i option of sed is useless on Windows.
+$SED_CMD -e "s/^#define LIBUSB_NANO.*/#define LIBUSB_NANO $NANO/" libusb/version.h > libusb/version.h~
+mv libusb/version.h~ libusb/version.h
+git add libusb/version.h