From 551b8f6785acd348633445261dac25f64c0a604e Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Thu, 15 Dec 2022 16:51:03 -0800 Subject: [PATCH] git: do not show warnings if project does not use git Signed-off-by: Tonis Tiigi --- build/git.go | 7 +++++-- build/git_test.go | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/build/git.go b/build/git.go index 0b2636b0..93325269 100644 --- a/build/git.go +++ b/build/git.go @@ -52,13 +52,16 @@ func getGitAttributes(ctx context.Context, contextPath string, dockerfilePath st gitc, err := gitutil.New(gitutil.WithContext(ctx), gitutil.WithWorkingDir(wd)) if err != nil { if st, err := os.Stat(path.Join(wd, ".git")); err == nil && st.IsDir() { - return res, errors.New("No git was found in the system. Current commit information was not captured by the build.") + return res, errors.New("git was not found in the system. Current commit information was not captured by the build") } return } if !gitc.IsInsideWorkTree() { - return res, errors.New("Not inside a git repository") + if st, err := os.Stat(path.Join(wd, ".git")); err == nil && st.IsDir() { + return res, errors.New("failed to read current commit information with git rev-parse --is-inside-work-tree") + } + return res, nil } if sha, err := gitc.FullCommit(); err != nil { diff --git a/build/git_test.go b/build/git_test.go index fc360fea..9f2f7324 100644 --- a/build/git_test.go +++ b/build/git_test.go @@ -31,7 +31,7 @@ func setupTest(tb testing.TB) { func TestGetGitAttributesNotGitRepo(t *testing.T) { _, err := getGitAttributes(context.Background(), t.TempDir(), "Dockerfile") - assert.Error(t, err) + assert.NoError(t, err) } func TestGetGitAttributesBadGitRepo(t *testing.T) {