From 2c8aa8553ef23d92c3360a4d4c6e760f4e29495c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sl=C3=A1vek=20Banko?= Date: Fri, 30 Apr 2021 01:50:48 +0200 Subject: Update switch_all_submodules_to_head_and_clean + Ensure checkout for new upstream branch in worktree mode of tree. + To test the availability of repository use curl if it is present. + Sign commits using GPG during rebase if the signing key is set. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Slávek Banko (cherry picked from commit 9545e31f1887508c47299477d95f08993026c02d) --- switch_all_submodules_to_head_and_clean | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/switch_all_submodules_to_head_and_clean b/switch_all_submodules_to_head_and_clean index 2c136fd..661ff8d 100755 --- a/switch_all_submodules_to_head_and_clean +++ b/switch_all_submodules_to_head_and_clean @@ -33,7 +33,7 @@ if [[ -z "$remote" ]]; then fi # get git user -echobd "Preparing $(git rev-parse --show-toplevel | xargs -r basename) $branch branch for development use" +echobd "Preparing $(git rev-parse --show-toplevel | xargs -r basename) on $branch branch for development use" if [[ $1 == "" ]]; then gituser=`git config --local remote.$remote.url | sed -n "s|\(https\?://\)\?\([^@]*\)@.*|\2|p" | grep -v "\(anonymous\|system\)"` else @@ -48,6 +48,10 @@ if [[ $gituser == "" ]]; then gituser="anonymous" fi +if [[ -n "$(git config --get user.signingkey)" ]]; then + GIT_SIGN="-S" +fi + # check git abilities if [[ -n "`git status --help 2>/dev/null|grep -- '--ignore-submodules'`" ]]; then GIT_IGNORE_SUBMODULES="--ignore-submodules" @@ -76,9 +80,13 @@ updateModule() { fi git remote | while read REMOTE; do - REPO_SERVER=$(git config remote."$REMOTE".url | + REPO_URL=$(git config remote."$REMOTE".url) + REPO_SERVER=$(echo "$REPO_URL" | sed -n "s|^http[^/]*/*\([^@]*@\)\?\([^/]*\)/.*|\2|p") - if [ -x /usr/bin/fping ] && [ -n "$REPO_SERVER" ]; then + if [ -x /usr/bin/curl ] && [ "${REPO_URL}" != "${REPO_URL#http}" ]; then + curl --silent --connect-timeout 10 --max-time 15 --location --netrc \ + $REPO_URL/info/refs?service=git-upload-pack >/dev/null || continue + elif [ -x /usr/bin/fping ] && [ -n "$REPO_SERVER" ]; then fping -q -r1 "$REPO_SERVER" || continue fi echo Fetching $REMOTE @@ -88,7 +96,7 @@ updateModule() { git checkout $branch remote=`git config branch."$branch".remote` [[ -n "$remote" ]] || return - git rebase $remote/$branch $branch + git rebase $GIT_SIGN $remote/$branch $branch if [[ ! -z "`git status --porcelain $GIT_IGNORE_SUBMODULES`" ]]; then git reset --hard HEAD git clean -dxff @@ -135,8 +143,9 @@ updateModule() { cd $REPO_LOCALTREE && git fetch && git worktree prune && - git worktree add $PARENTDIR/$MODULE$submodule $branch && + git worktree add $PARENTDIR/$MODULE$submodule origin/$branch && cd $PARENTDIR/$MODULE$submodule && + git checkout $branch && git branch --set-upstream-to=origin/$branch ) || continue fi -- cgit v1.2.1