From 1c4d02af7f78306304af95a4f4bd2ee0ac8f8759 Mon Sep 17 00:00:00 2001 From: Seb M'Caw Date: Thu, 23 Jan 2025 10:42:18 +0000 Subject: [PATCH] feat: make explicit Git URLs backward compatible (#1826) --- src/alire/alire-selftest.adb | 2 +- src/alire/alire-uri.adb | 9 ++++++--- src/alire/alire-uri.ads | 5 +---- testsuite/tests/publish/private-indexes/test.py | 3 ++- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/alire/alire-selftest.adb b/src/alire/alire-selftest.adb index a6f8c69b..a0e10ffb 100644 --- a/src/alire/alire-selftest.adb +++ b/src/alire/alire-selftest.adb @@ -140,7 +140,7 @@ package body Alire.Selftest is -- Proper transform starting with .git pragma Assert (Transform_To_Public ("git@github.com:user/project.git") = - "https://github.com/user/project.git"); + "git+https://github.com/user/project.git"); -- GitLab pragma Assert (Transform_To_Public ("git@gitlab.com:user/project") = diff --git a/src/alire/alire-uri.adb b/src/alire/alire-uri.adb index 6129773f..c89dbf1f 100644 --- a/src/alire/alire-uri.adb +++ b/src/alire/alire-uri.adb @@ -199,11 +199,14 @@ package body Alire.URI is elsif Current_Kind = SCP_Style_Git then -- git@host:/path is already explicit return This; - elsif Current_Kind in Probably_Git then - -- Prepend prefix to make it *_Definitely_Git + elsif not Has_Prefix (This, VCS_Prefix) then + -- Ensure a 'vcs+' prefix is present + -- + -- We do this even for URLs with a '.git' suffix, as they are + -- not otherwise recognized by pre-2.1 versions of alr. return VCS_Prefix & This; else - -- This is already recognized as the correct VCS, so do nothing + -- This already has a 'vcs+' prefix, so do nothing return This; end if; when others => diff --git a/src/alire/alire-uri.ads b/src/alire/alire-uri.ads index 4d0375b1..38022df0 100644 --- a/src/alire/alire-uri.ads +++ b/src/alire/alire-uri.ads @@ -231,15 +231,12 @@ package Alire.URI with Preelaborate is function Make_VCS_Explicit (This : String; Kind : VCS_Kinds) return String with Post => URI_Kind (Make_VCS_Explicit'Result) in VCS_URIs; - -- Return the URL minimally modified to make the VCS recognizable. + -- Return the URL modified to ensure the VCS is recognizable. -- -- For example, This => "https://host/path" with Kind => Git returns -- "git+https://host/path", and This => "/some/path" with Kind => Hg -- returns "hg+file:/some/path". -- - -- Changes are only made if necessary, so This => "https://host/path.git" - -- and Kind => Git returns the URL unmodified. - -- -- Raises Program_Error if the URL already looks like a different VCS -- or has a URI_Kind of External or System. diff --git a/testsuite/tests/publish/private-indexes/test.py b/testsuite/tests/publish/private-indexes/test.py index 7cf91495..012261bd 100644 --- a/testsuite/tests/publish/private-indexes/test.py +++ b/testsuite/tests/publish/private-indexes/test.py @@ -254,6 +254,7 @@ for force_arg in ([], ["--force"]): expect_success=False ) # "alr publish --for-private-index" will succeed. + explicit_url = url if url.startswith("git@") else f"git+{url}" test( args=force_arg + ["publish", "--for-private-index"], url=url, @@ -264,7 +265,7 @@ for force_arg in ([], ["--force"]): r".*Please upload this file to the index in the xx/xxx/ subdirectory", ], gen_manifest=[ - f'.*url = "{re.escape(url)}".*', + f'.*url = "{re.escape(explicit_url)}".*', ], expect_success=True ) -- 2.39.5