mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-18 09:17:49 +08:00
build: check reachable git commits
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com> (cherry picked from commit fd5884189cc0d24a92c98fd4747847361c49c9c0)
This commit is contained in:
parent
02cf539a08
commit
661af29d46
@ -64,7 +64,7 @@ func getGitAttributes(ctx context.Context, contextPath string, dockerfilePath st
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if sha, err := gitc.FullCommit(); err != nil {
|
if sha, err := gitc.FullCommit(); err != nil && !gitutil.IsUnknownRevision(err) {
|
||||||
return res, errors.Wrapf(err, "buildx: failed to get git commit")
|
return res, errors.Wrapf(err, "buildx: failed to get git commit")
|
||||||
} else if sha != "" {
|
} else if sha != "" {
|
||||||
if gitc.IsDirty() {
|
if gitc.IsDirty() {
|
||||||
|
@ -138,3 +138,12 @@ func (c *Git) clean(out string, err error) (string, error) {
|
|||||||
}
|
}
|
||||||
return out, err
|
return out, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsUnknownRevision(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
// https://github.com/git/git/blob/a6a323b31e2bcbac2518bddec71ea7ad558870eb/setup.c#L204
|
||||||
|
errMsg := strings.ToLower(err.Error())
|
||||||
|
return strings.Contains(errMsg, "unknown revision or path not in the working tree") || strings.Contains(errMsg, "bad revision")
|
||||||
|
}
|
||||||
|
@ -46,6 +46,18 @@ func TestGitShortCommit(t *testing.T) {
|
|||||||
require.Equal(t, 7, len(out))
|
require.Equal(t, 7, len(out))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGitFullCommitErr(t *testing.T) {
|
||||||
|
Mktmp(t)
|
||||||
|
c, err := New()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
GitInit(c, t)
|
||||||
|
|
||||||
|
_, err = c.FullCommit()
|
||||||
|
require.Error(t, err)
|
||||||
|
require.True(t, IsUnknownRevision(err))
|
||||||
|
}
|
||||||
|
|
||||||
func TestGitTagsPointsAt(t *testing.T) {
|
func TestGitTagsPointsAt(t *testing.T) {
|
||||||
Mktmp(t)
|
Mktmp(t)
|
||||||
c, err := New()
|
c, err := New()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user