From cf06e49bf323e65e3a2c4d45d69660e1fa7b27a1 Mon Sep 17 00:00:00 2001 From: xxf098 Date: Wed, 30 Nov 2022 10:32:10 -0500 Subject: [PATCH] pull default branch --- .github/workflows/workflow.yaml | 4 +-- common/git/git.go | 25 +++++++++++++------ do_test.go | 4 +-- pkg/github.com/xxf098/actionflow/core/git.cue | 2 +- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/.github/workflows/workflow.yaml b/.github/workflows/workflow.yaml index 82d1d54..35a41ed 100644 --- a/.github/workflows/workflow.yaml +++ b/.github/workflows/workflow.yaml @@ -17,8 +17,8 @@ jobs: uses: actions/checkout@v3 - name: Pre run: | - wget -q https://github.com/xxf098/actionflow/releases/download/v0.5.8/flow-linux-amd64-v0.5.8.zip - unzip flow-linux-amd64-v0.5.8.zip + wget -q https://github.com/xxf098/actionflow/releases/download/v0.5.9/flow-linux-amd64-v0.5.9.zip + unzip flow-linux-amd64-v0.5.9.zip rm -rf cue.mod ./flow init && ./flow update ./flow do setup diff --git a/common/git/git.go b/common/git/git.go index 2606669..fe1b8d7 100644 --- a/common/git/git.go +++ b/common/git/git.go @@ -320,13 +320,27 @@ func Clone(ctx context.Context, input GitCloneConfig) error { } // fetch latest changes - fetchOptions, pullOptions := gitOptions(input.Token) + _, pullOptions := gitOptions(input.Token) - err = r.Fetch(&fetchOptions) - if err != nil && !errors.Is(err, git.NoErrAlreadyUpToDate) { + // err = r.Fetch(&fetchOptions) + // if err != nil && !errors.Is(err, git.NoErrAlreadyUpToDate) { + // return err + // } + + var w *git.Worktree + if w, err = r.Worktree(); err != nil { return err } + if len(input.Ref) < 1 { + if err = w.Pull(&pullOptions); err != nil && err != git.NoErrAlreadyUpToDate { + logger.Debugf("Unable to pull %s: %v", refName, err) + return err + } + logger.Debugf("Cloned %s to %s", input.URL, input.Dir) + return nil + } + var hash *plumbing.Hash rev := plumbing.Revision(input.Ref) if hash, err = r.ResolveRevision(rev); err != nil { @@ -363,11 +377,6 @@ func Clone(ctx context.Context, input GitCloneConfig) error { return err } - var w *git.Worktree - if w, err = r.Worktree(); err != nil { - return err - } - // If the hash resolved doesn't match the ref provided in a workflow then we're // using a branch or tag ref, not a sha // diff --git a/do_test.go b/do_test.go index 5f3762c..6de1596 100644 --- a/do_test.go +++ b/do_test.go @@ -82,8 +82,8 @@ func TestGitPull(t *testing.T) { doTest("./testcues/git.cue", "hello") } -func TestCheckout(t *testing.T) { - doTest("./testcues/git.cue", "checkout") +func TestGitCheckout(t *testing.T) { + doTest("./testcues/git.cue", "lite") } func TestWorkDir(t *testing.T) { diff --git a/pkg/github.com/xxf098/actionflow/core/git.cue b/pkg/github.com/xxf098/actionflow/core/git.cue index 9ee6800..1379de5 100644 --- a/pkg/github.com/xxf098/actionflow/core/git.cue +++ b/pkg/github.com/xxf098/actionflow/core/git.cue @@ -4,7 +4,7 @@ package core $dagger: task: _name: "Git" args: [...string] | *[] repo: string | *"" - ref: string | *"HEAD" + ref: string | *"" dir: string | *"" token: string | *"" } \ No newline at end of file