added ability to delete branches
[jprojects-scripts.git] / create-jproject-branch.sh
1 #!/bin/bash
2
3 . ./.jprojects.sh || exit 255
4
5 echo "$0: JPROJECTS_HOME='${JPROJECTS_HOME}'"
6
7 NEW_BRANCH="rewrites/wildfly"
8
9 #COMMIT_MESSAGE="WildFly branch created with initial scripts, but it doesn't load my libs."
10 COMMIT_MESSAGE=""
11 COMMIT_ADD=""
12 AFTER_COMMIT_BRANCH="master"
13
14 for project in ${LIST}; do
15         if [ ! -d "${JPROJECTS_HOME}/${project}" ]
16         then
17                 continue
18         fi
19
20         echo "$0: Processing '${project}' ..."
21         cd "${JPROJECTS_HOME}/${project}"
22
23         CHECK_BRANCH=`git branch --all | grep "${NEW_BRANCH}"`
24         echo "$0: CHECK_BRANCH='${CHECK_BRANCH}'"
25
26         if [ -z "${CHECK_BRANCH}" ]
27         then
28                 echo "$0: Creating branch '${NEW_BRANCH}' ..."
29                 git checkout -b "${NEW_BRANCH}"
30         fi
31
32         if [ -n "${COMMIT_MESSAGE}" ]
33         then
34                 if [ -n "${COMMIT_ADD}" ]
35                 then
36                         echo "$0: Adding '${COMMIT_ADD}' ..."
37                         git add "${COMMIT_ADD}"
38                 fi
39
40                 echo "$0: Committing '${NEW_BRANCH}' ..."
41                 git commit -m "${COMMIT_MESSAGE}" --signoff -S -a
42         fi
43
44         if [ -n "${AFTER_COMMIT_BRANCH}" ]
45         then
46                 echo "$0: Switching in '${project}' to '${AFTER_COMMIT_BRANCH}' ..."
47                 git checkout "${AFTER_COMMIT_BRANCH}"
48         fi
49 done
50
51 echo "$0: All done."
52 exit 0