Linux: Search for /dev/usbdev<bus>.<device> USB device special files
[libusbx.git] / .private / pre-commit.sh
blobc62fb35c9d64c12b7d66c8f8ab348ebe2e002d09
1 #!/bin/sh
3 # Sets the nano version according to the number of commits on this branch, as
4 # well as the branch offset.
6 # To have git run this script on commit, first make sure you change
7 # BRANCH_OFFSET to 60000 or higher, then create a "pre-commit" text file in
8 # .git/hooks/ with the following content:
9 # #!/bin/sh
10 # if [ -x .private/pre-commit.sh ]; then
11 # source .private/pre-commit.sh
12 # fi
14 # NOTE: These versioning hooks are intended to be used *INTERNALLY* by the
15 # libusbx development team and are NOT intended to solve versioning for any
16 # derivative branch, such as one you would create for private development.
18 # Should you wish to reuse these scripts for your own versioning, in your own
19 # private branch, we kindly ask you to first set BRANCH_OFFSET to 60000, or
20 # higher, as any offset below below 60000 is *RESERVED* for libusbx official
21 # usage.
23 ################################################################################
24 ## YOU *MUST* SET THE FOLLOWING TO 60000 OR HIGHER IF YOU REUSE THIS SCRIPT ##
25 ################################################################################
26 BRANCH_OFFSET=10000
27 ################################################################################
29 type -P sed &>/dev/null || { echo "sed command not found. Aborting." >&2; exit 1; }
30 type -P git &>/dev/null || { echo "git command not found. Aborting." >&2; exit 1; }
32 # The -b option of sed, which we use to prevent CRLF conversions on Windows
33 # was only introduced recently, and Linux distros may not have it
34 SED_CMD='sed -b'
35 $SED_CMD --version > /dev/null 2>&1 || SED_CMD='sed'
37 NANO=`git log --oneline | wc -l`
38 NANO=`expr $NANO + $BRANCH_OFFSET`
39 # Amended commits need to have the nano corrected. Current versions of git hooks
40 # only allow detection of amending post commit, so we require a .amend file,
41 # which will be created post commit with a user warning if none exists when an
42 # amend is detected.
43 if [ -f .amend ]; then
44 NANO=`expr $NANO - 1`
46 echo "setting nano to $NANO"
47 # -i option of sed is useless on Windows.
48 $SED_CMD -e "s/^#define LIBUSB_NANO.*/#define LIBUSB_NANO $NANO/" libusb/version.h > libusb/version.h~
49 mv libusb/version.h~ libusb/version.h
50 git add libusb/version.h