Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add methods to add refspecs and tests to view fetchspecs #21227

Merged
merged 3 commits into from
Mar 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions base/libgit2/remote.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,54 @@ function push_refspecs(rmt::GitRemote)
res
end

"""
add_fetch!(repo::GitRepo, rmt::GitRemote, fetch_spec::String)

Add a *fetch* refspec for the specified `rmt`. This refspec will contain
information about which branch(es) to fetch from.

# Example
```julia
julia> LibGit2.add_fetch!(repo, remote, "upstream");

julia> LibGit2.fetch_refspecs(remote)
String["+refs/heads/*:refs/remotes/upstream/*"]
```
"""
function add_fetch!(repo::GitRepo, rmt::GitRemote, fetch_spec::String)
@check ccall((:git_remote_add_fetch, :libgit2), Cint,
(Ptr{Void}, Cstring, Cstring), repo.ptr,
name(rmt), fetch_spec)
end

"""
add_push!(repo::GitRepo, rmt::GitRemote, push_spec::String)

Add a *push* refspec for the specified `rmt`. This refspec will contain
information about which branch(es) to push to.

# Example
```julia
julia> LibGit2.add_push!(repo, remote, "refs/heads/master");

julia> remote = LibGit2.get(LibGit2.GitRemote, repo, branch);

julia> LibGit2.push_refspecs(remote)
String["refs/heads/master"]
```

!!! note
You may need to [`close`](@ref) and reopen the `GitRemote`
in question after updating its push refspecs in order for
the change to take effect and for calls to [`push`](@ref)
to work.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this is something we could handle behind the scenes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The plan is to get rid of close entirely so ideally soon we won't have to.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

"""
function add_push!(repo::GitRepo, rmt::GitRemote, push_spec::String)
@check ccall((:git_remote_add_push, :libgit2), Cint,
(Ptr{Void}, Cstring, Cstring), repo.ptr,
name(rmt), push_spec)
end

"""
fetch(rmt::GitRemote, refspecs; options::FetchOptions=FetchOptions(), msg="")

Expand All @@ -129,6 +177,13 @@ determine which remote branch(es) to push to.
The keyword arguments are:
* `force`: if `true`, a force-push will occur, disregarding conflicts.
* `options`: determines the options for the push, e.g. which proxy headers to use.

!!! note
You can add information about the push refspecs in two other ways: by setting
an option in the repository's `GitConfig` (with `push.default` as the key) or
by calling [`add_push!`](@ref). Otherwise you will need to explicitly specify
a push refspec in the call to `push` for it to have any effect, like so:
`LibGit2.push(repo, refspecs=["refs/heads/master"])`.
"""
function push(rmt::GitRemote, refspecs::Vector{<:AbstractString};
force::Bool = false, options::PushOptions = PushOptions())
Expand Down
6 changes: 6 additions & 0 deletions test/libgit2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ mktempdir() do dir
LibGit2.set_remote_url(cache_repo, repo_url, remote="upstream")
remote = LibGit2.get(LibGit2.GitRemote, repo, branch)
@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/*"]
LibGit2.add_push!(repo, remote, "refs/heads/master")
close(remote)
remote = LibGit2.get(LibGit2.GitRemote, repo, branch)
@test LibGit2.push_refspecs(remote) == String["refs/heads/master"]
close(remote)

remote = LibGit2.GitRemoteAnon(repo, repo_url)
Expand Down