pgit.sh: Support --refspec

In the attempt to move away from communicating options via
environment variables from one part of jw-build software to another,
replace PGIT_CLONE_FROM_USER with the clearer --refspec option. Which
is also more versatile.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2025-11-24 10:04:47 +01:00
commit d047ad650c
2 changed files with 32 additions and 21 deletions

View file

@ -103,30 +103,28 @@ clone()
local p
config
cd $pdir
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"
local ignore="$PGIT_IGNORE"
local thisdir="${0%/*}"
local jw_projects="/usr/bin/python3 $thisdir/jw-projects.py"
local create_remote_user_repos=false
[ "$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"
local long_opts="create-remote-user-repos"
local refspec=()
long_opts="$long_opts,refspec:"
local opts
opts=$(getopt -o C --long create-remote-user-repos -n clone -- "$@") || fatal "Failed to parse options $@"
opts=$(getopt -o C --long "$long_opts" -n clone -- "$@") || fatal "Failed to parse options $@"
eval set -- "$opts"
while [ "$1" != -- ]; do
case "$1" in
-c | --create-remote-user-repos)
-C | --create-remote-user-repos)
create_remote_user_repos=true
;;
--refspec)
refspec=(${2//:/ })
shift
;;
*)
fatal "Unknown option $1"
;;
@ -135,10 +133,20 @@ clone()
shift
done
local fromuser="${refspec[0]}"
local fromref="${refspec[1]}"
local toref="${refspec[2]}"
local whoami="$(id -un)"
[ "$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=`$jw_projects list-repos --from-user $fromuser $remote_base`
[ "$?" != 0 ] && exit 1
fi
n_projects=`echo $projects | wc -w`
if [ "$PGIT_KEEP_GOING" != y ]; then set -e; fi
for p in $projects; do