Yegor Timoshenko | c2e4941 | 2018-10-07 01:58:27 +0000 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Martin Roth | 5cb2263 | 2017-07-22 21:31:56 -0600 | [diff] [blame] | 2 | # |
Patrick Georgi | 7333a11 | 2020-05-08 20:48:04 +0200 | [diff] [blame] | 3 | # SPDX-License-Identifier: GPL-2.0-only |
Martin Roth | 5cb2263 | 2017-07-22 21:31:56 -0600 | [diff] [blame] | 4 | |
| 5 | # Description: |
| 6 | # Check all submodules for updates. If there are more than a minimum |
| 7 | # number of changes, create a commit to update the submodule to the |
| 8 | # new version. |
| 9 | |
| 10 | export LANG=C |
| 11 | export LC_ALL=C |
Paul Menzel | 38a906b | 2017-09-27 15:06:57 +0200 | [diff] [blame] | 12 | export TZ=UTC0 |
Martin Roth | 5cb2263 | 2017-07-22 21:31:56 -0600 | [diff] [blame] | 13 | |
| 14 | min_commits=10 |
| 15 | |
| 16 | TOP=${PWD} |
| 17 | SUBMODULES_WITH_UPDATES=0 |
| 18 | submodule_dirs=$(git submodule foreach pwd | grep -v Entering) |
| 19 | |
| 20 | ( |
| 21 | echo "Checking submodules..." |
| 22 | for submodule in $submodule_dirs; do |
| 23 | cd "$submodule" || exit 1 |
| 24 | initial_commit_id="$(git log --pretty='%h' -n 1)" |
| 25 | initial_commit_description="$(git log --pretty='%ci - (%s)' -n 1)" |
| 26 | git fetch 2>/dev/null |
| 27 | updated_commit_id="$(git log --pretty='%h' -n 1 origin/master)" |
| 28 | updated_commit_description="$(git log --pretty='%ci - (%s)' -n 1 "${updated_commit_id}")" |
| 29 | if [ "${initial_commit_id}" = "${updated_commit_id}" ]; then |
| 30 | # echo "No updates for ${submodule}" |
| 31 | continue |
| 32 | fi |
| 33 | SUBMODULES_WITH_UPDATES+=1 |
| 34 | update_count="$(git log --oneline "${initial_commit_id}..${updated_commit_id}" | wc -l)" |
| 35 | echo "${update_count} new commits for ${submodule}" |
| 36 | if [ "${update_count}" -ge "${min_commits}" ]; then |
| 37 | echo "Creating commit to update ${submodule##*/} submodule" |
| 38 | git checkout "${updated_commit_id}" > /dev/null 2>&1 |
| 39 | cd "${TOP}" || exit 1 |
| 40 | sleep 1 |
| 41 | git add "${submodule}" > /dev/null 2>&1 || exit 1 |
| 42 | sleep 1 |
| 43 | git commit -s -F- > /dev/null 2>&1 <<EOF |
| 44 | Update ${submodule##*/} submodule to upstream master |
| 45 | |
| 46 | Updating from commit id ${initial_commit_id}: |
| 47 | $initial_commit_description |
| 48 | |
| 49 | to commit id ${updated_commit_id}: |
| 50 | ${updated_commit_description} |
| 51 | |
| 52 | This brings in ${update_count} new commits. |
| 53 | EOF |
| 54 | sleep 1 |
| 55 | fi |
| 56 | done |
| 57 | |
| 58 | if [ "${SUBMODULES_WITH_UPDATES}" = "0" ]; then |
| 59 | echo "No submodules with any updates." |
| 60 | fi |
| 61 | ) |