blob: 68d8a948accb1f8f55b8ea9ec63cd9f2e156ace5 [file] [log] [blame]
Yegor Timoshenkoc2e49412018-10-07 01:58:27 +00001#!/usr/bin/env bash
Martin Roth5cb22632017-07-22 21:31:56 -06002
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
22export LANG=C
23export LC_ALL=C
Paul Menzel38a906b2017-09-27 15:06:57 +020024export TZ=UTC0
Martin Roth5cb22632017-07-22 21:31:56 -060025
26min_commits=10
27
28TOP=${PWD}
29SUBMODULES_WITH_UPDATES=0
30submodule_dirs=$(git submodule foreach pwd | grep -v Entering)
31
32(
33echo "Checking submodules..."
34for 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
56Update ${submodule##*/} submodule to upstream master
57
58Updating from commit id ${initial_commit_id}:
59$initial_commit_description
60
61to commit id ${updated_commit_id}:
62${updated_commit_description}
63
64This brings in ${update_count} new commits.
65EOF
66 sleep 1
67 fi
68done
69
70if [ "${SUBMODULES_WITH_UPDATES}" = "0" ]; then
71 echo "No submodules with any updates."
72fi
73)