Blame .private/pre-commit.sh

Packit Service b0a153
#!/bin/sh
Packit Service b0a153
#
Packit Service b0a153
# Sets the nano version according to the number of commits on this branch, as
Packit Service b0a153
# well as the branch offset.
Packit Service b0a153
#
Packit Service b0a153
# To have git run this script on commit, first make sure you change
Packit Service b0a153
# BRANCH_OFFSET to 60000 or higher, then create a "pre-commit" text file in
Packit Service b0a153
# .git/hooks/ with the following content:
Packit Service b0a153
# #!/bin/sh
Packit Service b0a153
# if [ -x .private/pre-commit.sh ]; then
Packit Service b0a153
#   source .private/pre-commit.sh
Packit Service b0a153
# fi
Packit Service b0a153
#
Packit Service b0a153
# NOTE: These versioning hooks are intended to be used *INTERNALLY* by the
Packit Service b0a153
# libusb development team and are NOT intended to solve versioning for any
Packit Service b0a153
# derivative branch, such as one you would create for private development.
Packit Service b0a153
#
Packit Service b0a153
# Should you wish to reuse these scripts for your own versioning, in your own
Packit Service b0a153
# private branch, we kindly ask you to first set BRANCH_OFFSET to 60000, or
Packit Service b0a153
# higher, as any offset below below 60000 is *RESERVED* for libusb official
Packit Service b0a153
# usage.
Packit Service b0a153
Packit Service b0a153
################################################################################
Packit Service b0a153
##  YOU *MUST* SET THE FOLLOWING TO 60000 OR HIGHER IF YOU REUSE THIS SCRIPT  ##
Packit Service b0a153
################################################################################
Packit Service b0a153
BRANCH_OFFSET=10000
Packit Service b0a153
################################################################################
Packit Service b0a153
Packit Service b0a153
if [ "$BASH_VERSION" = '' ]; then
Packit Service b0a153
  TYPE_CMD="type git >/dev/null 2>&1"
Packit Service b0a153
else
Packit Service b0a153
  TYPE_CMD="type -P git &>/dev/null"
Packit Service b0a153
fi
Packit Service b0a153
Packit Service b0a153
eval $TYPE_CMD || { echo "git command not found. Aborting." >&2; exit 1; }
Packit Service b0a153
Packit Service b0a153
NANO=`git log --oneline | wc -l`
Packit Service b0a153
NANO=`expr $NANO + $BRANCH_OFFSET`
Packit Service b0a153
# Amended commits need to have the nano corrected. Current versions of git hooks
Packit Service b0a153
# only allow detection of amending post commit, so we require a .amend file,
Packit Service b0a153
# which will be created post commit with a user warning if none exists when an
Packit Service b0a153
# amend is detected.
Packit Service b0a153
if [ -f .amend ]; then
Packit Service b0a153
  NANO=`expr $NANO - 1`
Packit Service b0a153
fi
Packit Service b0a153
echo "setting nano to $NANO"
Packit Service b0a153
echo "#define LIBUSB_NANO $NANO" > libusb/version_nano.h
Packit Service b0a153
git add libusb/version_nano.h