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 | |
| 3 | # This file is part of the coreboot project. |
| 4 | # |
| 5 | # Copyright (C) 2017 Google Inc. |
| 6 | # |
| 7 | # This program is free software; you can redistribute it and/or modify |
| 8 | # it under the terms of the GNU General Public License as published by |
| 9 | # the Free Software Foundation; version 2 of the License. |
| 10 | # |
| 11 | # This program is distributed in the hope that it will be useful, |
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | # GNU General Public License for more details. |
| 15 | # |
| 16 | |
| 17 | # Description: |
| 18 | # Check all submodules for updates. If there are more than a minimum |
| 19 | # number of changes, create a commit to update the submodule to the |
| 20 | # new version. |
| 21 | |
| 22 | export LANG=C |
| 23 | export LC_ALL=C |
Paul Menzel | 38a906b | 2017-09-27 15:06:57 +0200 | [diff] [blame] | 24 | export TZ=UTC0 |
Martin Roth | 5cb2263 | 2017-07-22 21:31:56 -0600 | [diff] [blame] | 25 | |
| 26 | min_commits=10 |
| 27 | |
| 28 | TOP=${PWD} |
| 29 | SUBMODULES_WITH_UPDATES=0 |
| 30 | submodule_dirs=$(git submodule foreach pwd | grep -v Entering) |
| 31 | |
| 32 | ( |
| 33 | echo "Checking submodules..." |
| 34 | for submodule in $submodule_dirs; do |
| 35 | cd "$submodule" || exit 1 |
| 36 | initial_commit_id="$(git log --pretty='%h' -n 1)" |
| 37 | initial_commit_description="$(git log --pretty='%ci - (%s)' -n 1)" |
| 38 | git fetch 2>/dev/null |
| 39 | updated_commit_id="$(git log --pretty='%h' -n 1 origin/master)" |
| 40 | updated_commit_description="$(git log --pretty='%ci - (%s)' -n 1 "${updated_commit_id}")" |
| 41 | if [ "${initial_commit_id}" = "${updated_commit_id}" ]; then |
| 42 | # echo "No updates for ${submodule}" |
| 43 | continue |
| 44 | fi |
| 45 | SUBMODULES_WITH_UPDATES+=1 |
| 46 | update_count="$(git log --oneline "${initial_commit_id}..${updated_commit_id}" | wc -l)" |
| 47 | echo "${update_count} new commits for ${submodule}" |
| 48 | if [ "${update_count}" -ge "${min_commits}" ]; then |
| 49 | echo "Creating commit to update ${submodule##*/} submodule" |
| 50 | git checkout "${updated_commit_id}" > /dev/null 2>&1 |
| 51 | cd "${TOP}" || exit 1 |
| 52 | sleep 1 |
| 53 | git add "${submodule}" > /dev/null 2>&1 || exit 1 |
| 54 | sleep 1 |
| 55 | git commit -s -F- > /dev/null 2>&1 <<EOF |
| 56 | Update ${submodule##*/} submodule to upstream master |
| 57 | |
| 58 | Updating from commit id ${initial_commit_id}: |
| 59 | $initial_commit_description |
| 60 | |
| 61 | to commit id ${updated_commit_id}: |
| 62 | ${updated_commit_description} |
| 63 | |
| 64 | This brings in ${update_count} new commits. |
| 65 | EOF |
| 66 | sleep 1 |
| 67 | fi |
| 68 | done |
| 69 | |
| 70 | if [ "${SUBMODULES_WITH_UPDATES}" = "0" ]; then |
| 71 | echo "No submodules with any updates." |
| 72 | fi |
| 73 | ) |