diff --git a/src/API.jl b/src/API.jl index 506e19aaf8..99179ee09e 100644 --- a/src/API.jl +++ b/src/API.jl @@ -555,12 +555,25 @@ function activate(path::String; shared::Bool=false) end """ - setprotocol!(proto::Union{Nothing, AbstractString}=nothing) + setprotocol!(site::AbstractString, proto::Union{Nothing, AbstractString}=nothing) Set the protocol used to access GitHub-hosted packages when `add`ing a url or `develop`ing a package. Defaults to delegating the choice to the package developer (`proto == nothing`). -Other choices for `proto` are `"https` or `git`. +Other choices for `proto` are `"https"` `"git" or `"ssh"`. """ -setprotocol!(proto::Union{Nothing, AbstractString}=nothing) = GitTools.setprotocol!(proto) +function setprotocol!(site::AbstractString, proto::Union{Nothing, AbstractString}=nothing) + if site in ("https", "ssh", "git") && proto === nothing + Base.depwarn( + "`setprotocol!(proto)` is deprecated, use `setprotocol!(\"github.com\", proto)` instead.", + :setprotocol! + ) + proto = site + site = "github.com" + end + + GitTools.setprotocol!(site, proto) +end + +@deprecate setprotocol!(proto::Nothing=nothing) setprotocol!("github.com", proto) false end # module diff --git a/src/GitTools.jl b/src/GitTools.jl index 70e7eff3a9..6d4478a9ea 100644 --- a/src/GitTools.jl +++ b/src/GitTools.jl @@ -67,13 +67,21 @@ end const GIT_REGEX = r"^(?:(?git|ssh|https)://)?(?:[\w\.\+\-:]+@)?(?.+?)(?()/|:)(?.+?)(?:\.git)?$" -const GIT_PROTOCOL = Dict{AbstractString, Union{Nothing, AbstractString}}() +const GIT_PROTOCOL = Dict{String, Union{Nothing, String}}() -function setprotocol!( - proto::Union{Nothing, AbstractString}=nothing, - site::AbstractString="github.com" -) - GIT_PROTOCOL[site] = proto +@deprecate setprotocol!(proto::Nothing=nothing) setprotocol!("github.com", proto) false + +function setprotocol!(site::AbstractString, proto::Union{Nothing, AbstractString}=nothing) + if site in ("https", "ssh", "git") && proto === nothing + Base.depwarn( + "`setprotocol!(proto)` is deprecated, use `setprotocol!(\"github.com\", proto)` instead.", + :setprotocol! + ) + proto = site + site = "github.com" + end + + GIT_PROTOCOL[lowercase(site)] = proto end function normalize_url(url::AbstractString) @@ -83,7 +91,7 @@ function normalize_url(url::AbstractString) host = m[:hostname] path = "$(m[:path]).git" - proto = get(GIT_PROTOCOL, host, nothing) + proto = get(GIT_PROTOCOL, lowercase(host), nothing) if proto === nothing url diff --git a/src/Pkg.jl b/src/Pkg.jl index ae94448fe3..72e1007ac1 100644 --- a/src/Pkg.jl +++ b/src/Pkg.jl @@ -334,9 +334,9 @@ Below is a comparison between the REPL version and the `PackageSpec` version: const PackageSpec = Types.PackageSpec """ - Pkg.setprotocol!(proto::Union{Nothing, AbstractString}=nothing) + Pkg.setprotocol!(site::AbstractString, proto::Union{Nothing, AbstractString}=nothing) -Set the protocol used to access GitHub-hosted packages when `add`ing a url or `develop`ing a package. +Set the protocol used to access `site`-hosted packages when `add`ing a url or `develop`ing a package. Defaults to 'https', with `proto == nothing` delegating the choice to the package developer. """ const setprotocol! = API.setprotocol! diff --git a/test/pkg.jl b/test/pkg.jl index 866481d38c..e851fbb77b 100644 --- a/test/pkg.jl +++ b/test/pkg.jl @@ -253,13 +253,13 @@ temp_pkg_dir() do project_path mktempdir() do devdir withenv("JULIA_PKG_DEVDIR" => devdir) do try - Pkg.setprotocol!("notarealprotocol") + Pkg.setprotocol!("github.com", "notarealprotocol") @test_throws PkgError Pkg.develop("Example") - Pkg.setprotocol!("https") + Pkg.setprotocol!("github.com", "https") Pkg.develop("Example") @test isinstalled(TEST_PKG) finally - Pkg.setprotocol!() + Pkg.setprotocol!("github.com") end end end @@ -269,7 +269,7 @@ temp_pkg_dir() do project_path https_url = "https://github.com/JuliaLang/Example.jl.git" ssh_url = "ssh://git@github.com/JuliaLang/Example.jl.git" @test Pkg.GitTools.normalize_url(https_url) == https_url - Pkg.setprotocol!("ssh") + Pkg.setprotocol!("github.com", "ssh") @test Pkg.GitTools.normalize_url(https_url) == ssh_url # TODO: figure out how to test this without # having to deploy a ssh key on github @@ -278,14 +278,19 @@ temp_pkg_dir() do project_path https_url = "https://gitlab.example.com/example/Example.jl.git" ssh_url = "ssh://git@gitlab.example.com/example/Example.jl.git" - Pkg.GitTools.setprotocol!(nothing, "gitlab.example.com") + Pkg.setprotocol!("gitlab.example.com") @test Pkg.GitTools.normalize_url(https_url) == https_url - Pkg.GitTools.setprotocol!("ssh", "gitlab.example.com") + Pkg.setprotocol!("gitlab.example.com", "ssh") @test Pkg.GitTools.normalize_url(https_url) == ssh_url + @test_deprecated Pkg.setprotocol!() + @test_deprecated Pkg.setprotocol!("ssh") + @test_deprecated Pkg.GitTools.setprotocol!() + @test_deprecated Pkg.GitTools.setprotocol!("ssh") + finally - Pkg.GitTools.setprotocol!() - Pkg.GitTools.setprotocol!(nothing, "gitlab.example.com") + Pkg.setprotocol!("github.com") + Pkg.setprotocol!("gitlab.example.com") end end end