Clone directly from the pull request reference (pull/refs/)? #1067
harkiratsm
started this conversation in
General
Replies: 1 comment
-
package main
import (
"fmt"
"os"
"strconv"
"github.com/go-git/go-git/v5"
. "github.com/go-git/go-git/v5/_examples"
"github.com/go-git/go-git/v5/config"
"github.com/go-git/go-git/v5/plumbing"
)
func main() {
CheckArgs("<url>", "<PR>", "<directory>")
url := os.Args[1]
pr, err := strconv.Atoi(os.Args[2])
CheckIfError(err)
directory := os.Args[3]
r, err := git.PlainInit(directory, false)
CheckIfError(err)
r.CreateRemote(&config.RemoteConfig{Name: "origin", URLs: []string{url}})
err = r.Fetch(&git.FetchOptions{
RefSpecs: []config.RefSpec{
config.RefSpec(fmt.Sprintf("+refs/pull/%[1]d/head:refs/pull/%[1]d/head", pr)),
},
})
CheckIfError(err)
ref, err := r.Reference(plumbing.ReferenceName(fmt.Sprintf("refs/pull/%d/head", pr)), true)
CheckIfError(err)
// ... retrieving the commit object
commit, err := r.CommitObject(ref.Hash())
CheckIfError(err)
fmt.Println(commit)
} The code above is based on the existing
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is it possible to directly clone a specific pull request reference instead of following the conventional approach of cloning, fetching, and then checking out? In other words, can we clone directly from the pull request reference (pull/refs/)?
Beta Was this translation helpful? Give feedback.
All reactions