pgit.sh: Support refspec keyword current-branch

If "current-branch" is specified within --refspec, either as from-ref
or as to-ref, expand that to the branch the working directory has
currently checked out.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-02-21 04:14:56 +01:00
commit 93b2a2f222

View file

@ -124,7 +124,7 @@ cmd_clone()
local jw_projects="/usr/bin/python3 $thisdir/jw-pkg.py" local jw_projects="/usr/bin/python3 $thisdir/jw-pkg.py"
local create_remote_user_repos=false local create_remote_user_repos=false
local long_opts="create-remote-user-repos" local long_opts="create-remote-user-repos"
local refspec=() local refspec_arg refspec=()
long_opts="$long_opts,refspec:" long_opts="$long_opts,refspec:"
local login="$whoami" local login="$whoami"
[ "$remote_user" ] && login="$remote_user" [ "$remote_user" ] && login="$remote_user"
@ -138,7 +138,8 @@ cmd_clone()
create_remote_user_repos=true create_remote_user_repos=true
;; ;;
--refspec) --refspec)
refspec=(${2//:/ }) refspec_arg="$2"
refspec=(${refspec_arg//:/ })
shift shift
;; ;;
*) *)
@ -177,10 +178,15 @@ cmd_clone()
cur=`expr $cur + 1` cur=`expr $cur + 1`
local pullurl=$remote_base/$fromuser$remote_subpath/$project_name local pullurl=$remote_base/$fromuser$remote_subpath/$project_name
local pushurl=$remote_base/$login$remote_subpath/$project_name local pushurl=$remote_base/$login$remote_subpath/$project_name
local curref=""
fat_marker "Fetching project $project_name from user $fromuser" fat_marker "Fetching project $project_name from user $fromuser"
local remotename="jw-$fromuser" local remotename="jw-$fromuser"
[ "$fromuser" = "$login" ] && remotename="origin" if [ "$fromuser" = "$login" ]; then
remotename="origin"
fi
local curref=$(git -C $project_dir rev-parse --abbrev-ref HEAD)
[ "$toref" = "current-branch" ] && toref=$curref
[ "$fromref" = "current-branch" ] && fromref=$curref
[ "$refspec_arg" != "$fromuser:$fromref:$toref" ] && log "Fetching $fromuser:$fromref:$toref ($refspec_arg)"
if [ -d $project_dir ]; then if [ -d $project_dir ]; then
run_git -C $project_dir remote | grep -q "^$remotename$" || { run_git -C $project_dir remote | grep -q "^$remotename$" || {
run_git -C $project_dir remote add $remotename $pullurl run_git -C $project_dir remote add $remotename $pullurl