summaryrefslogtreecommitdiff
path: root/lib/gitolite3/hooks/common/post-receive
blob: 9c9aed7ec4511f26c08e6537a7b943d70888e050 (plain)
  1. #!/bin/sh
  2. # This gitolite3 hook exports content for web publishing.
  3. # The following gitolite3 environment variables affect its use:
  4. # WEB_BRANCH tree-ish (hook silently skipped if unset)
  5. # WEB_BASEDIR path writable by gitolite3 (default: /var/www/gitolite3)
  6. # WEB_EXEC_INIT command executed in exported dir after initial checkout
  7. # WEB_EXEC command executed in exported dir after every checkout
  8. set -eu
  9. WEB_BRANCH=${GL_OPTION_WEB_BRANCH:-}
  10. WEB_EXEC=${GL_OPTION_WEB_EXEC:-}
  11. WEB_EXEC_INIT=${GL_OPTION_WEB_EXEC_INIT:-}
  12. [ -n "$WEB_BRANCH" ] || exit 0
  13. # which git branch to check out
  14. WEB_BASEDIR=${GL_OPTION_WEB_BASEDIR:-/var/www/gitolite3}
  15. GIT_WORK_TREE="$WEB_BASEDIR/$GL_REPO"
  16. export GIT_WORK_TREE
  17. pwd
  18. echo "Checking out content to $GIT_WORK_TREE ..."
  19. init=1
  20. [ -e "$GIT_WORK_TREE" ] || init=
  21. git checkout -f "$WEB_BRANCH"
  22. chmod -R u=rw,go=r,a+X "$GIT_WORK_TREE"
  23. if [ -n "$WEB_EXEC_INIT" ] && [ -n "$init" ]; then
  24. ( cd "$WEB_BASEDIR" && echo "$WEB_EXEC_INIT" | sh - )
  25. fi
  26. if [ -n "$WEB_EXEC" ]; then
  27. ( cd "$WEB_BASEDIR" && echo "$WEB_EXEC" | sh - )
  28. fi
  29. echo "Checkout completed succesfully!"