#!/bin/bash # this post-receive hook runs globally on my local git machine # if the public.conf file exists it reads it to get the remote repo and mirror pushes # if the file doesn't exist, it doesn't mirror the repo AKA it's private and it stays on my network # # USAGE: # 1) set core.hooksPath to point to where this file is located # ex `sudo git config --system core.hooksPath /home/git/scripts/git-hooks` # 2) create a public.conf file in the repo of your choice with the path to your remote # 3) push as normal and everything should mirror REPO_PATH=$(pwd) PUBLIC_FILE="$REPO_PATH/public.conf" LOGFILE="/home/git/public-sync.log" # log our syncing isssues if [ -f "$PUBLIC_FILE" ]; then REPO_URL=$(cat "$PUBLIC_FILE" | tr -d '\n' | xargs) if [ -z "$REPO_URL" ]; then echo "[$(date)] $REPO_PATH: misconfigured public.conf, skipping" >> "$LOGFILE" else OUTPUT=$(git push --mirror "$REPO_URL" 2>&1) if [ $? -ne 0 ]; then echo "[$(date)] MIRROR FAILED $REPO_PATH -> $REPO_URL" >> "$LOGFILE" echo "$OUTPUT" >> "$LOGFILE" fi fi fi # run repo specific post-recieve hook if it existst REPO_HOOK="$(git rev-parse --git-dir)/hooks/post-receive" if [ -x "$REPO_HOOK" ]; then "$REPO_HOOK" "$@" fi # vim: filetype=bash