aboutsummaryrefslogtreecommitdiffstats
path: root/_examples/revision
diff options
context:
space:
mode:
Diffstat (limited to '_examples/revision')
-rw-r--r--_examples/revision/main.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/_examples/revision/main.go b/_examples/revision/main.go
new file mode 100644
index 0000000..a2389bd
--- /dev/null
+++ b/_examples/revision/main.go
@@ -0,0 +1,32 @@
+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"
+)
+
+// Example how to resolve a revision into its commit counterpart
+func main() {
+ CheckArgs("<path>", "<revision>")
+
+ path := os.Args[1]
+ revision := os.Args[2]
+
+ // We instantiate a new repository targeting the given path (the .git folder)
+ r, err := git.PlainOpen(path)
+ CheckIfError(err)
+
+ // Resolve revision into a sha1 commit, only some revisions are resolved
+ // look at the doc to get more details
+ Info("git rev-parse %s", revision)
+
+ h, err := r.ResolveRevision(plumbing.Revision(revision))
+
+ CheckIfError(err)
+
+ fmt.Println(h.String())
+}