From 10129bd4211423a79e261d4d0ce58af159c0b2af Mon Sep 17 00:00:00 2001 From: Art Wild Date: Tue, 19 May 2015 19:29:22 -0400 Subject: [PATCH] added `push`, transitioned `pull_request` --- base/pkg/entry.jl | 40 +++++++++++++++++++++------------- base/pkg/libgit2.jl | 11 ++++++++++ base/pkg/libgit2/remote.jl | 13 +++++++++++ base/pkg/libgit2/repository.jl | 5 +---- base/pkg/libgit2/types.jl | 6 +++++ 5 files changed, 56 insertions(+), 19 deletions(-) diff --git a/base/pkg/entry.jl b/base/pkg/entry.jl index 27c4094f57207..ceaa896b784da 100644 --- a/base/pkg/entry.jl +++ b/base/pkg/entry.jl @@ -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="") diff --git a/base/pkg/libgit2.jl b/base/pkg/libgit2.jl index 315ac5fa90fe2..761edee4fc0e5 100644 --- a/base/pkg/libgit2.jl +++ b/base/pkg/libgit2.jl @@ -2,6 +2,8 @@ module LibGit2 +import ...Pkg.PkgError + export with, with_warn export GitRepo, GitConfig, GitIndex @@ -345,6 +347,15 @@ function cat{T<:GitObject}(repo::GitRepo, ::Type{T}, object::AbstractString) end end +""" git push []""" +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( diff --git a/base/pkg/libgit2/remote.jl b/base/pkg/libgit2/remote.jl index 6a82056f7aabd..194b9a93743b6 100644 --- a/base/pkg/libgit2/remote.jl +++ b/base/pkg/libgit2/remote.jl @@ -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 diff --git a/base/pkg/libgit2/repository.jl b/base/pkg/libgit2/repository.jl index bbea90db1d3c9..2a4383a81fbd3 100644 --- a/base/pkg/libgit2/repository.jl +++ b/base/pkg/libgit2/repository.jl @@ -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 diff --git a/base/pkg/libgit2/types.jl b/base/pkg/libgit2/types.jl index 892dac4aed62d..a07ea16c75f94 100644 --- a/base/pkg/libgit2/types.jl +++ b/base/pkg/libgit2/types.jl @@ -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