| 1 |
package main |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
"os" |
| 6 |
|
| 7 |
"gopkg.in/src-d/go-git.v4" |
| 8 |
. "gopkg.in/src-d/go-git.v4/_examples" |
| 9 |
) |
| 10 |
|
| 11 |
// Basic example of how to clone a repository using clone options. |
| 12 |
func main() { |
| 13 |
CheckArgs("<url>", "<directory>") |
| 14 |
url := os.Args[1] |
| 15 |
directory := os.Args[2] |
| 16 |
|
| 17 |
// Clone the given repository to the given directory |
| 18 |
Info("git clone %s %s --recursive", url, directory) |
| 19 |
|
| 20 |
r, err := git.PlainClone(directory, false, &git.CloneOptions{ |
| 21 |
URL: url, |
| 22 |
RecurseSubmodules: git.DefaultSubmoduleRecursionDepth, |
| 23 |
}) |
| 24 |
|
| 25 |
CheckIfError(err) |
| 26 |
|
| 27 |
// ... retrieving the branch being pointed by HEAD |
| 28 |
ref, err := r.Head() |
| 29 |
CheckIfError(err) |
| 30 |
// ... retrieving the commit object |
| 31 |
commit, err := r.CommitObject(ref.Hash()) |
| 32 |
CheckIfError(err) |
| 33 |
|
| 34 |
fmt.Println(commit) |
| 35 |
} |