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 # a very old commit for tracking upstream repo in case we re-create this local repo
18 # drop generic for now
19 #SYNC_SPECS="master:senslab2 master:generic"
20 SYNC_SPECS="master:senslab2"
25 echo "====================" step "$@"
28 echo "==========" "$@"
33 echo Emergency exit -- Bailing out
39 msg "Going to directory $to"
43 function runcheckout () {
45 msg "Checking out branch $branch"
50 if [ -z "$INTERACTIVE" ] ; then
53 echo -n "** Run" "$@ " "[y]/n/q ? "
56 x|xy*) echo Running "$@" ; "$@" ;;
57 xq*) echo Exiting ; exit 0 ;;
58 *) echo Skipped ; return ;;
63 function trash_workdir () {
64 if [ -d $WORKDIR ] ; then
66 msg "Cleaning up $WORKDIR"
71 function check_or_create_workdir () {
72 [ -d $WORKDIR ] && return
73 step "check_or_create_workdir"
74 msg Restarting with a brand new workdir $WORKDIR
75 run git clone $FLABREPO $WORKDIR
77 run git remote rename origin flab
78 # create branch upstreammaster as the tracking branch for upstream
79 run git checkout -b upstreammaster $EPOCH
80 run git remote add -t upstreammaster -m master upstream $UPSTREAMREPO
83 function update_local_master () {
84 step "update_local_master"
86 # pull onelab master onto upstreammaster - should be fast-forward
87 runcheckout upstreammaster
88 msg "pulling upstreammaster from upstream"
89 run git pull $GIT_OPTIONS upstream refs/heads/master:refs/heads/upstreammaster
90 # pull flab master onto master -
92 msg "pulling master from flab"
93 run git pull $GIT_OPTIONS flab refs/heads/master:refs/head/master
94 # merge upstream upon local
95 msg "locally merging upstream into (flab) master"
96 run git pull $GIT_OPTIONS . upstreammaster
97 if [ -n "$PUSH" ] ; then
98 msg pushing master back to flab
99 run git push $GIT_OPTIONS flab refs/heads/master:refs/heads/master
103 function merge_master_in_local_branches () {
104 step "merge_master_in_local_branches"
108 # manage our branches: merge master into generic and generic into senslab
109 for merge in $SYNC_SPECS; do
111 what=$(echo $merge | cut -d: -f1)
113 where=$(echo $merge | cut -d: -f2)
115 # also pull the latest master in the mix - we already have it at hand
116 # this OTOH may not be fast forward
118 # update the local branch for changes from flab chaps
119 # this is expected to be fast-forward
120 msg pulling $where from flab
121 run git pull $GIT_OPTIONS flab refs/heads/$where:refs/heads/$where
122 msg locally merging $what in $where
123 run git pull $GIT_OPTIONS . $what
125 if [ -n "$PUSH" ] ; then
126 msg pushing back $where onto flab
127 run git push $GIT_OPTIONS $FLABREPO refs/heads/$where:refs/heads/$where
133 echo "Usage: $COMMAND [options]"
135 echo " -d dir : use this dir as a workdir for merging"
136 echo " please use a *dedicated* space"
137 echo " -r : restart from a fresh workdir"
138 echo " -m : master only"
139 echo " -p : does pushes"
140 echo " -s : skip pushes"
141 echo " -i : interactive"
147 # default is not to push
150 while getopts "d:rmspinv" opt; do
152 d) WORKDIR=$OPTARG; shift ;;
153 r) RESTART_FROM_SCRATCH=true ;;
154 m) MASTER_ONLY=true ;;
157 i) INTERACTIVE=true ;;
158 n) GIT_OPTIONS="$GIT_OPTIONS --dry-run" ;;
159 v) set -x ; GIT_OPTIONS="$GIT_OPTIONS --verbose" ;;
164 [ -n "$WORKDIR" ] || WORKDIR=$DEFAULT_WORKDIR
168 [ -n "$RESTART_FROM_SCRATCH" ] && trash_workdir
169 check_or_create_workdir
171 [ -n "$MASTER_ONLY" ] && return
172 merge_master_in_local_branches