summaryrefslogtreecommitdiff
path: root/lib/gitolite3/hooks/common/post-receive
blob: a5f9ab680bbd1244a85149f1ded8412d017a2b16 (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. WEB_BASEDIR=${GL_OPTION_WEB_BASEDIR:-/var/www/gitolite3}
  14. GIT_WORK_TREE="$WEB_BASEDIR/$GL_REPO"
  15. if [ -e "$GIT_WORK_TREE" ]; then
  16. echo "Refreshing content in $GIT_WORK_TREE ..."
  17. git -C "$GIT_WORK_TREE" checkout -f "$WEB_BRANCH"
  18. chmod -R u=rw,go=r,a+X "$GIT_WORK_TREE"
  19. else
  20. echo "Checking out content to $GIT_WORK_TREE ..."
  21. git -C "$WEB_BASEDIR" clone --quiet --branch "$WEB_BRANCH" "$PWD"
  22. chmod -R u=rw,go=r,a+X "$GIT_WORK_TREE"
  23. if [ -n "$WEB_EXEC_INIT" ]; then
  24. ( cd "$GIT_WORK_TREE" && echo "$WEB_EXEC_INIT" | sh - )
  25. fi
  26. fi
  27. if [ -n "$WEB_EXEC" ]; then
  28. ( cd "$GIT_WORK_TREE" && echo "$WEB_EXEC" | sh - )
  29. fi
  30. echo "Checkout completed succesfully!"