2021-12-02 12:09:56 +01:00
|
|
|
# !/bin/bash
|
|
|
|
|
|
|
|
function get_upstream_branch {
|
|
|
|
local SUBMODULE_NAME=$0
|
|
|
|
local MEDIA_SERVICE_NAME="openslides-media-service"
|
2022-01-10 17:46:40 +01:00
|
|
|
# We have to treat the media-service differently to the other services
|
2021-12-02 12:09:56 +01:00
|
|
|
if [ "$SUBMODULE_NAME" == "$MEDIA_SERVICE_NAME" ]; then
|
|
|
|
echo "openslides4-dev"
|
|
|
|
return
|
|
|
|
fi;
|
|
|
|
|
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 SUBMODULE_NAME=$0
|
2021-12-10 12:44:13 +01:00
|
|
|
echo ""
|
|
|
|
echo "$SUBMODULE_NAME"
|
2021-12-02 12:09:56 +01:00
|
|
|
|
|
|
|
local BRANCH_NAME=$(get_upstream_branch)
|
|
|
|
local REMOTE_NAME=$(get_upstream_name)
|
|
|
|
|
2021-12-10 12:44:13 +01:00
|
|
|
echo "git fetch $REMOTE_NAME && git checkout $REMOTE_NAME/$BRANCH_NAME ..."
|
|
|
|
git fetch $REMOTE_NAME;
|
|
|
|
git checkout $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
|
|
|
|
|
|
|
|
git submodule foreach -q --recursive "bash -c pull_latest_commit \$name"
|
|
|
|
|
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
|
|
|
|
|
|
|
# Old command, if we need to checkout another branch than master or main:
|
|
|
|
# git submodule foreach -q --recursive
|
|
|
|
# '
|
2022-01-10 17:46:40 +01:00
|
|
|
# git checkout $(git config -f $$toplevel/.gitmodules submodule.$$name.branch || echo main);
|
|
|
|
# git pull upstream $$(git config -f $$toplevel/.gitmodules submodule.$$name.branch || echo main)
|
2022-01-13 19:10:34 +01:00
|
|
|
# '
|