From 45863c4f16dd48f971b5dece22058eae95365225 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Thu, 16 Feb 2023 07:34:54 +0100 Subject: [PATCH] Remove git warning: buildx/1633 Signed-off-by: David Gageot (cherry picked from commit d4a4aaf509dd006b253cda2ad399a37031eeb924) --- util/gitutil/gitutil.go | 4 ++-- util/gitutil/gitutil_test.go | 14 ++++++++++++++ util/gitutil/testutil.go | 9 +++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/util/gitutil/gitutil.go b/util/gitutil/gitutil.go index 69e6aa31..bf69d4fe 100644 --- a/util/gitutil/gitutil.go +++ b/util/gitutil/gitutil.go @@ -80,11 +80,11 @@ func (c *Git) RemoteURL() (string, error) { } func (c *Git) FullCommit() (string, error) { - return c.clean(c.run("show", "--format=%H", "HEAD", "--quiet")) + return c.clean(c.run("show", "--format=%H", "HEAD", "--quiet", "--")) } func (c *Git) ShortCommit() (string, error) { - return c.clean(c.run("show", "--format=%h", "HEAD", "--quiet")) + return c.clean(c.run("show", "--format=%h", "HEAD", "--quiet", "--")) } func (c *Git) Tag() (string, error) { diff --git a/util/gitutil/gitutil_test.go b/util/gitutil/gitutil_test.go index 050d4515..531db0f4 100644 --- a/util/gitutil/gitutil_test.go +++ b/util/gitutil/gitutil_test.go @@ -56,6 +56,20 @@ func TestGitFullCommitErr(t *testing.T) { _, err = c.FullCommit() require.Error(t, err) require.True(t, IsUnknownRevision(err)) + require.False(t, IsAmbiguousArgument(err)) +} + +func TestGitShortCommitErr(t *testing.T) { + Mktmp(t) + c, err := New() + require.NoError(t, err) + + GitInit(c, t) + + _, err = c.ShortCommit() + require.Error(t, err) + require.True(t, IsUnknownRevision(err)) + require.False(t, IsAmbiguousArgument(err)) } func TestGitTagsPointsAt(t *testing.T) { diff --git a/util/gitutil/testutil.go b/util/gitutil/testutil.go index 2b0d514b..8cdabc15 100644 --- a/util/gitutil/testutil.go +++ b/util/gitutil/testutil.go @@ -2,6 +2,7 @@ package gitutil import ( "os" + "strings" "testing" "github.com/stretchr/testify/require" @@ -73,3 +74,11 @@ func fakeGit(c *Git, args ...string) (string, error) { allArgs = append(allArgs, args...) return c.clean(c.run(allArgs...)) } + +func IsAmbiguousArgument(err error) bool { + if err == nil { + return false + } + errMsg := strings.ToLower(err.Error()) + return strings.Contains(errMsg, "use '--' to separate paths from revisions") +}