From 14c06ee5e4c854f396b4925df5b00054fea744e5 Mon Sep 17 00:00:00 2001 From: Shin Uozumi <7904748+sinozu@users.noreply.github.com> Date: Wed, 24 Feb 2021 02:50:28 +0900 Subject: [PATCH] enable to resolve commit hash in `uses` (#530) Co-authored-by: sinozu Co-authored-by: Casey Lee --- pkg/common/git.go | 10 ++++++++-- pkg/common/git_test.go | 5 +++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/pkg/common/git.go b/pkg/common/git.go index 09292b26..982eec4f 100644 --- a/pkg/common/git.go +++ b/pkg/common/git.go @@ -244,8 +244,14 @@ func NewGitCloneExecutor(input NewGitCloneExecutorInput) Executor { refType := "tag" rev := plumbing.Revision(path.Join("refs", "tags", input.Ref)) if _, err := r.Tag(input.Ref); errors.Is(err, git.ErrTagNotFound) { - refType = "branch" - rev = plumbing.Revision(path.Join("refs", "remotes", "origin", input.Ref)) + rName := plumbing.ReferenceName(path.Join("refs", "remotes", "origin", input.Ref)) + if _, err := r.Reference(rName, false); errors.Is(err, plumbing.ErrReferenceNotFound) { + refType = "sha" + rev = plumbing.Revision(input.Ref) + } else { + refType = "branch" + rev = plumbing.Revision(rName) + } } hash, err := r.ResolveRevision(rev) if err != nil { diff --git a/pkg/common/git_test.go b/pkg/common/git_test.go index e09004b0..d4b7698f 100644 --- a/pkg/common/git_test.go +++ b/pkg/common/git_test.go @@ -186,6 +186,11 @@ func TestGitCloneExecutor(t *testing.T) { Ref: "act-fails", Err: nil, }, + "sha": { + URL: "https://github.com/actions/checkout", + Ref: "5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f", // v2 + Err: nil, + }, } { tt := tt name := name