Last active
June 1, 2016 12:12
-
-
Save mathematicalcoffee/0fe87020d73946892a0e237cd9b80ccc to your computer and use it in GitHub Desktop.
precommit hook for R package. Adds a 'GitCommit' to the DESCRIPTION field.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# This updates the GitCommit field of the DESCRIPTION file with the git commit | |
# sha (and branch). You should commit before building to make sure yours line up. | |
# Then going to that sha will give you that version of the package. | |
# | |
# It goes in ~/phd/.git/modules/rphd/hooks (or if not a submodule, in .git/hooks) | |
#echo $(pwd) ~/phd/rphd | |
BRANCH=$(git rev-parse --abbrev-ref --verify HEAD ) | |
SHA=$(git rev-parse --short --verify HEAD) | |
DESC=DESCRIPTION | |
# replace GitCommit with current git sha. | |
# so you can `git checkout SHA` and you will get that version of the package. | |
# (so if you want the newest version of the package, you commit THEN build). | |
sed -i -r -e 's/^GitCommit:.+$/GitCommit: '$BRANCH'-'$SHA'/' $DESC | |
git add $DESC | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment