blob: 9154df97ca2009440c411a6767edd8bc8f9142d0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
#!/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/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
|