From 098533cb0b2bbea0e55ead77f7bc1b8c668965c0 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 10 Mar 2015 15:47:55 +1100 Subject: [PATCH] re-exec self if we are out of date --- launcher | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/launcher b/launcher index a573f5d..cce035d 100755 --- a/launcher +++ b/launcher @@ -557,8 +557,32 @@ case "$command" in rebuild) if [ "$(git symbolic-ref --short HEAD)" == "master" ]; then - echo "Updating discourse docker" - git pull || (echo 'failed to update' && exit 1) + echo "Ensuring discourse docker is up to date" + + git remote update + + LOCAL=$(git rev-parse @) + REMOTE=$(git rev-parse @{u}) + BASE=$(git merge-base @ @{u}) + + if [ $LOCAL = $REMOTE ]; then + echo "Discourse Docker is up-to-date" + + elif [ $LOCAL = $BASE ]; then + echo "Updating Discourse Docker" + git pull || (echo 'failed to update' && exit 1) + exec /bin/bash $0 $@ + + elif [ $REMOTE = $BASE ]; then + echo "Your version of Discourse Docker is ahead of origin" + + else + echo "Discourse Docker has diverged source" + + fi + + exit + fi if [ -e $cidfile ] then -- 2.25.1