blob: 754558c7657df9be7f659ac4d8c038d08c80a49a [file] [log] [blame]
package main
import (
"fmt"
"os"
git "gopkg.in/src-d/go-git.v4"
. "gopkg.in/src-d/go-git.v4/_examples"
"gopkg.in/src-d/go-git.v4/plumbing/transport/http"
)
func main() {
CheckArgs("<url>", "<directory>", "<github_username>", "<github_password>")
url, directory, username, password := os.Args[1], os.Args[2], os.Args[3], os.Args[4]
// Clone the given repository to the given directory
Info("git clone %s %s", url, directory)
r, err := git.PlainClone(directory, false, &git.CloneOptions{
Auth: &http.BasicAuth{
Username: username,
Password: password,
},
URL: url,
Progress: os.Stdout,
})
CheckIfError(err)
// ... retrieving the branch being pointed by HEAD
ref, err := r.Head()
CheckIfError(err)
// ... retrieving the commit object
commit, err := r.CommitObject(ref.Hash())
CheckIfError(err)
fmt.Println(commit)
}