Merge pull request #1634 from dgageot/fix-1633

build: fix git ambiguous argument
This commit is contained in:
CrazyMax 2023-02-16 14:05:32 +01:00 committed by GitHub
commit b1949b7388
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 2 deletions

View File

@ -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) {

View File

@ -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) {

View File

@ -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")
}