aboutsummaryrefslogtreecommitdiff
path: root/git-hooks/post-receive
blob: 6445e0b8ed1c6c35cdaf7f3a45473fd47c719545 (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
#!/bin/bash

# this post-receive hook runs globally on my local git machine
# if the knot.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 knot.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)
KNOT_FILE="$REPO_PATH/knot.conf"
LOGFILE="/home/git/knot-sync.log"  #log our syncing isssues

if [ ! -f "$KNOT_FILE" ]; then
  echo "[$(date)] $REPO_PATH: knot.conf not found, skipping" >> "$LOGFILE"
  exit 0
fi
REPO_URL=$(cat "$KNOT_FILE" | tr -d '\n' | xargs)
if [ -z "$REPO_URL" ]; then
  echo "[$(date)] $REPO_PATH: misconfigured knot.conf, skipping" >> "$LOGFILE"
  exit 0
fi

echo "[$(date)] BEGIN PUSH $REPO_PATH" >> "$LOGFILE"
git push --mirror "$REPO_URL" >> "$LOGFILE" 2>&1
echo "[$(date)] END PUSH $REPO_PATH" >> "$LOGFILE"

# vim: filetype=sh