-
Notifications
You must be signed in to change notification settings - Fork 534
fix Repository.ResolveRevision for branch and tag #660
Changes from all commits
b928b1f
11f9898
f810519
6be54fd
f1edccc
fe263b8
458f0be
eafce48
1aface6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1265,24 +1265,32 @@ func (s *RepositorySuite) TestWorktreeBare(c *C) { | |
} | ||
|
||
func (s *RepositorySuite) TestResolveRevision(c *C) { | ||
url := s.GetLocalRepositoryURL( | ||
fixtures.ByURL("https://github.com/git-fixtures/basic.git").One(), | ||
) | ||
|
||
r, _ := Init(memory.NewStorage(), nil) | ||
err := r.clone(context.Background(), &CloneOptions{URL: url}) | ||
f := fixtures.ByURL("https://github.com/git-fixtures/basic.git").One() | ||
sto, err := filesystem.NewStorage(f.DotGit()) | ||
c.Assert(err, IsNil) | ||
r, err := Open(sto, f.DotGit()) | ||
c.Assert(err, IsNil) | ||
|
||
datas := map[string]string{ | ||
"HEAD": "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", | ||
"refs/heads/master~2^^~": "b029517f6300c2da0f4b651b8642506cd6aaf45d", | ||
"HEAD~2^^~": "b029517f6300c2da0f4b651b8642506cd6aaf45d", | ||
"HEAD~3^2": "a5b8b09e2f8fcb0bb99d3ccb0958157b40890d69", | ||
"HEAD~3^2^0": "a5b8b09e2f8fcb0bb99d3ccb0958157b40890d69", | ||
"HEAD~2^{/binary file}": "35e85108805c84807bc66a02d91535e1e24b38b9", | ||
"HEAD~^{!-some}": "1669dce138d9b841a518c64b10914d88f5e488ea", | ||
"HEAD@{2015-03-31T11:56:18Z}": "918c48b83bd081e863dbe1b80f8998f058cd8294", | ||
"HEAD@{2015-03-31T11:49:00Z}": "1669dce138d9b841a518c64b10914d88f5e488ea", | ||
"HEAD": "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", | ||
"heads/master": "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", | ||
"heads/master~1": "918c48b83bd081e863dbe1b80f8998f058cd8294", | ||
"refs/heads/master": "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", | ||
"refs/heads/master~2^^~": "b029517f6300c2da0f4b651b8642506cd6aaf45d", | ||
"refs/tags/v1.0.0": "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", | ||
"refs/remotes/origin/master": "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", | ||
"refs/remotes/origin/HEAD": "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", | ||
"HEAD~2^^~": "b029517f6300c2da0f4b651b8642506cd6aaf45d", | ||
"HEAD~3^2": "a5b8b09e2f8fcb0bb99d3ccb0958157b40890d69", | ||
"HEAD~3^2^0": "a5b8b09e2f8fcb0bb99d3ccb0958157b40890d69", | ||
"HEAD~2^{/binary file}": "35e85108805c84807bc66a02d91535e1e24b38b9", | ||
"HEAD~^{/!-some}": "1669dce138d9b841a518c64b10914d88f5e488ea", | ||
"master": "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", | ||
"branch": "e8d3ffab552895c19b9fcf7aa264d277cde33881", | ||
"v1.0.0": "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This tag exists here but I can't find it on https://github.com/git-fixtures/basic.git There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extrange... but trust on the fixture. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe you could add it to the original repository ? It's convenient when you need to test on the repository and it will fit what is defined in fixtures. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe, I will check it. |
||
"branch~1": "918c48b83bd081e863dbe1b80f8998f058cd8294", | ||
"v1.0.0~1": "918c48b83bd081e863dbe1b80f8998f058cd8294", | ||
"master~1": "918c48b83bd081e863dbe1b80f8998f058cd8294", | ||
} | ||
|
||
for rev, hash := range datas { | ||
|
@@ -1303,10 +1311,9 @@ func (s *RepositorySuite) TestResolveRevisionWithErrors(c *C) { | |
c.Assert(err, IsNil) | ||
|
||
datas := map[string]string{ | ||
"efs/heads/master~": "reference not found", | ||
"HEAD^3": `Revision invalid : "3" found must be 0, 1 or 2 after "^"`, | ||
"HEAD^{/whatever}": `No commit message match regexp : "whatever"`, | ||
"HEAD@{2015-03-31T09:49:00Z}": `No commit exists prior to date "2015-03-31 09:49:00 +0000 UTC"`, | ||
"efs/heads/master~": "reference not found", | ||
"HEAD^3": `Revision invalid : "3" found must be 0, 1 or 2 after "^"`, | ||
"HEAD^{/whatever}": `No commit message match regexp : "whatever"`, | ||
} | ||
|
||
for rev, rerr := range datas { | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed this part because it's a bad implementation,I misread the spec, it must follows this :
This suffix may only be used immediately following a ref name and the ref must have an existing log ($GIT_DIR/logs/<ref>)
.