3 # implement the workflow between the various branches in flab
4 # basically keep the 2 branches generic and senslab
5 # in sync with master from upstream
7 # this is expected to be a standalone directory *not* a workdir
8 # initialized with a clone from git.f-lab.fr/sfa.git
10 COMMAND=$(basename $0)
12 DEFAULT_WORKDIR=/Users/parmentelat/git/sfa-flab-sync
13 UPSTREAMREPO=ssh://thierry@git.onelab.eu/git/sfa.git
14 FLABREPO=ssh://thierry@git.f-lab.fr/git/sfa.git
15 TOTRACK="generic senslab"
21 echo "====================" "$@"
26 echo Emergency exit -- Bailing out
32 msg "Going to directory $to"
37 if [ -z "$INTERACTIVE" ] ; then
40 echo -n "Run" "$@ " "[y]/n/q ? "
43 x|xy*) echo Running "$@" ; "$@" ;;
44 xq*) echo Exiting ; exit 0 ;;
45 *) echo Skipped ; return ;;
50 function trash_workdir () {
51 [ -d $WORKDIR ] && run rm -rf $WORKDIR || :
54 function check_or_create_workdir () {
55 [ -d $WORKDIR ] && return
56 msg Restarting with a brand new workdir $WORKDIR
57 run git clone $FLABREPO $WORKDIR
59 run git remote rename origin flab
60 run git remote add -t master -m master onelab $UPSTREAMREPO
63 function merge_master_in_local_branches () {
64 # start with pulling the upstream master onto flab
66 # better safe than sorry
67 run git checkout master
68 msg pulling master from upstream/onelab
69 run git pull $GIT_OPTIONS $UPSTREAMREPO refs/heads/master:refs/heads/master
70 msg pushing master to flab
71 run git push $GIT_OPTIONS $FLABREPO refs/heads/master:refs/heads/master
73 [ -n "$MASTER_ONLY" ] && return
75 # manage our branches: merge master into generic and generic into senslab
76 for merge in master:generic generic:senslab; do
77 what=$(echo $merge | cut -d: -f1)
78 where=$(echo $merge | cut -d: -f2)
80 # also pull the latest master in the mix - we already have it at hand
81 # this OTOH may not be fast forward
82 run git checkout $where
83 # update the local branch for changes from flab chaps
84 # this is expected to be fast-forward
85 msg pulling $where from flab
86 run git pull $GIT_OPTIONS $FLABREPO refs/heads/$where:refs/heads/$where
87 msg locally merging $what in $where
88 run git merge $GIT_OPTIONS $what
90 msg pushing back $where onto flab
91 run git push $GIT_OPTIONS $FLABREPO refs/heads/$where:refs/heads/$where
96 echo "Usage: $COMMAND [options]"
98 echo " -d dir : use this dir as a workdir for merging"
99 echo " please use a *dedicated* space"
100 echo " -r : restart from a fresh workdir"
101 echo " -m : master only"
102 echo " -i : interactive"
109 while getopts "d:rminv" opt; do
111 d) WORKDIR=$OPTARG; shift ;;
112 r) RESTART_FROM_SCRATCH=true ;;
113 m) MASTER_ONLY=true ;;
114 i) INTERACTIVE=true ;;
115 n) GIT_OPTIONS="$GIT_OPTIONS -n" ;;
116 v) set -x ; GIT_OPTIONS="$GIT_OPTIONS -v" ;;
121 [ -n "$WORKDIR" ] || WORKDIR=$DEFAULT_WORKDIR
125 [ -n "$RESTART_FROM_SCRATCH" ] && trash_workdir
126 check_or_create_workdir
127 merge_master_in_local_branches