cleanup services-to-main.sh (#6372)
- remove -B from checkout, didn't work as expected - all submodules are now using main, fallback to master no longer needed - make using git pull optional (--pull) Co-authored-by: Adrian Richter <adrian@intevation.de>
This commit is contained in:
parent
acfb4554d2
commit
a8f19e9901
@ -2,42 +2,64 @@
|
|||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
function get_upstream_branch {
|
ME=$(basename "$0")
|
||||||
local BRANCH_NAME=main
|
|
||||||
local exists=`git show-ref refs/heads/$BRANCH_NAME`
|
BRANCH_NAME=main
|
||||||
if [[ -z $exists ]]; then
|
REMOTE_NAME=
|
||||||
BRANCH_NAME=main
|
OPT_PULL=
|
||||||
fi;
|
|
||||||
echo "$BRANCH_NAME"
|
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."
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_upstream_name {
|
set_remote() {
|
||||||
git ls-remote --exit-code upstream &>/dev/null || {
|
REMOTE_NAME=upstream
|
||||||
echo "origin"
|
git ls-remote --exit-code "$REMOTE_NAME" &>/dev/null ||
|
||||||
return
|
REMOTE_NAME=origin
|
||||||
}
|
|
||||||
echo "upstream"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function pull_latest_commit {
|
pull_latest_commit() {
|
||||||
local BRANCH_NAME=$(get_upstream_branch)
|
if [ -z "$OPT_PULL" ]; then
|
||||||
local REMOTE_NAME=$(get_upstream_name)
|
echo "git fetch $REMOTE_NAME && git checkout $REMOTE_NAME/$BRANCH_NAME ..."
|
||||||
|
git fetch "$REMOTE_NAME" &&
|
||||||
echo "git checkout $BRANCH_NAME && git pull $REMOTE_NAME $BRANCH_NAME ..."
|
git checkout "$REMOTE_NAME/$BRANCH_NAME"
|
||||||
git checkout -B $BRANCH_NAME;
|
else
|
||||||
git pull $REMOTE_NAME $BRANCH_NAME;
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
export -f pull_latest_commit
|
while [ "$#" -gt 0 ]; do
|
||||||
export -f get_upstream_branch
|
case "$1" in
|
||||||
export -f get_upstream_name
|
-p | --pull)
|
||||||
|
OPT_PULL=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
usage
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
for mod in $(git submodule status | awk '{print $2}'); do
|
for mod in $(git submodule status | awk '{print $2}'); do
|
||||||
(
|
(
|
||||||
echo ""
|
echo ""
|
||||||
echo "$mod"
|
echo "$mod"
|
||||||
cd "$mod"
|
cd "$mod"
|
||||||
pull_latest_commit "$mod"
|
|
||||||
|
set_remote
|
||||||
|
pull_latest_commit
|
||||||
)
|
)
|
||||||
done
|
done
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user