summaryrefslogtreecommitdiff
path: root/lib/gitolite3/hooks/common/post-receive
blob: 49803c2c7a1b4d1d6b51f2922bbcc434db9ea963 (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. git -C "$GIT_WORK_TREE" config pull.ff only
  24. chmod -R u=rw,go=r,a+X "$GIT_WORK_TREE"
  25. if [ -n "$WEB_EXEC_INIT" ]; then
  26. ( cd "$GIT_WORK_TREE" && echo "$WEB_EXEC_INIT" | sh - )
  27. fi
  28. fi
  29. if [ -n "$WEB_EXEC" ]; then
  30. ( cd "$GIT_WORK_TREE" && echo "$WEB_EXEC" | sh - )
  31. fi
  32. echo "Checkout completed succesfully!"