diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2017-04-12 15:09:57 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2017-04-12 15:09:57 +0200 |
commit | 5bcf802213e801c4d52102612f007defa5d0397f (patch) | |
tree | 9b5dd9ad1665fad8424dfbdc5bd93b531f714b09 /_examples | |
parent | 63f234847bf613b621b3a714d77fc077d88717e6 (diff) | |
download | go-git-5bcf802213e801c4d52102612f007defa5d0397f.tar.gz |
examples: checkout example update
Diffstat (limited to '_examples')
-rw-r--r-- | _examples/checkout/main.go | 26 | ||||
-rw-r--r-- | _examples/common_test.go | 2 |
2 files changed, 20 insertions, 8 deletions
diff --git a/_examples/checkout/main.go b/_examples/checkout/main.go index 24f926a..2c54550 100644 --- a/_examples/checkout/main.go +++ b/_examples/checkout/main.go @@ -11,25 +11,37 @@ import ( // 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] + CheckArgs("<url>", "<directory>", "<commit>") + url, directory, commit := 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) + // ... retrieving the commit being pointed by HEAD + Info("git show-ref --head HEAD") + ref, err := r.Head() + CheckIfError(err) + fmt.Println(ref.Hash()) w, err := r.Worktree() - CheckIfError(err) - CheckIfError(w.Checkout(plumbing.NewHash(commitRef))) + // ... checking out to commit + Info("git checkout %s", commit) + err = w.Checkout(&git.CheckoutOptions{ + Hash: plumbing.NewHash(commit), + }) + CheckIfError(err) - fmt.Println("voila") + // ... retrieving the commit being pointed by HEAD, it's shows that the + // repository is poiting to the giving commit in detached mode + Info("git show-ref --head HEAD") + ref, err = r.Head() + CheckIfError(err) + fmt.Println(ref.Hash()) } diff --git a/_examples/common_test.go b/_examples/common_test.go index d812f2b..5543eaf 100644 --- a/_examples/common_test.go +++ b/_examples/common_test.go @@ -13,7 +13,7 @@ import ( var examplesTest = flag.Bool("examples", false, "run the examples tests") -var defaultURL = "https://github.com/mcuadros/basic.git" +var defaultURL = "https://github.com/git-fixtures/basic.git" var args = map[string][]string{ "checkout": []string{defaultURL, tempFolder(), "35e85108805c84807bc66a02d91535e1e24b38b9"}, |