#!/bin/sh -e # git-cron-digest URL [BRANCH] - generate a digest of new commits since last run # # Example usage (daily fetch at 13:00): # 0 13 * * * : foo/bar ; git-cron-digest https://github.com/foo/bar DATE=$(date "+%Y-%m-%d %H:%M:%S") : ${GIT_CRON_DIGEST_DIR:=/var/tmp/git-cron-digest} repo=$1 branch=$2 repohash=$(printf '%s\0' "$repo" "$branch" | git hash-object --stdin) mkdir -p "$GIT_CRON_DIGEST_DIR" if ! [ -d "$GIT_CRON_DIGEST_DIR/$repohash" ]; then cd "$GIT_CRON_DIGEST_DIR" git clone --mirror "$repo" ${2:+--branch=$branch} "$repohash" git -C "$repohash" config --add core.logAllRefUpdates true git -C "$repohash" update-ref -m "digest: initial clone" HEAD HEAD fi cd "$GIT_CRON_DIGEST_DIR/$repohash" git update-ref -m "digest: pre-$DATE" HEAD HEAD git fetch -q if git log -1 --pretty=%h HEAD@{1}.. | grep -q .; then echo "New commits since $(git show -s --date=short-local --pretty=%cd HEAD@{1}):" echo git log --reverse --date=format-local:"%Y-%m-%d %H:%M" \ --pretty="%cd %h %aE: %s" HEAD@{1}.. echo git diff --shortstat --dirstat=cumulative,5 HEAD@{1}.. printf '\n-- \ngit-cron-digest 0.1\n' fi