Force a non-lazy run if global.ini has changed
[puppet-git.git] / ppg-commit
blob4071d3f8d7bb57f2c1f1f8dfbadcc1b5bb147c6d
1 #!/bin/bash
3 if [[ -n "${PPG_DEBUG}" ]]; then
4 set -x
5 fi
7 PPG_EXEC_PATH=$( dirname $(readlink -f "${BASH_SOURCE[0]}" ) )
8 GIT_EXEC_PATH=$(git --exec-path)
9 GIT_DIR=$(git rev-parse --git-dir)
11 if [ -z "$GIT_DIR" ]; then
12 echo >&2 "Not in a git checkout"
13 exit 1
16 ## we walk the options to extract any ppg-commit options
17 ## any other option is passed on to git-commit
18 immediate=
20 ## actually don't init the var, to avoid prepending
21 ## an empty string to the array
22 #gitcommitargs=
24 while test $# != 0
26 myvar=
27 case "$1" in
28 --immediate)
29 immediate=t
30 myvar=t
32 esac
33 if [ -z "$myvar" ]; then
34 # array push
35 gitcommitargs[${#gitcommitargs[@]}]="$1"
37 shift
38 done
40 # these may not exist
41 production_sha1=$(git rev-parse --revs-only refs/heads/production 2>/dev/null)
42 orig_production_sha1=$(git rev-parse --revs-only origin/production \
43 2>/dev/null )
45 if [ -n "$production_sha1" -a -n "$orig_production_sha1" ]; then
46 if [ "$production_sha1" != "$orig_production_sha1" ]; then
47 echo "Fast-forwarding local production head to match origin/production"
48 if ! git push . $orig_production_sha1:refs/heads/production ; then
49 echo >&2 "ERROR: production and origin/production have diverged!"
50 exit 1
55 if [ -n "$immediate" ]; then
56 # sanity-check we are on master
57 headname=$(git rev-parse --symbolic-full-name --revs-only HEAD)
58 if [ "$headname" != "refs/heads/master" ]; then
59 echo >&2 "ERROR: can only issue immediate commit on the master branch!"
60 exit 1
64 $PPG_EXEC_PATH/ppg-validate-staged-files || exit 1
66 export PPG_COMMIT=yes
67 git commit "${gitcommitargs[@]}" || exit 1
69 if [ -n "$immediate" ]; then
70 if [ -z "$production_sha1" ]; then
71 echo "Creating production branch"
72 git branch production master
73 production_sha1=$(git rev-parse --revs-only production)
74 else
75 if [[ $(git log --oneline production..HEAD|wc -l) -gt 1 ]]; then
76 echo
77 echo WARNING: More than one change will be scheduled for immediate
78 echo deployment. Please review the list of commits.
79 echo
80 git log --pretty=short --stat production..HEAD
81 echo
82 echo -n "Is this correct? [Ny] "
83 read correct
84 if [[ "${correct:0:1}" != 'Y' ]] && [[ "${correct:0:1}" != 'y' ]];
85 then
86 echo Cancelling immediate schedule.
87 exit 1
90 if ! git push . HEAD:refs/heads/production ; then
91 echo >&2 "ERROR: cannot fast-forward master to production"
92 echo >&2 " make sure the branches have not diverged"
93 exit 1
96 echo "Immediate commit successful -- remember to git push --all"
97 echo "to publish the changes on the gold server."
98 else
99 echo 'Checking for scheduled updates to the production branch...'
100 $PPG_EXEC_PATH/ppg-update-production