Skip to content

Commit

Permalink
On-line test for git-over-ssh indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
mosteo committed Feb 22, 2024
1 parent 35203d5 commit 7b89ab4
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 31 deletions.
16 changes: 15 additions & 1 deletion src/alire/alire-index_on_disk.adb
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down
1 change: 1 addition & 0 deletions src/alire/alire-index_on_disk.ads
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/alire/alire-vcss.adb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions src/alr/alr-commands-index.adb
Original file line number Diff line number Diff line change
Expand Up @@ -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://[email protected]:/path/to/repo")
.Append ("- git user over SSH: [email protected]:/org/repo")
);

---------------------
Expand Down
33 changes: 33 additions & 0 deletions testsuite/tests/index/git-ssh-remote/test.py
Original file line number Diff line number Diff line change
@@ -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")
9 changes: 9 additions & 0 deletions testsuite/tests/index/git-ssh-remote/test.yaml
Original file line number Diff line number Diff line change
@@ -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"]
26 changes: 0 additions & 26 deletions testsuite/tests/ssh/test.py

This file was deleted.

3 changes: 0 additions & 3 deletions testsuite/tests/ssh/test.yaml

This file was deleted.

0 comments on commit 7b89ab4

Please sign in to comment.