before this change, we suse `git submodule summary ${submodule}`
for collecting the titles of commits in between current HEAD and
origin/master. normally, this works just fine. but it fails to
collect all commits if the origin/master happens to reference
a merge commit. for instance, if we have following history like:
1. merge foo
2. bar
3. foo
4. baz <--- submodule is pointing here.
`git submodule summary` would just print out the titles of commits
of 1 and 3.
so, in this change, instead of relying on `git submodule summary`,
we just collect the commits using `git log`. but we preserve the
output format used by `git submodule summary` to be consistent with
the previous commits bumping up the submodules. please note, in
this change instead of matching the output of `git submodule summary`,
we use `git merge-base --is-ancestor HEAD origin/master` to check
if we are going to create a fastforward change, this is less fragile.
Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>
Closes #13366
54 lines
1.6 KiB
Bash
Executable File
54 lines
1.6 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# Refresh git submodules by fast-forward merging them to the tip of the
|
|
# master branch of their respective repositories and committing the
|
|
# update with a default commit message of "git submodule summary".
|
|
#
|
|
# Copyright (C) 2020-present ScyllaDB
|
|
#
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
#
|
|
|
|
set -euo pipefail
|
|
|
|
# The following is the default list of submodules to refresh. To only refresh
|
|
# some of them, pass the list of modules to refresh as arguments. For example,
|
|
# "scripts/refresh-submodules.sh seastar tools/java" only refreshes the
|
|
# two submodules seastar and tools/java.
|
|
submodules=(
|
|
seastar
|
|
tools/jmx
|
|
tools/java
|
|
tools/python3
|
|
)
|
|
|
|
for ent in "${@:-${submodules[@]}}"; do
|
|
submodule=${ent%%:*}
|
|
[ ${submodule} == ${ent} ] && branch="master" || branch=${ent#*:}
|
|
bump_to=origin/${branch}
|
|
|
|
pushd .
|
|
cd $submodule
|
|
git fetch origin ${branch}
|
|
if ! git merge-base --is-ancestor HEAD ${bump_to}; then
|
|
echo "Non fast-forward changes detected! Fire three red flares from your flare pistol."
|
|
exit 1
|
|
fi
|
|
# collect the summary
|
|
head_ref=$(git rev-parse --short=8 HEAD)
|
|
branch_ref=$(git rev-parse --short=8 ${branch})
|
|
count=$(git rev-list --no-merges --count HEAD..${bump_to})
|
|
# create a summary using the output format of "git submodule summary"
|
|
SUMMARY="
|
|
* ${submodule} ${head_ref}...${branch_ref} (${count}):
|
|
$(git log --pretty='format: > %s' --no-merges HEAD..${bump_to})"
|
|
|
|
# fast-forward to origin/master
|
|
git merge --ff-only ${bump_to}
|
|
popd
|
|
|
|
if [ ! -z "$SUMMARY" ]; then
|
|
git commit --edit -m "Update $submodule submodule" -m "$SUMMARY" $submodule
|
|
fi
|
|
done
|