Skip to content

Commit

Permalink
Fixes arg order and adds deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
morris25 committed Nov 19, 2018
1 parent 6adfe07 commit 71e65a6
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 20 deletions.
19 changes: 16 additions & 3 deletions src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 15 additions & 7 deletions src/GitTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,21 @@ end

const GIT_REGEX =
r"^(?:(?<proto>git|ssh|https)://)?(?:[\w\.\+\-:]+@)?(?<hostname>.+?)(?(<proto>)/|:)(?<path>.+?)(?:\.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)
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Pkg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
21 changes: 13 additions & 8 deletions test/pkg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 71e65a6

Please sign in to comment.