diff options
Diffstat (limited to '_examples/checkout')
-rw-r--r-- | _examples/checkout/main.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/_examples/checkout/main.go b/_examples/checkout/main.go new file mode 100644 index 0000000..24f926a --- /dev/null +++ b/_examples/checkout/main.go @@ -0,0 +1,35 @@ +package main + +import ( + "fmt" + "os" + + "gopkg.in/src-d/go-git.v4" + . "gopkg.in/src-d/go-git.v4/_examples" + "gopkg.in/src-d/go-git.v4/plumbing" +) + +// Basic example of how to checkout a specific commit. +func main() { + CheckArgs("<url>", "<directory>", "<commit-ref>") + url, directory, commitRef := os.Args[1], os.Args[2], os.Args[3] + + // Clone the given repository to the given directory + Info("git clone %s %s", url, directory) + + r, err := git.PlainClone(directory, false, &git.CloneOptions{ + URL: url, + }) + + CheckIfError(err) + + Info("git checkout %s", commitRef) + + w, err := r.Worktree() + + CheckIfError(err) + + CheckIfError(w.Checkout(plumbing.NewHash(commitRef))) + + fmt.Println("voila") +} |