summaryrefslogtreecommitdiff
path: root/lib/gitolite3/hooks/common/post-receive
blob: 97312800501f992555956f1444a9d76917abe9fa (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. if [ -e "$GIT_WORK_TREE" ]; then
  20. git checkout -f "$WEB_BRANCH"
  21. chmod -R u=rw,go=r,a+X "$GIT_WORK_TREE"
  22. else
  23. git clone --quiet --branch "$WEB_BRANCH" .
  24. chmod -R u=rw,go=r,a+X "$GIT_WORK_TREE"
  25. if [ -n "$WEB_EXEC_INIT" ]; then
  26. ( cd "$WEB_BASEDIR" && echo "$WEB_EXEC_INIT" | sh - )
  27. fi
  28. fi
  29. if [ -n "$WEB_EXEC" ]; then
  30. ( cd "$WEB_BASEDIR" && echo "$WEB_EXEC" | sh - )
  31. fi
  32. echo "Checkout completed succesfully!"