Skip to content

Commit 99d0063

Browse files
Copilotmarkphip
andcommitted
Fix Microsoft Git install to use releases API for 'latest'
Co-authored-by: markphip <933108+markphip@users.noreply.github.com>
1 parent 5b86cae commit 99d0063

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/microsoft-git/install.sh

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,25 @@ fi
4444
# Partial version matching
4545
if [ "$(echo "${GIT_VERSION}" | grep -o '\.' | wc -l)" != "2" ]; then
4646
requested_version="${GIT_VERSION}"
47-
version_list="$(curl -sSL -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/microsoft/git/tags?per_page=100" | grep -oP '"name":\s*"v\K[0-9]+\.[0-9]+\.[0-9]+\.vfs\.[0-9]+\.[0-9]+"' | tr -d '"' | sort -rV)"
48-
if [ "${requested_version}" = "latest" ] || [ "${requested_version}" = "lts" ] || [ "${requested_version}" = "current" ]; then
49-
GIT_VERSION="$(echo "${version_list}" | head -n 1)"
47+
if [ "${requested_version}" = "latest" ]; then
48+
# For latest, use the releases API to get the actual latest release
49+
GIT_VERSION="$(curl -sSL -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/microsoft/git/releases/latest" | grep -oP '"tag_name":\s*"v\K[0-9]+\.[0-9]+\.[0-9]+\.vfs\.[0-9]+\.[0-9]+"' | tr -d '"')"
5050
else
51-
set +e
52-
GIT_VERSION="$(echo "${version_list}" | grep -E -m 1 "^${requested_version//./\\.}([\\.\\s]|$)")"
53-
set -e
51+
# For other cases (lts, current, partial versions), use the existing tags logic
52+
version_list="$(curl -sSL -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/microsoft/git/tags?per_page=100" | grep -oP '"name":\s*"v\K[0-9]+\.[0-9]+\.[0-9]+\.vfs\.[0-9]+\.[0-9]+"' | tr -d '"' | sort -rV)"
53+
if [ "${requested_version}" = "lts" ] || [ "${requested_version}" = "current" ]; then
54+
GIT_VERSION="$(echo "${version_list}" | head -n 1)"
55+
else
56+
set +e
57+
GIT_VERSION="$(echo "${version_list}" | grep -E -m 1 "^${requested_version//./\\.}([\\.\\s]|$)")"
58+
set -e
59+
fi
60+
if [ -z "${GIT_VERSION}" ] || ! echo "${version_list}" | grep "^${GIT_VERSION//./\\.}$" > /dev/null 2>&1; then
61+
echo "Invalid git version: ${requested_version}" >&2
62+
exit 1
63+
fi
5464
fi
55-
if [ -z "${GIT_VERSION}" ] || ! echo "${version_list}" | grep "^${GIT_VERSION//./\\.}$" > /dev/null 2>&1; then
65+
if [ -z "${GIT_VERSION}" ]; then
5666
echo "Invalid git version: ${requested_version}" >&2
5767
exit 1
5868
fi

0 commit comments

Comments
 (0)