diff --git a/cmd/wp-git-clone/flags.go b/cmd/wp-git-clone/flags.go index e234e2a..9ed2e8f 100644 --- a/cmd/wp-git-clone/flags.go +++ b/cmd/wp-git-clone/flags.go @@ -53,14 +53,6 @@ func settingsFlags(settings *plugin.Settings, category string) []cli.Flag { Destination: &settings.Repo.CommitRef, Category: category, }, - &cli.StringFlag{ - Name: "event", - Value: "push", - Usage: "pipeline event", - EnvVars: []string{"CI_PIPELINE_EVENT"}, - Destination: &settings.Pipeline.Event, - Category: category, - }, &cli.StringFlag{ Name: "netrc.machine", Usage: "netrc machine", @@ -99,7 +91,7 @@ func settingsFlags(settings *plugin.Settings, category string) []cli.Flag { }, &cli.BoolFlag{ Name: "tags", - Usage: "clone tags, if not explicitly set and event is tag its default is true else false", + Usage: "fetch git tags during clone", EnvVars: []string{"PLUGIN_TAGS"}, Destination: &settings.Tags, Category: category, diff --git a/docs/content/_index.md b/docs/content/_index.md index c2211a6..8b2a657 100644 --- a/docs/content/_index.md +++ b/docs/content/_index.md @@ -56,7 +56,6 @@ docker build --file Containerfile.multiarch --tag thegeeklab/wp-git-clone . ```Shell docker run --rm \ -e CI_REPO_CLONE_URL=https://github.com/octocat/Hello-World.git \ - -e CI_PIPELINE_EVENT=push \ -e CI_COMMIT_SHA=b3cbd5bbd7e81436d2eee04537ea2b4c0cad4cdf \ -e CI_COMMIT_REF=refs/heads/test \ -e CI_WORKSPACE=/tmp/wp_git_testrepo \ diff --git a/docs/data/data.yaml b/docs/data/data.yaml index 182bda6..46c6a08 100644 --- a/docs/data/data.yaml +++ b/docs/data/data.yaml @@ -5,23 +5,6 @@ properties: Change branch name. defaultvalue: "main" - - name: ci_netrc_machine - description: | - Netrc machine. - - - name: ci_netrc_password - description: | - Netrc password. - - - name: ci_netrc_username - description: | - Metrc username. - - - name: ci_pipeline_event - description: | - Pipeline event. - defaultvalue: "push" - - name: commit_ref description: | Git commit ref. @@ -90,8 +73,8 @@ properties: - name: tags description: | - Clone tags, if not explicitly set and event is tag its default is `true` else `false`. - defaultvalue: false + Fetch git tags during clone. + defaultvalue: true - name: use_ssh description: | diff --git a/git/clone.go b/git/clone.go index c4af447..d383084 100644 --- a/git/clone.go +++ b/git/clone.go @@ -8,10 +8,10 @@ import ( // FetchSource fetches the source from remote. func FetchSource(ref string, tags bool, depth int, filter string) *execabs.Cmd { - tagsOption := "--no-tags" + tagsOption := "--tags" - if tags { - tagsOption = "--tags" + if !tags { + tagsOption = "--no-tags" } args := []string{ diff --git a/plugin/impl.go b/plugin/impl.go index 127ca06..33d6ac1 100644 --- a/plugin/impl.go +++ b/plugin/impl.go @@ -59,19 +59,6 @@ func (p *Plugin) Validate() error { } } - if p.Settings.Pipeline.Event == "tag" && !p.Settings.Tags { - // tags clone not explicit set but pipeline is triggered by a tag - // auto set tags cloning to true - p.Settings.Tags = true - } - - if p.Settings.Tags && p.Settings.Partial { - log.Warn().Msg("ignore partial clone as tags are fetched") - - // if tag fetching is enabled per event or setting, disable partial clone - p.Settings.Partial = false - } - if p.Settings.Partial { p.Settings.Depth = 1 p.Settings.Filter = "tree:0" diff --git a/plugin/impl_test.go b/plugin/impl_test.go index 2bec026..0674f05 100644 --- a/plugin/impl_test.go +++ b/plugin/impl_test.go @@ -12,7 +12,6 @@ type testCommit struct { name string path string clone string - event string commit string ref string file string @@ -37,9 +36,6 @@ func TestClone(t *testing.T) { CommitSha: tt.commit, Branch: "main", }, - Pipeline: Pipeline{ - Event: tt.event, - }, Home: "/tmp", WorkDir: filepath.Join(dir, tt.path), Recursive: tt.recursive, @@ -83,9 +79,6 @@ func TestCloneNonEmpty(t *testing.T) { CommitSha: tt.commit, Branch: "main", }, - Pipeline: Pipeline{ - Event: tt.event, - }, Home: "/tmp", WorkDir: filepath.Join(dir, tt.path), Recursive: tt.recursive, @@ -150,7 +143,6 @@ func getCommits() []testCommit { name: "first commit", path: "octocat/Hello-World", clone: "https://github.com/octocat/Hello-World.git", - event: "push", commit: "553c2077f0edc3d5dc5d17262f6aa498e69d6f8e", ref: "refs/heads/master", file: "README", @@ -160,7 +152,6 @@ func getCommits() []testCommit { name: "head commit", path: "octocat/Hello-World", clone: "https://github.com/octocat/Hello-World.git", - event: "push", commit: "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d", ref: "refs/heads/master", file: "README", @@ -170,7 +161,6 @@ func getCommits() []testCommit { name: "pull request commit", path: "octocat/Hello-World", clone: "https://github.com/octocat/Hello-World.git", - event: "pull_request", commit: "762941318ee16e59dabbacb1b4049eec22f0d303", ref: "refs/pull/6/merge", file: "README", @@ -180,7 +170,6 @@ func getCommits() []testCommit { name: "branch", path: "octocat/Hello-World", clone: "https://github.com/octocat/Hello-World.git", - event: "push", commit: "b3cbd5bbd7e81436d2eee04537ea2b4c0cad4cdf", ref: "refs/heads/test", file: "CONTRIBUTING.md", @@ -190,7 +179,6 @@ func getCommits() []testCommit { name: "tags", path: "github/mime-types", clone: "https://github.com/github/mime-types.git", - event: "tag", commit: "bf68d60215a167c935bc5976b7d06a7ffb290926", ref: "refs/tags/v1.17", file: ".gitignore", @@ -200,7 +188,6 @@ func getCommits() []testCommit { name: "submodules", path: "test-assets/woodpecker-git-test-submodule", clone: "https://github.com/test-assets/woodpecker-git-test-submodule.git", - event: "push", commit: "cc020eb6aaa601c13ca7b0d5db9d1ca694e7a003", ref: "refs/heads/main", file: "Hello-World/README", @@ -211,7 +198,6 @@ func getCommits() []testCommit { name: "checkout with ref only", path: "octocat/Hello-World", clone: "https://github.com/octocat/Hello-World.git", - event: "push", // commit: "a11fb45a696bf1d696fc9ab2c733f8f123aa4cf5", ref: "pull/2403/head", file: "README", @@ -222,7 +208,6 @@ func getCommits() []testCommit { name: "checkout with lfs skip", path: "test-assets/woodpecker-git-test-lfs", clone: "https://github.com/test-assets/woodpecker-git-test-lfs.git", - event: "push", commit: "69d4dadb4c2899efb73c0095bb58a6454d133cef", ref: "refs/heads/main", file: "4M.bin", @@ -232,7 +217,6 @@ func getCommits() []testCommit { name: "checkout with lfs", path: "test-assets/woodpecker-git-test-lfs", clone: "https://github.com/test-assets/woodpecker-git-test-lfs.git", - event: "push", commit: "69d4dadb4c2899efb73c0095bb58a6454d133cef", ref: "refs/heads/main", file: "4M.bin", diff --git a/plugin/plugin.go b/plugin/plugin.go index 447c840..35d3cf9 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -16,10 +16,6 @@ type Plugin struct { Settings *Settings } -type Pipeline struct { - Event string -} - type Netrc struct { Machine string Login string @@ -39,9 +35,8 @@ type Settings struct { Home string WorkDir string - Pipeline Pipeline - Netrc Netrc - Repo git.Repository + Netrc Netrc + Repo git.Repository } func New(options wp.Options, settings *Settings) *Plugin {