Skip to content

Commit

Permalink
fix(cargo): don't attempt to fetch versions when version targets comm…
Browse files Browse the repository at this point in the history
…it SHA (#1585)
  • Loading branch information
williamboman committed Dec 29, 2023
1 parent 41e75af commit a09da6a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lua/mason-core/installer/registry/providers/cargo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,14 @@ end
function M.get_versions(purl)
---@type string?
local repository_url = _.path({ "qualifiers", "repository_url" }, purl)
local rev = _.path({ "qualifiers", "rev" }, purl)
if repository_url then
if rev == "true" then
-- When ?rev=true we're targeting a commit SHA. It's not feasible to retrieve all commit SHAs for a
-- repository so we fail instead.
return Result.failure "Unable to retrieve commit SHAs."
end

---@type Result?
local git_tags = _.cond {
{
Expand Down
12 changes: 12 additions & 0 deletions tests/mason-core/installer/registry/providers/cargo_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,16 @@ describe("cargo provider :: versions", function()
assert.spy(providers.github.get_all_tags).was_called(1)
assert.spy(providers.github.get_all_tags).was_called_with "rust-lang/rust-analyzer"
end)

it("should not provide git commit SHAs", function()
local result = cargo.get_versions(purl {
qualifiers = {
repository_url = "https://github.com/rust-lang/rust-analyzer",
rev = "true",
},
})

assert.is_false(result:is_success())
assert.equals("Unable to retrieve commit SHAs.", result:err_or_nil())
end)
end)

0 comments on commit a09da6a

Please sign in to comment.