more reliable; hopefully it would not merge generic and senslab anymore
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Fri, 14 Oct 2011 16:29:11 +0000 (18:29 +0200)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Fri, 14 Oct 2011 16:29:11 +0000 (18:29 +0200)
scripts/flab-sync.sh

index ad25021..c132ec9 100755 (executable)
@@ -17,10 +17,30 @@ AGAINST=master
 
 GIT_OPTIONS=""
 
+function msg () {
+    echo "====================" "$@"
+}
+
+
+function failure () {
+    echo Emergency exit -- Bailing out
+    exit 1
+}
+
+function check_or_create_workdir () {
+    [ -d $WORKDIR ] && return
+    msg Restarting with a brand new workdir $WORKDIR
+    git clone $FLABREPO $WORKDIR 
+}
+
 function merge_master_in_local_branches () {
     # start with pulling the upstream master onto flab
     cd $WORKDIR
+    # better safe than sorry
+    git checkout master
+    msg pulling master from onelab
     git pull $GIT_OPTIONS $UPSTREAMREPO refs/heads/master:refs/heads/master
+    msg pushing master to flab
     git push $GIT_OPTIONS $FLABREPO refs/heads/master:refs/heads/master
 
     # manage our branches
@@ -28,12 +48,15 @@ function merge_master_in_local_branches () {
        cd $WORKDIR
         # update the local branch for changes from flab chaps
         # this is expected to be fast-forward
+       msg pulling $branch from flab
        git pull $GIT_OPTIONS $FLABREPO refs/heads/$branch:refs/heads/$branch
         # also pull the latest master in the mix - we already have it at hand
         # this OTOH may not be fast forward
        git checkout $branch
+       msg locally merging master in $branch
        git merge $GIT_OPTIONS master
         # push back
+       msg pushing back $branch onto flab
        git push $GIT_OPTIONS $FLABREPO refs/heads/$branch:refs/heads/$branch
     done
 }
@@ -60,6 +83,9 @@ function main () {
     
     [ -n "$WORKDIR" ] || WORKDIR=$DEFAULT_WORKDIR
 
+    trap failure ERR INT 
+
+    check_or_create_workdir
     merge_master_in_local_branches
  
 }