#!/bin/sh
# Example bare-repo post-receive hook to update a checked-out deploy directory
# Adjust DEPLOY_DIR and paths as necessary. Ensure this hook is executable.

DEPLOY_DIR=/srv/caddy-config

echo "Updating working tree at ${DEPLOY_DIR}"
GIT_WORK_TREE=${DEPLOY_DIR} git checkout -f

# Run validation + reload script from the deploy dir (if present)
if [ -x "${DEPLOY_DIR}/deploy/validate-and-reload.sh" ]; then
    echo "Running validation and reload"
    "${DEPLOY_DIR}/deploy/validate-and-reload.sh"
else
    echo "No validate-and-reload.sh found or not executable in ${DEPLOY_DIR}/deploy" >&2
    exit 1
fi
