blob: 854a943cb563d9517b189bf2c01097278dad8a93 [file] [log] [blame]
Yegor Timoshenkoc2e49412018-10-07 01:58:27 +00001#!/usr/bin/env bash
Martin Roth5cb22632017-07-22 21:31:56 -06002#
Patrick Georgi7333a112020-05-08 20:48:04 +02003# SPDX-License-Identifier: GPL-2.0-only
Martin Roth5cb22632017-07-22 21:31:56 -06004
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
10export LANG=C
11export LC_ALL=C
Paul Menzel38a906b2017-09-27 15:06:57 +020012export TZ=UTC0
Martin Roth5cb22632017-07-22 21:31:56 -060013
14min_commits=10
15
16TOP=${PWD}
17SUBMODULES_WITH_UPDATES=0
18submodule_dirs=$(git submodule foreach pwd | grep -v Entering)
19
20(
21echo "Checking submodules..."
22for 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
44Update ${submodule##*/} submodule to upstream master
45
46Updating from commit id ${initial_commit_id}:
47$initial_commit_description
48
49to commit id ${updated_commit_id}:
50${updated_commit_description}
51
52This brings in ${update_count} new commits.
53EOF
54 sleep 1
55 fi
56done
57
58if [ "${SUBMODULES_WITH_UPDATES}" = "0" ]; then
59 echo "No submodules with any updates."
60fi
61)