re-exec self if we are out of date
authorSam <sam.saffron@gmail.com>
Tue, 10 Mar 2015 04:47:55 +0000 (15:47 +1100)
committerSam <sam.saffron@gmail.com>
Tue, 10 Mar 2015 04:47:55 +0000 (15:47 +1100)
launcher

index a573f5d19dddccf9a4b134faaf3df5599e524fb5..cce035d8b6ec8a9c42cd3324d446ab9942e34707 100755 (executable)
--- 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