diff options
author | Anthony HAMON <antham@users.noreply.github.com> | 2017-12-01 16:27:52 +0100 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2017-12-01 16:27:52 +0100 |
commit | 44c364fe3b7b8cdc0f9623afe870d6781a97ebb4 (patch) | |
tree | 03284e910c75da7c896381b439c04498eabe63db /_examples | |
parent | e20d3347d26f0b7193502e2ad7386d7c504b0cde (diff) | |
download | go-git-44c364fe3b7b8cdc0f9623afe870d6781a97ebb4.tar.gz |
Fix revision solver for branch and tag (#660)
fix Repository.ResolveRevision for branch and tag
Diffstat (limited to '_examples')
-rw-r--r-- | _examples/README.md | 7 | ||||
-rw-r--r-- | _examples/common.go | 2 | ||||
-rw-r--r-- | _examples/common_test.go | 1 | ||||
-rw-r--r-- | _examples/revision/main.go | 32 |
4 files changed, 38 insertions, 4 deletions
diff --git a/_examples/README.md b/_examples/README.md index 10594ab..271379b 100644 --- a/_examples/README.md +++ b/_examples/README.md @@ -11,9 +11,10 @@ Here you can find a list of annotated _go-git_ examples: - [remotes](remotes/main.go) - Working with remotes: adding, removing, etc - [progress](progress/main.go) - Printing the progress information from the sideband - [push](push/main.go) - Push repository to default remote (origin) -- [checkout](checkout/main.go) - check out a specific commit from a repository -- [tag](tag/main.go) - list/print repository tags -- [pull](pull/main.go) - pull changes from a remote repository +- [checkout](checkout/main.go) - Check out a specific commit from a repository +- [tag](tag/main.go) - List/print repository tags +- [pull](pull/main.go) - Pull changes from a remote repository +- [revision](revision/main.go) - Solve a revision into a commit ### Advanced - [custom_http](custom_http/main.go) - Replacing the HTTP client using a custom one - [storage](storage/README.md) - Implementing a custom storage system diff --git a/_examples/common.go b/_examples/common.go index 2719c0e..81ed647 100644 --- a/_examples/common.go +++ b/_examples/common.go @@ -6,7 +6,7 @@ import ( "strings" ) -// CheckArgs should be used to esnure the right command line arguments are +// CheckArgs should be used to ensure the right command line arguments are // passed before executing an example. func CheckArgs(arg ...string) { if len(os.Args) < len(arg)+1 { diff --git a/_examples/common_test.go b/_examples/common_test.go index d164297..6f8df45 100644 --- a/_examples/common_test.go +++ b/_examples/common_test.go @@ -23,6 +23,7 @@ var args = map[string][]string{ "open": {cloneRepository(defaultURL, tempFolder())}, "progress": {defaultURL, tempFolder()}, "push": {setEmptyRemote(cloneRepository(defaultURL, tempFolder()))}, + "revision": {cloneRepository(defaultURL, tempFolder()), "master~2^"}, "showcase": {defaultURL, tempFolder()}, "tag": {cloneRepository(defaultURL, tempFolder())}, "pull": {createRepositoryWithRemote(tempFolder(), defaultURL)}, 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()) +} |