added ability to delete branches
[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         echo "$0: Processing '${project}' ..."
11         cd "${JPROJECTS_HOME}/${project}"
12
13         # Make sure the source branch is there
14         git checkout "${SOURCE_BRANCH}" || exit 255
15
16         # ... and target branch
17         git checkout "${TARGET_BRANCH}" 2>&1
18         STATUS="$?"
19
20         if [ "${STATUS}" = "0" ]
21         then
22                 # Then merge
23                 echo "$0: Merging '${SOURCE_BRANCH}' in project '${project}' ..."
24                 git merge -S "${SOURCE_BRANCH}" || exit 255
25
26                 if [ "${SWITCH_TO_SOURCE}" = "Y" ]
27                 then
28                         echo "$0: Switching back to '${SOURCE_BRANCH}'"
29                         git checkout "${SOURCE_BRANCH}"
30                 fi
31         else
32                 echo "$0: Project '${project}' has no branch '${TARGET_BRANCH}'."
33         fi
34 done
35
36 echo "$0: All done."
37 exit 0