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