pullapply: unconditional hour now between 6am and midnight
[puppet-git.git] / ppg-push-reports
blob7c3c5ba96aa4dce20be50b04b176d219cfb753ea
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 $(readlink -f "${BASH_SOURCE[0]}" ) )
10 GIT_EXEC_PATH=$(git --exec-path)
11 GIT_DIR=$(git rev-parse --git-dir)
12 GIT_SSH="${PPG_EXEC_PATH}/ppg-ssh"
14 . ${PPG_EXEC_PATH}/ppg-functions
16 ### FIXME PROXYSERVER
17 if [ -z "$GIT_DIR" ]; then
18 echo >&2 "Not in a git checkout"
19 exit 1
22 hostname=$(xhostname)
24 ## all ops on .ppg
26 ## FIXME PROXY SERVER
27 export GIT_DIR=/etc/puppet/.ppg
28 git push origin \
29 refs/heads/${hostname}:refs/heads/${hostname} || exit $?
31 # reports are tiny, we can spool a month of them safely
32 # if you want it shorter, configure it so :-)
33 expiry="one.month.ago"
34 config_expiry=$(git config --get ppg.reportexpiry)
35 if [ -n "$config_expiry" ]; then
36 expiry="$config_expiry"
39 for head in $(git branch|sed 's/^..//'); do
40 graft_sha1=$(git log --until="$expiry" -n1 --pretty=format:%H ${head})
41 if [[ -z "$graft_sha1" ]]; then
42 # nothing to prune
43 continue
45 # is it already grafted?
46 if grep -q "^${graft_sha1} " "${GIT_DIR}/info/grafts" &>/dev/null ; then
47 # don't duplicate the graft
48 continue
50 some_grafted='true'
51 # prep empty commit
52 # skip git read-tree --empty, we get the same with
53 export GIT_INDEX_FILE=/tmp/ppg-emptytree.$$
54 empty_tree="$(git write-tree)"
55 rm ${GIT_INDEX_FILE}
56 unset GIT_INDEX_FILE
57 empty_commit=$(echo empty | git commit-tree ${empty_tree})
58 echo "${graft_sha1} ${empty_commit}" >> ${GIT_DIR}/info/grafts
59 done
61 if [[ -z "$some_grafted" ]]; then
62 # nothing to do
63 exit 0
66 # ppg-repack makes the unreachable objects "loose"
67 # git prune --expire actually deletes them
68 $PPG_EXEC_PATH/ppg-repack -AFfd
69 git prune --expire=now
71 ### Cleanup stale grafts
72 # current grafts points are reachable,
73 # pruned graft points (made obsolete by a newer graft)
74 # cannot be retrieved and git cat-file exit code is 128
75 touch ${GIT_DIR}/info/grafts.tmp.$$
76 while read line; do
77 graftpoint=$(echo "${line}" | cut -d' ' -f1)
78 if git cat-file commit ${graftpoint} &>/dev/null ; then
79 echo ${line} >> ${GIT_DIR}/info/grafts.tmp.$$
81 done < "${GIT_DIR}/info/grafts"
83 if [ -s ${GIT_DIR}/info/grafts.tmp.$$ ]; then
84 mv ${GIT_DIR}/info/grafts.tmp.$$ ${GIT_DIR}/info/grafts