From b83b48bed663c8c42eb3cfe36575fe3c482856d0 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Sat, 23 Dec 2023 22:54:17 +0100 Subject: [PATCH] fix: use special step to retrieve tags and suppress output --- git/clone.go | 29 +++++++++++++++++++---------- git/clone_test.go | 5 +---- plugin/impl.go | 8 ++++++-- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/git/clone.go b/git/clone.go index d383084..981fbe2 100644 --- a/git/clone.go +++ b/git/clone.go @@ -7,16 +7,9 @@ import ( ) // FetchSource fetches the source from remote. -func FetchSource(ref string, tags bool, depth int, filter string) *execabs.Cmd { - tagsOption := "--tags" - - if !tags { - tagsOption = "--no-tags" - } - +func FetchSource(ref string, depth int, filter string) *execabs.Cmd { args := []string{ "fetch", - tagsOption, } if depth != 0 { @@ -36,6 +29,21 @@ func FetchSource(ref string, tags bool, depth int, filter string) *execabs.Cmd { ) } +// FetchTags fetches the source from remote. +func FetchTags() *execabs.Cmd { + args := []string{ + "fetch", + "--tags", + "--quiet", + "origin", + } + + return execabs.Command( + gitBin, + args..., + ) +} + // FetchLFS fetches lfs. func FetchLFS() *execabs.Cmd { args := []string{ @@ -53,7 +61,8 @@ func FetchLFS() *execabs.Cmd { func CheckoutHead() *execabs.Cmd { args := []string{ "checkout", - "-qf", + "--force", + "--quiet", "FETCH_HEAD", } @@ -68,7 +77,7 @@ func CheckoutSha(repo Repository) *execabs.Cmd { args := []string{ "reset", "--hard", - "-q", + "--quiet", repo.CommitSha, } diff --git a/git/clone_test.go b/git/clone_test.go index ae2fe8d..d46823f 100644 --- a/git/clone_test.go +++ b/git/clone_test.go @@ -19,7 +19,6 @@ func TestFetch(t *testing.T) { []string{ "/usr/bin/git", "fetch", - "--no-tags", "origin", "+refs/heads/master:", }, @@ -31,7 +30,6 @@ func TestFetch(t *testing.T) { []string{ "/usr/bin/git", "fetch", - "--no-tags", "--depth=50", "origin", "+refs/heads/master:", @@ -44,7 +42,6 @@ func TestFetch(t *testing.T) { []string{ "/usr/bin/git", "fetch", - "--tags", "--depth=100", "origin", "+refs/heads/master:", @@ -52,7 +49,7 @@ func TestFetch(t *testing.T) { }, } for _, td := range testdata { - c := FetchSource(td.ref, td.tags, td.depth, "") + c := FetchSource(td.ref, td.depth, "") if len(c.Args) != len(td.exp) { t.Errorf("Expected: %s, got %s", td.exp, c.Args) } diff --git a/plugin/impl.go b/plugin/impl.go index 33d6ac1..df99ef8 100644 --- a/plugin/impl.go +++ b/plugin/impl.go @@ -110,13 +110,17 @@ func (p *Plugin) Execute() error { // fetch and checkout by ref log.Info().Msg("no commit information: using head checkout") - cmds = append(cmds, git.FetchSource(p.Settings.Repo.CommitRef, p.Settings.Tags, p.Settings.Depth, p.Settings.Filter)) + cmds = append(cmds, git.FetchSource(p.Settings.Repo.CommitRef, p.Settings.Depth, p.Settings.Filter)) cmds = append(cmds, git.CheckoutHead()) } else { - cmds = append(cmds, git.FetchSource(p.Settings.Repo.CommitSha, p.Settings.Tags, p.Settings.Depth, p.Settings.Filter)) + cmds = append(cmds, git.FetchSource(p.Settings.Repo.CommitSha, p.Settings.Depth, p.Settings.Filter)) cmds = append(cmds, git.CheckoutSha(p.Settings.Repo)) } + if p.Settings.Tags { + cmds = append(cmds, git.FetchTags()) + } + for name, submoduleURL := range p.Settings.Repo.Submodules { cmds = append(cmds, git.ConfigRemapSubmodule(name, submoduleURL)) }