From 17244e9a3f8be5cb646a5bc3fcd15e299106de2c Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Mon, 24 Feb 2020 14:35:26 +0000 Subject: [PATCH] pgit.sh: Add support for target refspec to PGIT_CLONE_FROM_USER PGIT_CLONE_CLONE_FROM_USER now supports optional suffixes of the form [:src-ref[:dst-ref]]. If present, src-ref specifies the remote branch pgit.sh tries to fetch, and dst-ref the local branch it tries to fetch into. src-ref defaults to "master" (as it was before) and dst-ref to nothing, i.e. no head-update of any local branch. Signed-off-by: Jan Lindemann --- scripts/pgit.sh | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/scripts/pgit.sh b/scripts/pgit.sh index 364871fd..933ad564 100644 --- a/scripts/pgit.sh +++ b/scripts/pgit.sh @@ -107,11 +107,15 @@ clone() local p config cd $pdir - local fromuser=$PGIT_CLONE_FROM_USER + local refspec=(${PGIT_CLONE_FROM_USER//:/ }) + local fromuser=${refspec[0]} + local fromref=${refspec[1]} + local toref=${refspec[2]} local login=$JANWARE_USER local projects="$PGIT_CLONE_PROJECTS" [ "$login" ] || login=`whoami` [ "$fromuser" ] || fromuser=`whoami` + [ "$fromref" ] || fromref=master local git_srv_admin="$SSH $login@git.janware.com /opt/jw-build/bin/git-srv-admin.sh" if [ -z "$projects" ]; then projects=`$git_srv_admin -u $fromuser -j list-personal-projects` @@ -123,6 +127,7 @@ clone() cur=`expr $cur + 1` local pullurl=ssh://$login@git.janware.com/srv/git/$fromuser/proj/$p local pushurl=ssh://$login@git.janware.com/srv/git/$login/proj/$p + local curref="" fat_marker "Fetching project $p from user $fromuser" if [ "$fromuser" = "$login" ]; then if [ -d $p ]; then @@ -130,7 +135,6 @@ clone() else run_git clone ssh://$login@git.janware.com/srv/git/$fromuser/proj/$p fi - run_git -C $p submodule update --init --recursive || fatal git submodule update failed in $p else local remotename="jw-$fromuser" if [ -d $p ]; then @@ -138,7 +142,15 @@ clone() run_git -C $p remote add $remotename $pullurl run_git -C $p remote set-url --push $remotename no_push } - run_git -C $p fetch --recurse-submodules=on-demand $remotename master + run_git -C $p fetch --prune --recurse-submodules=on-demand $remotename $fromref + if [ "$toref" ]; then + curref=`git -C $p branch --show-current` + if [ "$curref" = "$toref" ]; then + run_git -C $p pull --recurse-submodules=on-demand $remotename $fromref + else + run_git -C $p fetch --recurse-submodules=on-demand $remotename $fromref:$toref + fi + fi else # set -x run_git clone ssh://$login@git.janware.com/srv/git/$fromuser/proj/$p @@ -151,8 +163,8 @@ clone() run_git -C $p branch --set-upstream-to origin/master master # set +x fi - run_git -C $p submodule update --init --recursive || fatal git submodule update failed in $p fi + run_git -C $p submodule update --init --recursive || fatal git submodule update failed in $p done )}