From e34616574fe307321a9f82c55d00570f3f474d5c Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 16 Jul 2025 16:19:44 +0200 Subject: [PATCH] fix linting issues Signed-off-by: Sebastiaan van Stijn --- cli/command/image/build/internal/git/gitutils.go | 3 +++ .../image/build/internal/git/gitutils_test.go | 16 ++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/cli/command/image/build/internal/git/gitutils.go b/cli/command/image/build/internal/git/gitutils.go index b02993511f..1f3063b504 100644 --- a/cli/command/image/build/internal/git/gitutils.go +++ b/cli/command/image/build/internal/git/gitutils.go @@ -148,6 +148,9 @@ func supportsShallowClone(remoteURL string) bool { // Try a HEAD request and fallback to a Get request on error res, err := http.Head(serviceURL) // #nosec G107 + if err == nil { + _ = res.Body.Close() + } if err != nil || res.StatusCode != http.StatusOK { res, err = http.Get(serviceURL) // #nosec G107 if err == nil { diff --git a/cli/command/image/build/internal/git/gitutils_test.go b/cli/command/image/build/internal/git/gitutils_test.go index 204c2477eb..c8d9ee1bfd 100644 --- a/cli/command/image/build/internal/git/gitutils_test.go +++ b/cli/command/image/build/internal/git/gitutils_test.go @@ -350,15 +350,15 @@ func TestValidGitTransport(t *testing.T) { "github.com/docker/docker", } - for _, url := range gitUrls { - if !isGitTransport(url) { - t.Fatalf("%q should be detected as valid Git prefix", url) + for _, u := range gitUrls { + if !isGitTransport(u) { + t.Fatalf("%q should be detected as valid Git prefix", u) } } - for _, url := range incompleteGitUrls { - if isGitTransport(url) { - t.Fatalf("%q should not be detected as valid Git prefix", url) + for _, u := range incompleteGitUrls { + if isGitTransport(u) { + t.Fatalf("%q should not be detected as valid Git prefix", u) } } } @@ -371,8 +371,8 @@ func TestGitInvalidRef(t *testing.T) { "git@g.com:a/b.git#with space", } - for _, url := range gitUrls { - _, err := Clone(url) + for _, u := range gitUrls { + _, err := Clone(u) assert.Assert(t, err != nil) // On Windows, git has different case for the "invalid refspec" error, // so we can't use ErrorContains.