| 1 |
package main |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
"os" |
| 6 |
|
| 7 |
"gopkg.in/src-d/go-git.v4" |
| 8 |
. "gopkg.in/src-d/go-git.v4/_examples" |
| 9 |
"gopkg.in/src-d/go-git.v4/plumbing" |
| 10 |
) |
| 11 |
|
| 12 |
// Example how to resolve a revision into its commit counterpart |
| 13 |
func main() { |
| 14 |
CheckArgs("<path>", "<revision>") |
| 15 |
|
| 16 |
path := os.Args[1] |
| 17 |
revision := os.Args[2] |
| 18 |
|
| 19 |
// We instantiate a new repository targeting the given path (the .git folder) |
| 20 |
r, err := git.PlainOpen(path) |
| 21 |
CheckIfError(err) |
| 22 |
|
| 23 |
// Resolve revision into a sha1 commit, only some revisions are resolved |
| 24 |
// look at the doc to get more details |
| 25 |
Info("git rev-parse %s", revision) |
| 26 |
|
| 27 |
h, err := r.ResolveRevision(plumbing.Revision(revision)) |
| 28 |
|
| 29 |
CheckIfError(err) |
| 30 |
|
| 31 |
fmt.Println(h.String()) |
| 32 |
} |