11name : update submodules
22
3- # This workflow will checkout the tracked branch of all (or a subset of) submodules
3+ # This workflow will checkout the tracked branch of all submodules
44# and will update the submodule pull the latest commit of that submodule branch
55
66# If the branch was not up to date this will then open a PR against the base branch
@@ -11,8 +11,6 @@ name: update submodules
1111# this will workflow will fail.
1212#
1313
14-
15-
1614# requires sudmodules URL to be "https..." (no ssh)
1715
1816# requires submodule to be specified to follow a specific branch (stored in .gitmodules)
5452 description : " Log"
5553 required : false
5654
57- env :
58- # to update all submodules
59- SUBMOD_TO_UPDATE : " *"
60- # otherwise use a space separated list of the relative paths of each submodule to update
61- # SUBMOD_TO_UPDATE: "lib/sub_3 lib/sub_1"
62-
6355defaults :
6456 run :
6557 shell : bash
@@ -82,21 +74,22 @@ jobs:
8274 # https://stackoverflow.com/questions/5828324/update-git-submodule-to-latest-commit-on-origin
8375 - name : Update submodules
8476 run : |
77+ set -e -u
8578 start_dir=$PWD
86- if [ "${SUBMOD_TO_UPDATE}" = "*" ]; then
87- submodules=$(git submodule | awk '{print $2}')
88- else
89- submodules=$(echo -e ${SUBMOD_TO_UPDATE} | sed "s/ /\n/g")
90- fi
79+ submodules=$(git submodule | awk '{print $2}')
9180 nb_submod=$(echo "${submodules}" | wc -l)
9281 echo -e "\nUPDATING ${nb_submod} SUBMODULES"
9382 echo -e "${submodules}"
94- for i in $(seq 1 ${nb_submod}); do
95- path=$(echo -e ${submodules} | awk -v i=${i} '{print $i}')
96- branch=$(git config --get --file .gitmodules submodule.${path}.branch)
83+ paths=$(git config --file .gitmodules --name-only --get-regexp path)
84+ branches=$(git config --file .gitmodules --name-only --get-regexp branch)
85+ for i in $(seq 1 "${nb_submod}"); do
86+ path=$(echo "${paths}" | awk -v i="${i}" '{print $i}')
87+ path=$(git config --get --file .gitmodules "${path}")
88+ branch=$(echo "${branches}" | awk -v i="${i}" '{print $i}')
89+ branch=$(git config --get --file .gitmodules "${branch}")
9790 echo -e "\nswitching submodule ${path} to ${branch}"
9891 cd "${path}" || exit
99- git checkout ${branch}
92+ git checkout " ${branch}"
10093 cd "${start_dir}"
10194 done
10295 git submodule update --remote --merge
0 commit comments