aboutsummaryrefslogtreecommitdiffstats
path: root/_examples/revision
diff options
context:
space:
mode:
authorAnthony HAMON <antham@users.noreply.github.com>2017-12-01 16:27:52 +0100
committerMáximo Cuadros <mcuadros@gmail.com>2017-12-01 16:27:52 +0100
commit44c364fe3b7b8cdc0f9623afe870d6781a97ebb4 (patch)
tree03284e910c75da7c896381b439c04498eabe63db /_examples/revision
parente20d3347d26f0b7193502e2ad7386d7c504b0cde (diff)
downloadgo-git-44c364fe3b7b8cdc0f9623afe870d6781a97ebb4.tar.gz
Fix revision solver for branch and tag (#660)
fix Repository.ResolveRevision for branch and tag
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())
+}