added ability to delete branches
[jprojects-scripts.git] / cherry-jprojects.sh
1 #!/bin/bash
2
3 . ./.jprojects.sh || exit 255
4
5 for project in ${LIST}; do
6         if [ "${project}" = "jprojects-scripts" ]
7         then
8                 echo "$0: Skipping jprojects-scripts ..."
9                 continue
10         elif [ ! -d "${JPROJECTS_HOME}/${project}" ]
11         then
12                 echo "$0: Project '${project}' does not exist."
13                 continue
14         elif [ ! -f "${JPROJECTS_HOME}/${project}/.gitcommits" ]
15         then
16                 # No .gitcommits file, skip this silently
17                 continue
18         fi
19
20         COMMIT_IDS=`cat "${JPROJECTS_HOME}/${project}/.gitcommits"`
21         COMMITS_FILE="${JPROJECTS_HOME}/${project}/.gitcommits"
22
23         echo "$0: Cherry-picking on project '${project}' ..."
24         for commit in ${COMMIT_IDS}; do
25                 cd "${JPROJECTS_HOME}/${project}"
26                 echo "$0: Working on commit '${commit}' ..."
27                 FOUND_ID=`git rev-list "${commit}" --max-count=1 2>&1`
28                 STATUS="$?"
29
30                 if [ "${STATUS}" != "0" ]
31                 then
32                         echo "$0: Found invalid commit id '${commit}' or status '${STATUS}'."
33                         echo "$0: Maybe forgot git-remote add <project-name>-local <local-path> ?"
34                         exit 1
35                 fi
36
37                 git cherry-pick -S "${commit}" || exit 255
38
39                 echo "$0: Removing commit from list ..."
40                 REMAINING_IDS=`cat ${COMMITS_FILE} | grep -v "${commit}"`
41                 echo "${REMAINING_IDS}" > ${COMMITS_FILE}
42         done
43
44         rm -f "${COMMITS_FILE}"
45 done
46
47 echo "$0: All done."
48 exit 0