2022-01-18 20:46:13 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -e
|
2021-12-02 12:09:56 +01:00
|
|
|
|
2022-02-25 15:16:36 +01:00
|
|
|
ME=$(basename "$0")
|
|
|
|
|
|
|
|
BRANCH_NAME=main
|
|
|
|
REMOTE_NAME=
|
|
|
|
OPT_PULL=
|
2021-12-02 12:09:56 +01:00
|
|
|
|
2022-02-25 15:16:36 +01:00
|
|
|
usage() {
|
|
|
|
echo "USAGE:"
|
|
|
|
echo " $ME [ --pull | -p ]"
|
|
|
|
echo
|
|
|
|
echo "By default $ME will fetch the latest upstream changes for every"
|
|
|
|
echo "service/submodule and directly checkout the upstream's $BRANCH_NAME branch."
|
|
|
|
echo "This will leave them in detached HEAD state."
|
|
|
|
echo "Use --pull to instead forward the local $BRANCH_NAME branch."
|
2021-12-02 12:09:56 +01:00
|
|
|
}
|
|
|
|
|
2022-02-25 15:16:36 +01:00
|
|
|
set_remote() {
|
|
|
|
REMOTE_NAME=upstream
|
|
|
|
git ls-remote --exit-code "$REMOTE_NAME" &>/dev/null ||
|
|
|
|
REMOTE_NAME=origin
|
|
|
|
}
|
2021-12-02 12:09:56 +01:00
|
|
|
|
2022-02-25 15:16:36 +01:00
|
|
|
pull_latest_commit() {
|
|
|
|
if [ -z "$OPT_PULL" ]; then
|
|
|
|
echo "git fetch $REMOTE_NAME && git checkout $REMOTE_NAME/$BRANCH_NAME ..."
|
|
|
|
git fetch "$REMOTE_NAME" &&
|
|
|
|
git checkout "$REMOTE_NAME/$BRANCH_NAME"
|
|
|
|
else
|
|
|
|
echo "git checkout $BRANCH_NAME && git pull --ff-only $REMOTE_NAME $BRANCH_NAME ..."
|
|
|
|
git checkout "$BRANCH_NAME" &&
|
|
|
|
git pull --ff-only "$REMOTE_NAME" "$BRANCH_NAME" || {
|
|
|
|
echo "ERROR: make sure a local branch $BRANCH_NAME exists and can be fast-forwarded to $REMOTE_NAME"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
fi
|
2021-12-02 12:09:56 +01:00
|
|
|
}
|
|
|
|
|
2022-02-25 15:16:36 +01:00
|
|
|
while [ "$#" -gt 0 ]; do
|
|
|
|
case "$1" in
|
|
|
|
-p | --pull)
|
|
|
|
OPT_PULL=1
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2021-12-02 12:09:56 +01:00
|
|
|
|
2022-01-18 20:46:13 +01:00
|
|
|
for mod in $(git submodule status | awk '{print $2}'); do
|
|
|
|
(
|
|
|
|
echo ""
|
|
|
|
echo "$mod"
|
|
|
|
cd "$mod"
|
2022-02-25 15:16:36 +01:00
|
|
|
|
|
|
|
set_remote
|
|
|
|
pull_latest_commit
|
2022-01-18 20:46:13 +01:00
|
|
|
)
|
|
|
|
done
|
2021-12-02 12:09:56 +01:00
|
|
|
|
2021-12-10 12:44:13 +01:00
|
|
|
echo ""
|
|
|
|
echo "Successfully updated all submodules to latest commit."
|
2021-12-02 12:09:56 +01:00
|
|
|
|