From 7507d3fff57dfa4916e81aa80a876e9cb1e06908 Mon Sep 17 00:00:00 2001 From: Seb M'Caw Date: Fri, 25 Apr 2025 08:18:33 +0100 Subject: [PATCH] fix: recognition of hash specified with `--commit=` (#1942) * Add tests * Fix recognition of hash specified with `--commit=` * Fix `Remote_Commit` with local repo URLs --- src/alire/alire-vcss-git.adb | 2 +- src/alire/alire-vcss-git.ads | 3 +- src/alire/alire-vcss-hg.ads | 3 +- testsuite/tests/pin/remote/test.py | 9 +++++ testsuite/tests/with/git-reference/test.py | 38 ++++++++++++++++++++++ 5 files changed, 52 insertions(+), 3 deletions(-) diff --git a/src/alire/alire-vcss-git.adb b/src/alire/alire-vcss-git.adb index c2fd159b..09eb435b 100644 --- a/src/alire/alire-vcss-git.adb +++ b/src/alire/alire-vcss-git.adb @@ -587,7 +587,7 @@ package body Alire.VCSs.Git is Ref : String := "HEAD") return String is Output : constant AAA.Strings.Vector := - Run_Git_And_Capture (Empty_Vector & "ls-remote" & From); + Run_Git_And_Capture (Empty_Vector & "ls-remote" & Repo_URL (From)); begin -- Sample output from git (space is tab): -- 95818710c1a2bea0cbfa617a67972fe984761227 HEAD diff --git a/src/alire/alire-vcss-git.ads b/src/alire/alire-vcss-git.ads index 3a0ef639..dcb5be41 100644 --- a/src/alire/alire-vcss-git.ads +++ b/src/alire/alire-vcss-git.ads @@ -12,7 +12,8 @@ package Alire.VCSs.Git is (for all Char of Git_Commit => Char in Utils.Hexadecimal_Character); function Is_Valid_Commit (S : String) return Boolean - is (S in Git_Commit); + is (S'Length = Git_Commit'Length and then + (for all Char of S => Char in Utils.Hexadecimal_Character)); No_Commit : constant Git_Commit := (others => '0'); -- This is actually returned by e.g. `git worktree`, even if it could be a diff --git a/src/alire/alire-vcss-hg.ads b/src/alire/alire-vcss-hg.ads index 891fcec8..3d0a7dc3 100644 --- a/src/alire/alire-vcss-hg.ads +++ b/src/alire/alire-vcss-hg.ads @@ -7,7 +7,8 @@ package Alire.VCSs.Hg is (for all Char of Hg_Commit => Char in Utils.Hexadecimal_Character); function Is_Valid_Commit (S : String) return Boolean - is (S in Hg_Commit); + is (S'Length = Hg_Commit'Length and then + (for all Char of S => Char in Utils.Hexadecimal_Character)); type VCS (<>) is new VCSs.VCS with private; diff --git a/testsuite/tests/pin/remote/test.py b/testsuite/tests/pin/remote/test.py index f51a8adb..135fae81 100644 --- a/testsuite/tests/pin/remote/test.py +++ b/testsuite/tests/pin/remote/test.py @@ -55,6 +55,10 @@ init_local_crate() # This leaves us inside the new crate run_alr("with", "--use", URL, "--commit", head) verify(head) +# Add using with directly, using --arg=value +run_alr("with", f"--use={URL}", f"--commit={head}") +verify(head) + # Add using with, without head commit run_alr("with", "--use", URL) verify() @@ -64,6 +68,11 @@ run_alr("with", "upstream", force=True) # force, as it is unsolvable run_alr("pin", "upstream", "--use", URL, "--commit", head) verify(head) +# Pin afterwards, with commit, using --arg=value +run_alr("with", "upstream", force=True) +run_alr("pin", "upstream", f"--use={URL}", f"--commit={head}") +verify(head) + # Pin afterwards, without commit run_alr("with", "upstream", force=True) run_alr("pin", "upstream", "--use", URL) diff --git a/testsuite/tests/with/git-reference/test.py b/testsuite/tests/with/git-reference/test.py index 75927801..e5afdcae 100644 --- a/testsuite/tests/with/git-reference/test.py +++ b/testsuite/tests/with/git-reference/test.py @@ -27,10 +27,48 @@ alr_with("remote", delete=True, manual=False) p = run_alr("pin") assert_eq("There are no pins\n", p.out) +# Verify that pinning to a valid reference also succeeds with the --arg=value +# form +run_alr("with", "--use=../remote", "--commit=v1") +p = run_alr("pin") +assert_match("remote file:alire/cache/pins/remote_.{,8} ../remote#.{,8}", + p.out) + +# Remove dependency for next test +alr_with("remote", delete=True, manual=False) +p = run_alr("pin") +assert_eq("There are no pins\n", p.out) + +# Verify that pinning to a valid reference also succeeds with an explicit URL +alr_with(url="git+file:../remote", commit="v1", manual=False) +p = run_alr("pin") +assert_match( + r"remote file:alire/cache/pins/remote_.{,8} git\+file:\.\./remote#.{,8}", + p.out +) + +# Remove dependency for next test +alr_with("remote", delete=True, manual=False) +p = run_alr("pin") +assert_eq("There are no pins\n", p.out) + # Verify that pinning to an invalid reference fails p = run_alr("with", "--use", "../remote", "--commit", "v2", complain_on_error=False) assert_match(".*Requested remote reference v2 not found in repository.*", p.out) +# Verify that pinning to an invalid reference also fails with the +# --arg=value form +p = run_alr("with", "--use=../remote", "--commit=v2", + complain_on_error=False) +assert_match(".*Requested remote reference v2 not found in repository.*", + p.out) + +# Verify that pinning to an invalid reference also fails with an explicit URL +p = run_alr("with", "--use=git+file:../remote", "--commit=v2", + complain_on_error=False) +assert_match(".*Requested remote reference v2 not found in repository.*", + p.out) + print('SUCCESS') -- 2.39.5