Skip to content

Commit

Permalink
added push, transitioned pull_request
Browse files Browse the repository at this point in the history
  • Loading branch information
wildart committed May 19, 2015
1 parent 6d32dd3 commit 10129bd
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 19 deletions.
40 changes: 25 additions & 15 deletions base/pkg/entry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -323,21 +323,31 @@ function update(branch::AbstractString)
end

function pull_request(dir::AbstractString, commit::AbstractString="", url::AbstractString="")
commit = isempty(commit) ? Git.head(dir=dir) :
Git.readchomp(`rev-parse --verify $commit`, dir=dir)
isempty(url) && (url = Git.readchomp(`config remote.origin.url`, dir=dir))
m = match(Git.GITHUB_REGEX, url)
m == nothing && throw(PkgError("not a GitHub repo URL, can't make a pull request: $url"))
owner, repo = m.captures[2:3]
user = GitHub.user()
info("Forking $owner/$repo to $user")
response = GitHub.fork(owner,repo)
fork = response["ssh_url"]
branch = "pull-request/$(commit[1:8])"
info("Pushing changes as branch $branch")
Git.run(`push -q $fork $commit:refs/heads/$branch`, dir=dir)
pr_url = "$(response["html_url"])/compare/$branch"
@osx? run(`open $pr_url`) : info("To create a pull-request, open:\n\n $pr_url\n")
with(GitRepo, dir) do repo
if isempty(commit)
commit = string(LibGit2.head_oid(repo))
else
!LibGit2.iscommit(commit, repo) && throw(PkgError("Cannot find pull commit: $commit"))
end
if isempty(url)
with(GitConfig, repo) do cfg
url = LibGit2.get(cfg, "remote.origin.url", "")
end
end

m = match(LibGit2.GITHUB_REGEX, url)
m == nothing && throw(PkgError("not a GitHub repo URL, can't make a pull request: $url"))
owner, repo = m.captures[2:3]
user = GitHub.user()
info("Forking $owner/$repo to $user")
response = GitHub.fork(owner,repo)
fork = response["ssh_url"]
branch = "pull-request/$(commit[1:8])"
info("Pushing changes as branch $branch")
LibGit2.push(repo, fork, "$commit:refs/heads/$branch")
pr_url = "$(response["html_url"])/compare/$branch"
@osx? run(`open $pr_url`) : info("To create a pull-request, open:\n\n $pr_url\n")
end
end

function submit(pkg::AbstractString, commit::AbstractString="")
Expand Down
11 changes: 11 additions & 0 deletions base/pkg/libgit2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

module LibGit2

import ...Pkg.PkgError

export with, with_warn
export GitRepo, GitConfig, GitIndex

Expand Down Expand Up @@ -345,6 +347,15 @@ function cat{T<:GitObject}(repo::GitRepo, ::Type{T}, object::AbstractString)
end
end

""" git push <url> [<refspecs>]"""
function push(repo::GitRepo, url::AbstractString, refspecs::AbstractString="")
with(GitRemoteAnon(repo, url, refspecs)) do rmt
with(default_signature(repo)) do sig
push(rmt, sig)
end
end
end

""" Returns all commit authors """
function authors(repo::GitRepo)
athrs = map(
Expand Down
13 changes: 13 additions & 0 deletions base/pkg/libgit2/remote.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,16 @@ function url(rmt::GitRemote)
url_ptr == C_NULL && return ""
return bytestring(url_ptr)
end

function push(rmt::GitRemote, sig::GitSignature, refspecs::AbstractString="";
msg::AbstractString="")
push_opts = PushOptionsStruct()
!isempty(refspecs) && (sa = StrArrayStruct(pathspecs...))
try
@check ccall((:git_remote_push, :libgit2), Cint,
(Ptr{Void}, Ptr{StrArrayStruct}, Ptr{PushOptionsStruct}, Ptr{Void}, Ptr{UInt8}),
rmt.ptr, !isempty(refspecs) ? Ref(sa) : C_NULL, Ref(push_opts), sig.ptr, isempty(msg) ? C_NULL : msg)
finally
!isempty(refspecs) && finalize(sa)
end
end
5 changes: 1 addition & 4 deletions base/pkg/libgit2/repository.jl
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,12 @@ function fetch(repo::GitRepo, rmt::GitRemote; msg::AbstractString="")
end

function reset!(repo::GitRepo, obj::Nullable{GitAnyObject}, pathspecs::AbstractString...)
sa = StrArrayStruct(pathspecs...)
try
with(StrArrayStruct(pathspecs...)) do sa
@check ccall((:git_reset_default, :libgit2), Cint,
(Ptr{Void}, Ptr{Void}, Ptr{StrArrayStruct}),
repo.ptr,
isnull(obj) ? C_NULL: Base.get(obj).ptr,
Ref(sa))
finally
finalize(sa)
end
end

Expand Down
6 changes: 6 additions & 0 deletions base/pkg/libgit2/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ MergeOptionsStruct(; flags::Cint = Cint(0),
file_favor
)

immutable PushOptionsStruct
version::Cuint
parallelism::Cint
end
PushOptionsStruct() = PushOptionsStruct(one(Cuint),one(Cuint))

immutable IndexTime
seconds::Int64
nanoseconds::Cuint
Expand Down

0 comments on commit 10129bd

Please sign in to comment.