Continued:
[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         fi
15
16         COMMITS_FILE="${JPROJECTS_HOME}/${project}/.gitcommits"
17
18         if [ ! -f "${COMMITS_FILE}" ]
19         then
20                 # No .gitcommits file, skip this silently
21                 continue
22         fi
23
24         COMMIT_IDS=$(cat "${COMMITS_FILE}")
25
26         if [ -n "${COMMIT_IDS}" ]
27         then
28                 cd "${JPROJECTS_HOME}/${project}"
29                 echo "$0: Fetching all for project '${project}' ..."
30                 git prune
31                 git fetch --all
32         else
33                 echo "$0: Nothing to cherry-pick for '${project}'."
34                 rm "${COMMITS_FILE}"
35                 continue
36         fi
37
38         echo "$0: Cherry-picking on project '${project}' ..."
39         for commit in ${COMMIT_IDS}; do
40                 echo "$0: Working on commit '${commit}' ..."
41                 FOUND_ID=$(git rev-list "${commit}" --max-count=1 2>&1)
42                 STATUS="$?"
43
44                 if [ "${STATUS}" != "0" ]
45                 then
46                         echo "$0: Found invalid commit id '${commit}' or status '${STATUS}'."
47                         echo "$0: Maybe forgot git-remote add <project-name>-local <local-path> ?"
48                         exit 1
49                 fi
50
51                 git cherry-pick -S "${commit}" || exit 255
52
53                 echo "$0: Removing commit from list ..."
54                 REMAINING_IDS=$(cat ${COMMITS_FILE} | grep -v "${commit}")
55                 echo "${REMAINING_IDS}" > ${COMMITS_FILE}
56         done
57
58         rm -f "${COMMITS_FILE}"
59 done
60
61 echo "$0: All done."
62 exit 0