pullapply: learn PPG_NOTLAZY to disable lazyness
[puppet-git.git] / ppg-pullapply
blob284ba146af2a62b3d019900cc77f98ccd554405a
1 #!/bin/bash
3 if [[ -n "${PPG_DEBUG}" ]]; then
4 set -x
5 fi
8 PPG_EXEC_PATH=$( dirname $(readlink -f "${BASH_SOURCE[0]}" ) )
9 GIT_EXEC_PATH=$(git --exec-path)
10 export GIT_SSH="${PPG_EXEC_PATH}/ppg-ssh"
12 . ${PPG_EXEC_PATH}/ppg-functions
14 pushd /etc/puppet >/dev/null || exit 1
15 GIT_DIR=$(git rev-parse --git-dir)
17 if [ -z "$GIT_DIR" ]; then
18 echo >&2 "Not in a git checkout"
19 exit 1
22 headname=$(git rev-parse --symbolic-full-name --revs-only HEAD)
24 if [[ "$headname" != "refs/heads/production" ]]; then
25 echo >&2 "WARNING: Not on production branch"
28 initial_sha1=$(git rev-parse --revs-only HEAD)
29 lastgood_sha1=$(git rev-parse --revs-only refs/heads/ppg/lastgood)
31 # resilient wrt server availability...
32 git fetch || echo "WARNING: error in git fetch"
34 if [[ "$headname" = "refs/heads/production" ]]; then
35 $PPG_EXEC_PATH/ppg-update-production || exit 1
36 else
37 if ! git pull --ff-only ; then
38 echo "ERROR: Failed to auto-merge with ff-only,"
39 echo " perhaps the current branch needs to"
40 echo " track a remote branch or you have dirty state."
41 echo " You can merge by hand and use ppg-apply"
45 uptodate_sha1=$(git rev-parse --revs-only HEAD)
47 echo "Executing command"
48 echo
49 echo " "ppg-apply "$@"
50 echo
51 echo "Log of changes to apply"
52 echo
53 if [ -n "$lastgood_sha1" ]; then
54 if [[ "$uptodate_sha1" != "$lastgood_sha1" ]]; then
55 git log --oneline ${lastgood_sha1}..${uptodate_sha1}
56 else
57 echo "No changes in git"
58 this_hour=$(date +%H)
59 unconditional_hour=$(( ( $(hostnametoint) % 18 ) + 5 ))
60 # incrond triggered runs use PPG_NOTLAZY
61 if [[ -z "${PPG_NOTLAZY}" ]]; then
62 # lazy 23 times a day
63 if [ ${this_hour} -ne ${unconditional_hour} ]; then
64 exec $PPG_EXEC_PATH/ppg-push-empty-report
68 else
69 git log --oneline ${uptodate_sha1}
71 echo
72 exec $PPG_EXEC_PATH/ppg-apply "$@"