/tools/pre-commit

http://github.com/jwiegley/ledger · #! · 69 lines · 58 code · 11 blank · 0 comment · 0 complexity · 5eb9ef27fa06a9f9916f357bc012c696 MD5 · raw file

  1. #!/bin/bash
  2. # Exit with status 1 if any command below fails
  3. set -e
  4. # Exit if it's not a branch we're interested in being thorough about
  5. if echo $(git rev-parse --symbolic-full-name HEAD) | \
  6. egrep -q '^refs/heads/(t/)'; then
  7. exit 0
  8. fi
  9. # These are the locations I keep my temporary source and build trees in
  10. PRODUCTS=$(./acprep products) # generates a build directory name such as
  11. # ~/Products/ledger
  12. if echo $PRODUCTS | grep -qv ledger; then
  13. PRODUCTS=$PRODUCTS/ledger
  14. fi
  15. TMPDIR=$PRODUCTS/pre-commit
  16. MIRROR=$PRODUCTS/pre-commit-mirror
  17. # Checkout a copy of the current index into MIRROR
  18. git checkout-index --prefix=$MIRROR/ -af
  19. # Remove files from MIRROR which are no longer present in the index
  20. git diff-index --cached --name-only --diff-filter=D -z HEAD | \
  21. (cd $MIRROR && xargs -0 rm -f --)
  22. # Copy only _changed files_ from MIRROR to TMPDIR, without copying
  23. # timestamps. This includes copying over new files, and deleting
  24. # removed ones. This way, "make check" will only rebuild what is
  25. # necessary to validate the commit.
  26. rsync -rlpgoDOc --delete --exclude-from=tools/excludes $MIRROR/ $TMPDIR/
  27. # Everything else happens in the temporary build tree
  28. if [ ! -f $TMPDIR/lib/utfcpp/source/utf8.h ]; then
  29. rsync -a --delete lib/utfcpp/ $TMPDIR/lib/utfcpp/
  30. fi
  31. cd $TMPDIR
  32. # Make sure there is a current Makefile. Regeneration of Makefile
  33. # happens automatically, but if myacprep or acprep changes, we want to
  34. # regenerate everything manually. If the user doesn't have acprep, look
  35. # for other common autoconf-related script files.
  36. if [ ! -f Makefile -o \
  37. Makefile.in -nt Makefile -o \
  38. configure -nt Makefile -o \
  39. tools/Makefile.am -nt Makefile.in -o \
  40. tools/configure.ac -nt configure -o \
  41. \( -f acprep -a acprep -nt Makefile \) ]
  42. then
  43. if [ -f acprep ]; then
  44. echo Will run acprep in a moment
  45. elif [ -f autogen.sh ]; then
  46. sh autogen.sh && ./configure
  47. else
  48. autoreconf && ./configure
  49. fi
  50. fi
  51. # Finally, (re)build this proposed source tree and see if it passes
  52. # muster.
  53. if [ -f acprep ]; then
  54. nice -n 20 ./acprep default --warn make check
  55. else
  56. nice -n 20 make check
  57. fi
  58. exit 0