Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make explicit Git URLs backward compatible #1826

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/alire/alire-selftest.adb
Original file line number Diff line number Diff line change
Expand Up @@ -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") =
Expand Down
9 changes: 6 additions & 3 deletions src/alire/alire-uri.adb
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down
5 changes: 1 addition & 4 deletions src/alire/alire-uri.ads
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
3 changes: 2 additions & 1 deletion testsuite/tests/publish/private-indexes/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ def test(
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,
Expand All @@ -264,7 +265,7 @@ def test(
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
)
Expand Down
Loading