pullapply: simplify - exec ppg-apply
[puppet-git.git] / ppg-pullapply
blob1134688a9372187456f1527421b433deee4ecdd8
1 #!/bin/bash
3 PPG_EXEC_PATH=$( dirname $(realpath "${BASH_SOURCE[0]}" ) )
4 GIT_EXEC_PATH=$(git --exec-path)
5 GIT_DIR=$(git rev-parse --git-dir)
7 if [ -z "$GIT_DIR" ]; then
8 echo >&2 "Not in a git checkout"
9 exit 1
12 headname=$(git rev-parse --symbolic-full-name --revs-only HEAD)
14 if [[ "$headname" != "refs/heads/production" ]]; then
15 echo >&2 "WARNING: Not on production branch"
18 initial_sha1=$(git rev-parse --revs-only HEAD)
19 lastgood_sha1=$(git rev-parse --revs-only refs/heads/ppg/lastgood)
21 # resilient wrt server availability...
22 git fetch || echo "WARNING: error in git fetch"
24 if [[ "$headname" = "refs/heads/production" ]]; then
25 $PPG_EXEC_PATH/ppg-update-production || exit 1
26 else
27 if ! git merge --ff-only ; then
28 echo "ERROR: Failed to auto-merge with ff-only,"
29 echo " perhaps the current branch needs to"
30 echo " track a remote branch or you have dirty state."
31 echo " You can merge by hand and use ppg-apply"
35 uptodate_sha1=$(git rev-parse --revs-only HEAD)
37 if [[ "$uptodate_sha1" = "$lastgood_sha1" ]]; then
38 # nothing to do
39 exit 0
42 echo "Executing command"
43 echo
44 echo " "ppg-apply "$@"
45 echo
46 echo "Log of changes to apply"
47 echo
48 if [ -n "$lastgood_sha1" ]; then
49 git log --oneline ${lastgood_sha1}..${uptodate_sha1}
50 else
51 git log --oneline ${uptodate_sha1}
53 echo
54 exec $PPG_EXEC_PATH/ppg-apply "$@"