Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions actions/setup/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,44 @@ gitResolvePrefixToTag() {
local prefix="$2"
local refs=$(git ls-remote --tags --heads "$url")

local exact_match=$(echo "$refs" | sed -E -n "s%.*refs/(heads|tags)/($prefix)\$%\2%p" | head -n1)
if [ -n "$exact_match" ]; then
echo "$exact_match"
# try exact matching ref
local ref=$(echo "$refs" | sed -E -n "s%.*refs/(heads|tags)/($prefix)\$%\2%p" | head -n1)
if [ -n "$ref" ]; then
echo "$ref"
return 0
fi

if [ -z "$prefix" ]; then
prefix="v?"
# find latest ref matching prefix
local ref=$(
echo "$refs" \
| sed -E -n "s%.*refs/tags/${prefix-v?}([0-9]+\.[0-9]+\.[0-9]+)\$%\1%p" \
| grep -v '\^{}$' \
| sort -t. -k1,1nr -k2,2nr -k3,3nr \
| head -n1
)
if [ -n "$ref" ]; then
echo "$prefix$ref"
Comment on lines +13 to +22
Copy link
Member

@rchl rchl Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think one case it doesn't handle is when no prefix is provided but tags start with v. Then $prefix will be an empty string and v won't be part of returned ref.

Copy link
Member

@rchl rchl Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also it seems like ${prefix-v?} will only fall back to v? when it's not set which I believe will never be true in this case. It doesn't fall back when $prefix is empty string.

return 0
fi

local matched_tags=$(echo "$refs" | sed -E -n "s%.*refs/tags/($prefix[0-9]+\.[0-9]+\.[0-9]+)\$%\1%p" | grep -v '\^{}$')

echo "$matched_tags" | sort -t. -k1,1nr -k2,2nr -k3,3nr | head -n1
return 2
}

InstallPackage() {
local dest="$SUBLIME_TEXT_PACKAGES/$1"
local url="$2"
local prefix="$3"
local tag=$(gitResolvePrefixToTag "$url" "$prefix")
echo Installing "$1" from "$url"@"$tag" to "$dest"
local ref=$(gitResolvePrefixToTag "$url" "$prefix")

if [ -z "$ref" ]; then
echo No ref found for "$1"
exit 2;
fi

echo Installing "$1" from "$url"@"$ref" to "$dest"
if [ ! -d "$dest" ]; then
mkdir -p "$dest"
git clone --quiet --depth 1 --branch "$tag" "$url" "$dest"
git clone --quiet --depth 1 --branch "$ref" "$url" "$dest"
rm -rf "$dest/.git"
fi
}