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
20 echo "====================" "$@"
25 echo Emergency exit -- Bailing out
31 msg "Going to directory $to"
36 if [ -z "$INTERACTIVE" ] ; then
39 echo -n "Run" "$@ " "[y]/n/q ? "
42 x|xy*) echo Running "$@" ; "$@" ;;
43 xq*) echo Exiting ; exit 0 ;;
44 *) echo Skipped ; return ;;
49 function trash_workdir () {
50 [ -d $WORKDIR ] && run rm -rf $WORKDIR || :
53 function check_or_create_workdir () {
54 [ -d $WORKDIR ] && return
55 msg Restarting with a brand new workdir $WORKDIR
56 run git clone $FLABREPO $WORKDIR
58 run git remote rename origin flab
59 run git remote add -t master -m master onelab $UPSTREAMREPO
62 function merge_master_in_local_branches () {
63 # start with pulling the upstream master onto flab
65 # better safe than sorry
66 run git checkout master
67 msg pulling master from upstream/onelab
68 run git pull $GIT_OPTIONS $UPSTREAMREPO refs/heads/master:refs/heads/master
69 if [ -n "$PUSH_MASTER" ] ; then
70 msg pushing master to flab
71 run git push $GIT_OPTIONS $FLABREPO refs/heads/master:refs/heads/master
74 [ -n "$MASTER_ONLY" ] && return
76 # manage our branches: merge master into generic and generic into senslab
77 for merge in master:generic master:senslab2; do
78 what=$(echo $merge | cut -d: -f1)
79 where=$(echo $merge | cut -d: -f2)
81 # also pull the latest master in the mix - we already have it at hand
82 # this OTOH may not be fast forward
83 run git checkout $where
84 # update the local branch for changes from flab chaps
85 # this is expected to be fast-forward
86 msg pulling $where from flab
87 run git pull $GIT_OPTIONS $FLABREPO refs/heads/$where:refs/heads/$where
88 msg locally merging $what in $where
89 run git merge $GIT_OPTIONS $what
91 msg Avoiding the push back for now, run manually if needed
92 msg git push $GIT_OPTIONS $FLABREPO refs/heads/$where:refs/heads/$where
93 #msg pushing back $where onto flab
94 #run git push $GIT_OPTIONS $FLABREPO refs/heads/$where:refs/heads/$where
99 echo "Usage: $COMMAND [options]"
101 echo " -d dir : use this dir as a workdir for merging"
102 echo " please use a *dedicated* space"
103 echo " -r : restart from a fresh workdir"
104 echo " -m : master only"
105 echo " -s : skip master push"
106 echo " -i : interactive"
114 while getopts "d:rmsinv" opt; do
116 d) WORKDIR=$OPTARG; shift ;;
117 r) RESTART_FROM_SCRATCH=true ;;
118 m) MASTER_ONLY=true ;;
120 i) INTERACTIVE=true ;;
121 n) GIT_OPTIONS="$GIT_OPTIONS -n" ;;
122 v) set -x ; GIT_OPTIONS="$GIT_OPTIONS -v" ;;
127 [ -n "$WORKDIR" ] || WORKDIR=$DEFAULT_WORKDIR
131 [ -n "$RESTART_FROM_SCRATCH" ] && trash_workdir
132 check_or_create_workdir
133 merge_master_in_local_branches