Skip to content

Instantly share code, notes, and snippets.

@mathematicalcoffee
Last active June 1, 2016 12:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mathematicalcoffee/0fe87020d73946892a0e237cd9b80ccc to your computer and use it in GitHub Desktop.
Save mathematicalcoffee/0fe87020d73946892a0e237cd9b80ccc to your computer and use it in GitHub Desktop.
precommit hook for R package. Adds a 'GitCommit' to the DESCRIPTION field.
#!/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