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