diff --git a/cli/command/image/build/internal/git/gitutils.go b/cli/command/image/build/internal/git/gitutils.go index b02993511..1f3063b50 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 204c2477e..c8d9ee1bf 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.