aboutsummaryrefslogtreecommitdiffstats
path: root/_examples
diff options
context:
space:
mode:
Diffstat (limited to '_examples')
-rw-r--r--_examples/checkout/main.go26
-rw-r--r--_examples/common_test.go2
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"},