From 16af66983f63ab205bf8d522eb39793f6cb55f81 Mon Sep 17 00:00:00 2001 From: Filip Pytloun Date: Mon, 13 Oct 2025 15:26:30 +0200 Subject: [PATCH 1/2] fix(git): optimize fetch to selectively include tags and checkout exact refs - Disabled unconditional addition of "remote.origin.tagOpt" config; only add if not fetching exact ref - Introduced exactRef flag to detect when fetching a specific origin ref - When fetching exact ref, checkout uses "FETCH_HEAD" instead of the ref name to avoid detached head advice - Cleaned up commented-out code and improved fetch argument logic accordingly Signed-off-by: Filip Pytloun --- pkg/vendir/fetch/git/git.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pkg/vendir/fetch/git/git.go b/pkg/vendir/fetch/git/git.go index 07883a7f..fee00694 100644 --- a/pkg/vendir/fetch/git/git.go +++ b/pkg/vendir/fetch/git/git.go @@ -166,17 +166,20 @@ func (t *Git) fetch(dstPath string, tempArea ctlfetch.TempArea, bundle string) e } } - argss = append(argss, []string{"config", "remote.origin.tagOpt", "--tags"}) - if bundle != "" { argss = append(argss, []string{"bundle", "unbundle", bundle}) } + exactRef := false { fetchArgs := []string{"fetch", "origin"} if strings.HasPrefix(t.opts.Ref, "origin/") { // only fetch the exact ref we're seeking fetchArgs = append(fetchArgs, t.opts.Ref[7:]) + exactRef = true + } else { + // Only fetch tags if not fetching exact ref + argss = append(argss, []string{"config", "remote.origin.tagOpt", "--tags"}) } if t.opts.Depth > 0 { fetchArgs = append(fetchArgs, "--depth", strconv.Itoa(t.opts.Depth)) @@ -201,7 +204,12 @@ func (t *Git) fetch(dstPath string, tempArea ctlfetch.TempArea, bundle string) e } } - _, _, err = t.cmdRunner.Run([]string{"-c", "advice.detachedHead=false", "checkout", ref}, env, dstPath) + checkoutRef := ref + if exactRef { + checkoutRef = "FETCH_HEAD" + } + + _, _, err = t.cmdRunner.Run([]string{"-c", "advice.detachedHead=false", "checkout", checkoutRef}, env, dstPath) if err != nil { return err } From ae6b2b2ca1f294b7cb038bb4ae5aa43cbc022ee8 Mon Sep 17 00:00:00 2001 From: Cory Dolphin Date: Tue, 9 Dec 2025 23:09:14 -0800 Subject: [PATCH 2/2] Address lint failures Signed-off-by: Cory Dolphin --- pkg/vendir/fetch/git/git.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/vendir/fetch/git/git.go b/pkg/vendir/fetch/git/git.go index fee00694..a538f3d9 100644 --- a/pkg/vendir/fetch/git/git.go +++ b/pkg/vendir/fetch/git/git.go @@ -179,7 +179,10 @@ func (t *Git) fetch(dstPath string, tempArea ctlfetch.TempArea, bundle string) e exactRef = true } else { // Only fetch tags if not fetching exact ref - argss = append(argss, []string{"config", "remote.origin.tagOpt", "--tags"}) + argss = append( + argss, + []string{"config", "remote.origin.tagOpt", "--tags"}, + ) } if t.opts.Depth > 0 { fetchArgs = append(fetchArgs, "--depth", strconv.Itoa(t.opts.Depth)) @@ -209,7 +212,11 @@ func (t *Git) fetch(dstPath string, tempArea ctlfetch.TempArea, bundle string) e checkoutRef = "FETCH_HEAD" } - _, _, err = t.cmdRunner.Run([]string{"-c", "advice.detachedHead=false", "checkout", checkoutRef}, env, dstPath) + _, _, err = t.cmdRunner.Run( + []string{"-c", "advice.detachedHead=false", "checkout", checkoutRef}, + env, + dstPath, + ) if err != nil { return err }