Skip to content

Commit

Permalink
resolve issue with reference a branch on a github action
Browse files Browse the repository at this point in the history
  • Loading branch information
cplee committed Jan 15, 2019
1 parent c668a41 commit 44e21b1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions actions/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func TestParseImageGithub(t *testing.T) {
{"nektos/act/foo", "https://github.com/nektos/act", "master", "foo", true},
{"nektos/act@xxxxx", "https://github.com/nektos/act", "xxxxx", ".", true},
{"nektos/act/bar/baz@zzzzz", "https://github.com/nektos/act", "zzzzz", "bar/baz", true},
{"assimovt/actions-github-deploy/github-deploy@deployment-status-metadata", "https://github.com/assimovt/actions-github-deploy", "deployment-status-metadata", "github-deploy", true},
{"nektos/zzzzundefinedzzzz", "", "", "", false},
}

Expand Down
13 changes: 9 additions & 4 deletions common/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,14 @@ func NewGitCloneExecutor(input NewGitCloneExecutorInput) Executor {
cloneLock.Lock()
defer cloneLock.Unlock()

refName := plumbing.ReferenceName(fmt.Sprintf("refs/heads/%s", input.Ref))

r, err := git.PlainOpen(input.Dir)
if err != nil {
r, err = git.PlainClone(input.Dir, false, &git.CloneOptions{
URL: input.URL.String(),
Progress: input.Logger.WriterLevel(log.DebugLevel),
URL: input.URL.String(),
Progress: input.Logger.WriterLevel(log.DebugLevel),
ReferenceName: refName,
})
if err != nil {
return err
Expand All @@ -206,10 +209,12 @@ func NewGitCloneExecutor(input NewGitCloneExecutorInput) Executor {

err = w.Checkout(&git.CheckoutOptions{
//Branch: plumbing.NewHash(ref),
Hash: plumbing.NewHash(input.Ref),
Branch: refName,
//Hash: plumbing.NewHash(input.Ref),
Force: true,
})
if err != nil {
input.Logger.Error(err)
input.Logger.Errorf("Unable to checkout %s: %v", refName, err)
return err
}

Expand Down

0 comments on commit 44e21b1

Please sign in to comment.