first draft for a merging script for our branches in sfa
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Wed, 12 Oct 2011 13:41:06 +0000 (15:41 +0200)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Wed, 12 Oct 2011 13:41:06 +0000 (15:41 +0200)
scripts/flab-sync.sh [new file with mode: 0755]

diff --git a/scripts/flab-sync.sh b/scripts/flab-sync.sh
new file mode 100755 (executable)
index 0000000..ad25021
--- /dev/null
@@ -0,0 +1,70 @@
+#!/bin/bash
+
+# implement the workflow between the various branches in flab
+# basically keep the 2 branches generic and senslab 
+# in sync with master from upstream
+
+# this is expected to be a standalone directory *not* a workdir
+# initialized with a clone from git.f-lab.fr/sfa.git
+
+COMMAND=$(basename $0)
+
+DEFAULT_WORKDIR=/Users/parmentelat/git/sfa-flab-sync
+UPSTREAMREPO=ssh://thierry@git.onelab.eu/git/sfa.git
+FLABREPO=ssh://thierry@git.f-lab.fr/git/sfa.git
+TOTRACK="generic senslab"
+AGAINST=master
+
+GIT_OPTIONS=""
+
+function merge_master_in_local_branches () {
+    # start with pulling the upstream master onto flab
+    cd $WORKDIR
+    git pull $GIT_OPTIONS $UPSTREAMREPO refs/heads/master:refs/heads/master
+    git push $GIT_OPTIONS $FLABREPO refs/heads/master:refs/heads/master
+
+    # manage our branches
+    for branch in $TOTRACK; do
+       cd $WORKDIR
+        # update the local branch for changes from flab chaps
+        # this is expected to be fast-forward
+       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
+       git merge $GIT_OPTIONS master
+        # push back
+       git push $GIT_OPTIONS $FLABREPO refs/heads/$branch:refs/heads/$branch
+    done
+}
+
+function usage () {
+    echo "Usage: $COMMAND [options]"
+    echo "Options"
+    echo "-d dir : use this dir as a workdir for merging"
+    echo "         please use a *dedicated* space"
+    echo " -n : dry-run"
+    echo " -v : verbose"
+    exit 1
+}
+
+function main () {
+    while getopts "d:nv" opt; do
+       case $opt in 
+           d) WORKDIR=$OPTARG; shift ;;
+           n) GIT_OPTIONS="$GIT_OPTIONS -n" ;;
+           v) set -x ; GIT_OPTIONS="$GIT_OPTIONS -v" ;;
+            *) usage;;
+       esac
+    done
+    
+    [ -n "$WORKDIR" ] || WORKDIR=$DEFAULT_WORKDIR
+
+    merge_master_in_local_branches
+}
+
+###
+main "$@"
+
+