| 1 |
package main |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
"os" |
| 6 |
|
| 7 |
git "gopkg.in/src-d/go-git.v4" |
| 8 |
. "gopkg.in/src-d/go-git.v4/_examples" |
| 9 |
"gopkg.in/src-d/go-git.v4/plumbing/transport/http" |
| 10 |
) |
| 11 |
|
| 12 |
func main() { |
| 13 |
CheckArgs("<url>", "<directory>", "<github_username>", "<github_password>") |
| 14 |
url, directory, username, password := os.Args[1], os.Args[2], os.Args[3], os.Args[4] |
| 15 |
|
| 16 |
// Clone the given repository to the given directory |
| 17 |
Info("git clone %s %s", url, directory) |
| 18 |
|
| 19 |
r, err := git.PlainClone(directory, false, &git.CloneOptions{ |
| 20 |
Auth: &http.BasicAuth{ |
| 21 |
Username: username, |
| 22 |
Password: password, |
| 23 |
}, |
| 24 |
URL: url, |
| 25 |
Progress: os.Stdout, |
| 26 |
}) |
| 27 |
CheckIfError(err) |
| 28 |
|
| 29 |
// ... retrieving the branch being pointed by HEAD |
| 30 |
ref, err := r.Head() |
| 31 |
CheckIfError(err) |
| 32 |
// ... retrieving the commit object |
| 33 |
commit, err := r.CommitObject(ref.Hash()) |
| 34 |
CheckIfError(err) |
| 35 |
|
| 36 |
fmt.Println(commit) |
| 37 |
} |