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"
12 production_sha1
=$
(git rev-parse
--revs-only refs
/heads
/production
2>/dev
/null
)
13 if [ -z "$production_sha1" ]; then
14 # no production branch, nothing to do
18 nowepoch
=$
(date --utc +%s
)
19 for tag
in $
(git tag
-l |
grep '^ppg-sched-' |
sort -r); do
20 # Sneaky sed: 's/-/ /3g' replaces the 3rd dash only
21 datestamp
=$
(echo "$tag"|
sed 's/^ppg-sched-//;s/-/ /3g;s/\./:/g;')
22 tagepoch
=$
(date -d "$datestamp" +%s
)
23 if [[ $tagepoch -lt $nowepoch ]]; then
28 if [ -z "$targettag" ]; then
29 # no relevant tags, nothing to do...'
33 target_sha1
=$
(git rev-parse
--revs-only ${targettag}^
{commit
} ) ||
exit 1
35 # perhaps origin/production is ahead of scheduled tags,
37 orig_production_sha1
=$
(git rev-parse
--revs-only refs
/heads
/origin
/master
)
38 if [ -n "$orig_production_sha1" ]; then
39 if $PPG_EXEC_PATH/ppg-is-ancestor
$targettag $orig_production_sha1 ; then
40 target_sha1
=$orig_production_sha1
44 if [ "$production_sha1" = "$target_sha1" ]; then
50 if $PPG_EXEC_PATH/ppg-is-ancestor
$targettag $production_sha1 ; then
55 if ! $PPG_EXEC_PATH/ppg-is-ancestor
$production_sha1 $target_sha1 ; then
56 echo "ERROR: production branch and $targettag have diverged!"
60 headname
=$
(git rev-parse
--symbolic-full-name --revs-only HEAD
)
62 if [ "$headname" = 'refs/heads/production' ]; then
63 # sanity checks when on production
64 if [ $
(git
diff --name-status HEAD |
wc -l) -gt 0 ]; then
65 echo >&2 'ERROR: Currently on "production" branch and with dirty state.'
66 echo >&2 " Refusing to update with scheduled changes."
71 echo "About to update production with scheduled changes:"
72 git log
--oneline refs
/heads
/production..
$target_sha1
75 if [ "$headname" = 'refs/heads/production' ]; then
76 echo "Updating current production checkout"
77 git merge
--ff-only $target_sha1
80 git push .
$target_sha1:refs
/heads
/production