From 5cb2263004c2068090ecdf955d3da01fd46daee7 Mon Sep 17 00:00:00 2001 From: Martin Roth Date: Sat, 22 Jul 2017 21:31:56 -0600 Subject: util/scripts: Add script to update submodules Change-Id: I4e238b539f06ce4031e0e99d26943d226a3c2556 Signed-off-by: Martin Roth Reviewed-on: https://review.coreboot.org/20703 Tested-by: build bot (Jenkins) Reviewed-by: Werner Zeh --- util/scripts/update_submodules | 73 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100755 util/scripts/update_submodules (limited to 'util/scripts') diff --git a/util/scripts/update_submodules b/util/scripts/update_submodules new file mode 100755 index 0000000000..fbf9d4f5b1 --- /dev/null +++ b/util/scripts/update_submodules @@ -0,0 +1,73 @@ +#!/bin/bash + +# This file is part of the coreboot project. +# +# Copyright (C) 2017 Google Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# + +# Description: +# Check all submodules for updates. If there are more than a minimum +# number of changes, create a commit to update the submodule to the +# new version. + +export LANG=C +export LC_ALL=C +export TZ=UTC + +min_commits=10 + +TOP=${PWD} +SUBMODULES_WITH_UPDATES=0 +submodule_dirs=$(git submodule foreach pwd | grep -v Entering) + +( +echo "Checking submodules..." +for submodule in $submodule_dirs; do + cd "$submodule" || exit 1 + initial_commit_id="$(git log --pretty='%h' -n 1)" + initial_commit_description="$(git log --pretty='%ci - (%s)' -n 1)" + git fetch 2>/dev/null + updated_commit_id="$(git log --pretty='%h' -n 1 origin/master)" + updated_commit_description="$(git log --pretty='%ci - (%s)' -n 1 "${updated_commit_id}")" + if [ "${initial_commit_id}" = "${updated_commit_id}" ]; then + # echo "No updates for ${submodule}" + continue + fi + SUBMODULES_WITH_UPDATES+=1 + update_count="$(git log --oneline "${initial_commit_id}..${updated_commit_id}" | wc -l)" + echo "${update_count} new commits for ${submodule}" + if [ "${update_count}" -ge "${min_commits}" ]; then + echo "Creating commit to update ${submodule##*/} submodule" + git checkout "${updated_commit_id}" > /dev/null 2>&1 + cd "${TOP}" || exit 1 + sleep 1 + git add "${submodule}" > /dev/null 2>&1 || exit 1 + sleep 1 + git commit -s -F- > /dev/null 2>&1 <