2022-01-18 20:46:13 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -e
|
2021-12-02 12:09:56 +01:00
|
|
|
|
|
|
|
function get_upstream_branch {
|
2022-01-13 19:10:34 +01:00
|
|
|
local BRANCH_NAME=main
|
2021-12-02 12:09:56 +01:00
|
|
|
local exists=`git show-ref refs/heads/$BRANCH_NAME`
|
|
|
|
if [[ -z $exists ]]; then
|
|
|
|
BRANCH_NAME=main
|
|
|
|
fi;
|
|
|
|
echo "$BRANCH_NAME"
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_upstream_name {
|
2021-12-09 16:05:50 +01:00
|
|
|
git ls-remote --exit-code upstream &>/dev/null || {
|
2021-12-02 12:09:56 +01:00
|
|
|
echo "origin"
|
2021-12-09 16:05:50 +01:00
|
|
|
return
|
2021-12-02 12:09:56 +01:00
|
|
|
}
|
2022-01-10 17:46:40 +01:00
|
|
|
echo "upstream"
|
2021-12-02 12:09:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function pull_latest_commit {
|
|
|
|
local BRANCH_NAME=$(get_upstream_branch)
|
|
|
|
local REMOTE_NAME=$(get_upstream_name)
|
|
|
|
|
2022-02-16 16:19:58 +01:00
|
|
|
echo "git checkout $BRANCH_NAME && git pull $REMOTE_NAME $BRANCH_NAME ..."
|
|
|
|
git checkout -B $BRANCH_NAME;
|
|
|
|
git pull $REMOTE_NAME $BRANCH_NAME;
|
2021-12-02 12:09:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export -f pull_latest_commit
|
|
|
|
export -f get_upstream_branch
|
|
|
|
export -f get_upstream_name
|
|
|
|
|
2022-01-18 20:46:13 +01:00
|
|
|
for mod in $(git submodule status | awk '{print $2}'); do
|
|
|
|
(
|
|
|
|
echo ""
|
|
|
|
echo "$mod"
|
|
|
|
cd "$mod"
|
|
|
|
pull_latest_commit "$mod"
|
|
|
|
)
|
|
|
|
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
|
|
|
|