diff --git a/src/alire/alire-index_on_disk.adb b/src/alire/alire-index_on_disk.adb index 37013ca28..336fa0fde 100644 --- a/src/alire/alire-index_on_disk.adb +++ b/src/alire/alire-index_on_disk.adb @@ -223,7 +223,21 @@ package body Alire.Index_On_Disk is return Process_Local_Index (Origin); end if; - -- Process other paths as VCS's + -- Process "git+ssh://" as git over ssh and suggest for "ssh://" + + if AAA.Strings.Has_Prefix (Origin, SSH_Prefix) then + Result := Outcome_Failure + ("ssh:// URLs are not valid index origins. " + & "You may want git+" & Origin & " instead."); + return New_Invalid_Index; + elsif AAA.Strings.Has_Prefix (Origin, "git+" & SSH_Prefix) then + Result := Outcome_Success; + return Index_On_Disk.Git + .New_Handler (Origin, Name, Parent) + .With_Priority (Priority); + end if; + + -- Process other paths as VCSs case VCSs.Kind (Origin) is when VCSs.VCS_Git => diff --git a/src/alire/alire-index_on_disk.ads b/src/alire/alire-index_on_disk.ads index da33535c7..7d273dbd1 100644 --- a/src/alire/alire-index_on_disk.ads +++ b/src/alire/alire-index_on_disk.ads @@ -22,6 +22,7 @@ package Alire.Index_On_Disk is File_Prefix : constant String := "file://"; HTTP_Prefix : constant String := "http"; + SSH_Prefix : constant String := "ssh://"; subtype Priorities is Integer; -- Lower is loaded before diff --git a/src/alire/alire-vcss.adb b/src/alire/alire-vcss.adb index 022c1294f..90d4cb276 100644 --- a/src/alire/alire-vcss.adb +++ b/src/alire/alire-vcss.adb @@ -51,7 +51,7 @@ package body Alire.VCSs is --------------------- function Repo_And_Commit (Origin : URL) return String - is (if Contains (Origin, "+http") + is (if Contains (Origin, "+http") or else Has_Prefix (Origin, "git+") then Tail (Origin, '+') elsif Has_Prefix (Origin, "file://") then Origin (Origin'First + 7 .. Origin'Last) diff --git a/src/alr/alr-commands-index.adb b/src/alr/alr-commands-index.adb index 6908e469b..a5a470e33 100644 --- a/src/alr/alr-commands-index.adb +++ b/src/alr/alr-commands-index.adb @@ -208,6 +208,13 @@ package body Alr.Commands.Index is & " case a pull operation will be performed on them." & " An index initially set up with a specific commit will" & " not be updated.") + .New_Line + .Append ("URL can be one of:") + .Append ("- Plain absolute path: /path/to/index") + .Append ("- Explicit path: file://path/to/index") + .Append ("- git over HTTP/HTTPS: git+https://github.com/org/repo") + .Append ("- git over SSH: git+ssh://user@host.com:/path/to/repo") + .Append ("- git user over SSH: git@github.com:/org/repo") ); --------------------- diff --git a/testsuite/tests/index/git-ssh-remote/test.py b/testsuite/tests/index/git-ssh-remote/test.py new file mode 100644 index 000000000..d442c3f2b --- /dev/null +++ b/testsuite/tests/index/git-ssh-remote/test.py @@ -0,0 +1,33 @@ +from drivers.alr import init_local_crate, run_alr + +ORG="github.com:/alire-project" +INDEX_REPO="test-index" +CRATE_REPO="libhello" +SSH_IMPLICIT_INDEX = f"git@{ORG}/{INDEX_REPO}" +SSH_EXPLICIT_INDEX = f"git+ssh://{SSH_IMPLICIT_INDEX}" + +# Test that we can add an index using implicit ssh +run_alr("index", "--name", "implicit", "--add", SSH_EXPLICIT_INDEX) +run_alr("index", "--check") +run_alr("index", "--update-all") # Check pulling + +# Remove so it can be re-added +run_alr("index", "--del", "implicit") + +# Test that we can add an index using explicit ssh +run_alr("index", "--name", "explicit", "--add", SSH_EXPLICIT_INDEX) +run_alr("index", "--check") +run_alr("index", "--update-all") + +# Test that we can pin a crate using implicit ssh +init_local_crate() +run_alr("with", "libhello", "--use", f"git@{ORG}/{CRATE_REPO}") +run_alr("update") # Check pulling pin + +# Remove and re-pin using explicit ssh +run_alr("with", "--del", "libhello") +run_alr("with", "libhello", "--use", f"git+ssh://git@{ORG}/{CRATE_REPO}") +run_alr("update") + + +print("SUCCESS") diff --git a/testsuite/tests/index/git-ssh-remote/test.yaml b/testsuite/tests/index/git-ssh-remote/test.yaml new file mode 100644 index 000000000..b61eac805 --- /dev/null +++ b/testsuite/tests/index/git-ssh-remote/test.yaml @@ -0,0 +1,9 @@ +driver: python-script +indexes: + compiler_only_index: {} + +# We cannot run this test without ssh keys, so not intended for remote use. +# Also, it requires going on-line. +control: + - [SKIP, "skip_local", "Local developer-only tests disabled"] + - [SKIP, "skip_network", "Network-requiring tests disabled"] diff --git a/testsuite/tests/ssh/test.py b/testsuite/tests/ssh/test.py deleted file mode 100644 index 7ced45369..000000000 --- a/testsuite/tests/ssh/test.py +++ /dev/null @@ -1,26 +0,0 @@ -from drivers.alr import init_local_crate, run_alr -import os, subprocess - -HOST = "github.com" -INDEX = "git@github.com:alire-project/test-index.git" -KNOWN_HOSTS_DIRECTORY = "~/.ssh" - -# Test setup. -os.makedirs(KNOWN_HOSTS_DIRECTORY, exist_ok=True) -with open(KNOWN_HOSTS_DIRECTORY + "/known_hosts", "a+") as known_hosts: - if HOST not in known_hosts.read(): - host_key = subprocess.run(["ssh-keyscan", HOST], capture_output=True).stdout - known_hosts.write(f"{host_key}\n") -init_local_crate() - -# Ensure we can add an index using ssh. -run_alr("index", "--name", "test", "--add", INDEX, complain_on_error=True) -run_alr("index", "--check", complain_on_error=True) - -# Ensure we can pin a crate using ssh. -run_alr("with", "libhello", "--use", "git@github.com:alire-project/libhello.git") - -# Test teardown. -run_alr("index", "--del", "test", complain_on_error=True) - -print("SUCCESS") diff --git a/testsuite/tests/ssh/test.yaml b/testsuite/tests/ssh/test.yaml deleted file mode 100644 index fa855459b..000000000 --- a/testsuite/tests/ssh/test.yaml +++ /dev/null @@ -1,3 +0,0 @@ -driver: python-script -indexes: - compiler_only_index: {}