post-commit 1.6 KB

123456789101112131415161718192021222324252627282930313233
  1. #!/bin/sh
  2. # Bring the records of tests-covering up to the commit just made.
  3. #
  4. # git-hooks/pre-commit chooses tests by reading a diff against these records,
  5. # and a diff describes the files as they were before the change. So after each
  6. # commit the records must describe that commit, or the next choice falls back
  7. # to every test that loaded a changed file, and grows coarser with each commit.
  8. #
  9. # In the background, because it runs each stale test under Devel::Cover, and a
  10. # full refresh takes much longer than a commit should. Run it by hand to catch
  11. # up. It runs the tests the way the pre-commit hook does, with lib/ on the
  12. # path and nothing else set, so that the records describe the same runs.
  13. #
  14. # Install it: cp git-hooks/pre-commit git-hooks/post-commit .git/hooks/
  15. command -v tests-covering >/dev/null 2>&1 || exit 0
  16. # Not while a rebase, or a cherry-pick or revert of several commits, applies
  17. # them. git runs this hook for each commit that it applies, and each refresh
  18. # runs every stale test under Devel::Cover. A refresh brings the records up to
  19. # the working tree, however many commits it missed, so the next commit after
  20. # the rebase catches them up.
  21. for state in rebase-merge rebase-apply sequencer; do
  22. [ -d "$(git rev-parse --git-path "$state")" ] && exit 0
  23. done
  24. # Without the GIT_ variables that git sets for this hook, for the reason the
  25. # pre-commit hook gives: the refresh runs the tests, and a test that runs git
  26. # in a repository of its own would otherwise work in this one.
  27. unset $(env | sed -n 's/^\(GIT_[A-Za-z0-9_]*\)=.*/\1/p')
  28. tests-covering --refresh --jobs "$(nproc 2>/dev/null || echo 1)" >/dev/null 2>&1 &