fix: use special step to retrieve tags and suppress output

This commit is contained in:
Robert Kaussow 2023-12-23 22:54:17 +01:00
parent d93763eccd
commit b83b48bed6
Signed by: xoxys
GPG Key ID: 4E692A2EAECC03C0
3 changed files with 26 additions and 16 deletions

View File

@ -7,16 +7,9 @@ import (
) )
// FetchSource fetches the source from remote. // FetchSource fetches the source from remote.
func FetchSource(ref string, tags bool, depth int, filter string) *execabs.Cmd { func FetchSource(ref string, depth int, filter string) *execabs.Cmd {
tagsOption := "--tags"
if !tags {
tagsOption = "--no-tags"
}
args := []string{ args := []string{
"fetch", "fetch",
tagsOption,
} }
if depth != 0 { 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. // FetchLFS fetches lfs.
func FetchLFS() *execabs.Cmd { func FetchLFS() *execabs.Cmd {
args := []string{ args := []string{
@ -53,7 +61,8 @@ func FetchLFS() *execabs.Cmd {
func CheckoutHead() *execabs.Cmd { func CheckoutHead() *execabs.Cmd {
args := []string{ args := []string{
"checkout", "checkout",
"-qf", "--force",
"--quiet",
"FETCH_HEAD", "FETCH_HEAD",
} }
@ -68,7 +77,7 @@ func CheckoutSha(repo Repository) *execabs.Cmd {
args := []string{ args := []string{
"reset", "reset",
"--hard", "--hard",
"-q", "--quiet",
repo.CommitSha, repo.CommitSha,
} }

View File

@ -19,7 +19,6 @@ func TestFetch(t *testing.T) {
[]string{ []string{
"/usr/bin/git", "/usr/bin/git",
"fetch", "fetch",
"--no-tags",
"origin", "origin",
"+refs/heads/master:", "+refs/heads/master:",
}, },
@ -31,7 +30,6 @@ func TestFetch(t *testing.T) {
[]string{ []string{
"/usr/bin/git", "/usr/bin/git",
"fetch", "fetch",
"--no-tags",
"--depth=50", "--depth=50",
"origin", "origin",
"+refs/heads/master:", "+refs/heads/master:",
@ -44,7 +42,6 @@ func TestFetch(t *testing.T) {
[]string{ []string{
"/usr/bin/git", "/usr/bin/git",
"fetch", "fetch",
"--tags",
"--depth=100", "--depth=100",
"origin", "origin",
"+refs/heads/master:", "+refs/heads/master:",
@ -52,7 +49,7 @@ func TestFetch(t *testing.T) {
}, },
} }
for _, td := range testdata { 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) { if len(c.Args) != len(td.exp) {
t.Errorf("Expected: %s, got %s", td.exp, c.Args) t.Errorf("Expected: %s, got %s", td.exp, c.Args)
} }

View File

@ -110,13 +110,17 @@ func (p *Plugin) Execute() error {
// fetch and checkout by ref // fetch and checkout by ref
log.Info().Msg("no commit information: using head checkout") 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()) cmds = append(cmds, git.CheckoutHead())
} else { } 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)) 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 { for name, submoduleURL := range p.Settings.Repo.Submodules {
cmds = append(cmds, git.ConfigRemapSubmodule(name, submoduleURL)) cmds = append(cmds, git.ConfigRemapSubmodule(name, submoduleURL))
} }