Fix git commit-tree invokation for git v1.7.1
[puppet-git.git] / ppg-apply
blobf928ad25c397421b8fa3777c87dbd6e210c14403
1 #!/bin/bash
3 if [[ -n "${PPG_DEBUG}" ]]; then
4 set -x
5 fi
7 pushd /etc/puppet >/dev/null || exit 1
9 PPG_EXEC_PATH=$( dirname $(realpath "${BASH_SOURCE[0]}" ) )
10 GIT_EXEC_PATH=$(git --exec-path)
11 GIT_DIR=$(git rev-parse --git-dir)
13 if [ -z "$GIT_DIR" ]; then
14 echo >&2 "Not in a git checkout"
15 exit 1
18 ## FIXME?: check whether these are overriden
19 PUPPETCONF=/etc/puppet/puppet.conf
20 REPORT_PATH=/var/lib/puppet/state/last_run_report.yaml
22 # puppet.conf syntax is compat with git config syntax
23 # (both are INI style). How lucky can we be? :-)
24 report_bool=$(git config -f $PUPPETCONF --bool --get agent.report)
26 # note: default is true
27 if [ "$report_bool" = 'false' ]; then
28 echo >&2 "ERROR: reports are disabled!"
29 exit 1
31 puppet apply --detailed-exitcodes $@
32 pexit=$?
34 # From http://docs.puppetlabs.com/man/apply.html
35 # 0 means ?? (guess: no changes)
36 # 2 means there were changes
37 # 4 means failures
38 # 6 means changes & failures
39 if [[ $pexit -eq 00 ]] || [[ $pexit -eq 2 ]]; then
40 # mark as good
41 lastgood_sha1=$(git rev-parse --revs-only refs/heads/ppg/lastgood)
42 if [ -n "$lastgood_sha1" ]; then
43 git push . HEAD refs/heads/ppg/lastgood
44 else
45 # setup with reflog - may be handy
46 # for diagnosis
47 git branch -l refs/heads/ppg/lastgood HEAD
49 else
50 ## TODO: do we want to warn in any way?
54 # TODO: handle reports
55 hostname=$(/usr/bin/hostname -f)
56 worktree='/etc/puppet/.ppg/scratch-worktree'
57 mkdir -p ${worktree}/reports
59 export GIT_DIR=/etc/puppet/.ppg
60 pushd ${worktree} &>/dev/null
62 if ! git rev-parse --revs-only \
63 refs/heads/${hostname} &>/dev/null ; then
64 # it is going to be the first commit
65 # FIXME: any special handling?
68 cp ${REPORT_PATH} ${worktree}/reports/${hostname}.yaml
69 git update-index --add reports/${hostname}.yaml
70 git commit -m 'ppg apply report'
72 headname=$(git rev-parse --symbolic-full-name --revs-only HEAD)
73 if [[ "${headname}" != "refs/heads/${hostname}" ]]; then
74 # we are in thefirst run, auto-created 'master' branch
75 git branch ${hostname} HEAD
76 git checkout ${hostname}
77 git branch -D master
80 popd &>/dev/null
81 unset GIT_DIR
83 $PPG_EXEC_PATH/ppg-push-reports
85 popd &>/dev/null