4fc55254d1760cda77662603e5e64d2b764dc9d4
[jprojects-scripts.git] / merge-jprojects.sh
1 #!/bin/bash
2
3 . ./.jprojects.sh || exit 255
4
5 SOURCE_BRANCH="master"
6 TARGET_BRANCH="rewrites/jpa"
7 SWITCH_TO_SOURCE="Y"
8
9 for project in ${LIST}; do
10         if [ "${project}" = "jprojects-scripts" ]
11         then
12                 echo "$0: Skipping jprojects-scripts ..."
13                 continue
14         elif [ ! -d "${JPROJECTS_HOME}/${project}" ]
15         then
16                 echo "$0: Project '${project}' does not exist."
17                 continue
18         fi
19
20         echo "$0: Processing '${project}' ..."
21         cd "${JPROJECTS_HOME}/${project}"
22
23         # Make sure the source branch is there
24         git checkout "${SOURCE_BRANCH}" || exit 255
25
26         # ... and target branch
27         git checkout "${TARGET_BRANCH}" 2>&1
28         STATUS="$?"
29
30         if [ "${STATUS}" = "0" ]
31         then
32                 # Then merge
33                 echo "$0: Merging '${SOURCE_BRANCH}' in project '${project}' ..."
34                 git merge -S "${SOURCE_BRANCH}" || exit 255
35
36                 if [ "${SWITCH_TO_SOURCE}" = "Y" ]
37                 then
38                         echo "$0: Switching back to '${SOURCE_BRANCH}'"
39                         git checkout "${SOURCE_BRANCH}"
40                 fi
41         else
42                 echo "$0: Project '${project}' has no branch '${TARGET_BRANCH}'."
43         fi
44 done
45
46 echo "$0: All done."
47 exit 0