pgit.sh get: Fix default revision for fresh clones

Fix detection of a project's revision if a project directory is
freshly cloned, and hence doesn't exist, yet. The fix is to default
to master for now.
This commit is contained in:
Jan Lindemann 2026-03-04 16:59:44 +00:00
commit f55a32024b

View file

@ -145,6 +145,15 @@ cmd_get()
fi fi
} }
project_current_revision() {
local dir="$1"
if [ -d $dir ]; then
git -C $dir rev-parse --abbrev-ref HEAD
else
echo master
fi
}
local remote_base="$global_remote_base" local remote_base="$global_remote_base"
local remote_subpath="$global_remote_subpath" local remote_subpath="$global_remote_subpath"
local whoami="$(id -un)" local whoami="$(id -un)"
@ -202,7 +211,7 @@ cmd_get()
cur=`expr $cur + 1` cur=`expr $cur + 1`
local pull_url=$remote_base/$from_user$remote_subpath/$project_name local pull_url=$remote_base/$from_user$remote_subpath/$project_name
local push_url=$remote_base/$remote_user$remote_subpath/$project_name local push_url=$remote_base/$remote_user$remote_subpath/$project_name
local cur_ref=$(git -C $project_dir rev-parse --abbrev-ref HEAD) local cur_ref=$(project_current_revision $project_dir)
local remote_name="jw-$from_user" local remote_name="jw-$from_user"
local from_ref="${refspec[1]}" local from_ref="${refspec[1]}"
local to_ref="${refspec[2]}" local to_ref="${refspec[2]}"