Pete Batard | b9e3a9b | 2012-04-11 23:12:21 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Sets the nano version according to the number of commits on this branch, as |
| 4 | # well as the branch offset. |
| 5 | # |
| 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 |
| 13 | # |
| 14 | # NOTE: These versioning hooks are intended to be used *INTERNALLY* by the |
hjelmn@cs.unm.edu | 1eff220 | 2014-01-08 23:50:34 +0000 | [diff] [blame] | 15 | # libusb development team and are NOT intended to solve versioning for any |
Pete Batard | b9e3a9b | 2012-04-11 23:12:21 +0100 | [diff] [blame] | 16 | # derivative branch, such as one you would create for private development. |
| 17 | # |
| 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 |
hjelmn@cs.unm.edu | 1eff220 | 2014-01-08 23:50:34 +0000 | [diff] [blame] | 20 | # higher, as any offset below below 60000 is *RESERVED* for libusb official |
Pete Batard | b9e3a9b | 2012-04-11 23:12:21 +0100 | [diff] [blame] | 21 | # usage. |
| 22 | |
| 23 | ################################################################################ |
| 24 | ## YOU *MUST* SET THE FOLLOWING TO 60000 OR HIGHER IF YOU REUSE THIS SCRIPT ## |
| 25 | ################################################################################ |
| 26 | BRANCH_OFFSET=10000 |
| 27 | ################################################################################ |
| 28 | |
Chris Dickens | 9fd7659 | 2020-04-16 17:10:39 -0700 | [diff] [blame] | 29 | if [ -n "$LIBUSB_SKIP_NANO" ]; then |
| 30 | exit 0 |
| 31 | fi |
| 32 | |
Chris Dickens | ba86d27 | 2017-12-26 15:46:13 -0800 | [diff] [blame] | 33 | if [ "$BASH_VERSION" = '' ]; then |
| 34 | TYPE_CMD="type git >/dev/null 2>&1" |
| 35 | else |
| 36 | TYPE_CMD="type -P git &>/dev/null" |
| 37 | fi |
| 38 | |
| 39 | eval $TYPE_CMD || { echo "git command not found. Aborting." >&2; exit 1; } |
Pete Batard | b9e3a9b | 2012-04-11 23:12:21 +0100 | [diff] [blame] | 40 | |
Pete Batard | b9e3a9b | 2012-04-11 23:12:21 +0100 | [diff] [blame] | 41 | NANO=`git log --oneline | wc -l` |
| 42 | NANO=`expr $NANO + $BRANCH_OFFSET` |
| 43 | # Amended commits need to have the nano corrected. Current versions of git hooks |
| 44 | # only allow detection of amending post commit, so we require a .amend file, |
| 45 | # which will be created post commit with a user warning if none exists when an |
| 46 | # amend is detected. |
| 47 | if [ -f .amend ]; then |
| 48 | NANO=`expr $NANO - 1` |
| 49 | fi |
| 50 | echo "setting nano to $NANO" |
Pete Batard | a221271 | 2012-05-10 15:56:51 +0100 | [diff] [blame] | 51 | echo "#define LIBUSB_NANO $NANO" > libusb/version_nano.h |
| 52 | git add libusb/version_nano.h |