Skip to content

Commit

Permalink
Fix issue #21773
Browse files Browse the repository at this point in the history
When using `LibGit2.set_remote_url` to specify a GitHub HTTP URL only
the fetch URL would be modified to use HTTP and the push URL would
always be set to SSH.

(cherry picked from commit d4a43e4)
partial backport of #22062
  • Loading branch information
omus authored and tkelman committed Jun 17, 2017
1 parent ad290e9 commit 716cf02
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
9 changes: 1 addition & 8 deletions base/libgit2/libgit2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,7 @@ LibGit2.set_remote_url(repo_path, url2, remote="upstream2")
function set_remote_url(repo::GitRepo, url::AbstractString; remote::AbstractString="origin")
with(GitConfig, repo) do cfg
set!(cfg, "remote.$remote.url", url)

m = match(GITHUB_REGEX,url)
if m !== nothing
push = "git@github.com:$(m.captures[1]).git"
if push != url
set!(cfg, "remote.$remote.pushurl", push)
end
end
set!(cfg, "remote.$remote.pushurl", url)
end
end

Expand Down
17 changes: 14 additions & 3 deletions base/libgit2/remote.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,18 @@ end
"""
url(rmt::GitRemote)
Get the URL of a remote git repository.
Get the fetch URL of a remote git repository.
# Example
```julia-repl
julia> repo_url = "https://github.com/JuliaLang/Example.jl";
julia> repo = LibGit2.clone(cache_repo, "test_directory");
julia> repo = LibGit2.init(mktempdir());
julia> remote = LibGit2.GitRemote(repo, "origin", repo_url);
julia> url(remote)
julia> LibGit2.url(remote)
"https://github.com/JuliaLang/Example.jl"
```
"""
Expand All @@ -95,6 +95,17 @@ function url(rmt::GitRemote)
return unsafe_string(url_ptr)
end

"""
push_url(rmt::GitRemote)
Get the push URL of a remote git repository.
"""
function push_url(rmt::GitRemote)
url_ptr = ccall((:git_remote_pushurl, :libgit2), Cstring, (Ptr{Void},), rmt.ptr)
url_ptr == C_NULL && return ""
return unsafe_string(url_ptr)
end

"""
name(rmt::GitRemote)
Expand Down
6 changes: 6 additions & 0 deletions test/libgit2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -252,16 +252,21 @@ mktempdir() do dir

remote = LibGit2.get(LibGit2.GitRemote, repo, branch)
@test LibGit2.url(remote) == repo_url
@test LibGit2.push_url(remote) == ""
@test LibGit2.name(remote) == "upstream"
@test isa(remote, LibGit2.GitRemote)
@test sprint(show, remote) == "GitRemote:\nRemote name: upstream url: $repo_url"
@test LibGit2.isattached(repo)
LibGit2.set_remote_url(repo, "", remote="upstream")
remote = LibGit2.get(LibGit2.GitRemote, repo, branch)
@test LibGit2.url(remote) == ""
@test LibGit2.push_url(remote) == ""
@test sprint(show, remote) == "GitRemote:\nRemote name: upstream url: "
close(remote)
LibGit2.set_remote_url(cache_repo, repo_url, remote="upstream")
remote = LibGit2.get(LibGit2.GitRemote, repo, branch)
@test LibGit2.url(remote) == repo_url
@test LibGit2.push_url(remote) == repo_url
@test sprint(show, remote) == "GitRemote:\nRemote name: upstream url: $repo_url"
LibGit2.add_fetch!(repo, remote, "upstream")
@test LibGit2.fetch_refspecs(remote) == String["+refs/heads/*:refs/remotes/upstream/*"]
Expand All @@ -278,6 +283,7 @@ mktempdir() do dir

remote = LibGit2.GitRemoteAnon(repo, repo_url)
@test LibGit2.url(remote) == repo_url
@test LibGit2.push_url(remote) == ""
@test LibGit2.name(remote) == ""
@test isa(remote, LibGit2.GitRemote)
close(remote)
Expand Down

0 comments on commit 716cf02

Please sign in to comment.