Skip to content

Commit 29a496c

Browse files
authored
Merge pull request #2012 from jedevc/git-propogate-errors
git: propogate failure to locate git binary
2 parents a97e164 + a43d9a6 commit 29a496c

3 files changed

Lines changed: 7 additions & 7 deletions

File tree

build/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
737737
hasMobyDriver := false
738738
gitattrs, err := getGitAttributes(ctx, opt.Inputs.ContextPath, opt.Inputs.DockerfilePath)
739739
if err != nil {
740-
logrus.Warn(err)
740+
logrus.WithError(err).Warn("current commit information was not captured by the build")
741741
}
742742
for i, np := range m[k] {
743743
node := nodes[np.driverIndex]

build/git.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,21 @@ func getGitAttributes(ctx context.Context, contextPath string, dockerfilePath st
5151

5252
gitc, err := gitutil.New(gitutil.WithContext(ctx), gitutil.WithWorkingDir(wd))
5353
if err != nil {
54-
if st, err := os.Stat(path.Join(wd, ".git")); err == nil && st.IsDir() {
55-
return res, errors.New("buildx: git was not found in the system. Current commit information was not captured by the build")
54+
if st, err1 := os.Stat(path.Join(wd, ".git")); err1 == nil && st.IsDir() {
55+
return res, errors.Wrap(err, "git was not found in the system")
5656
}
5757
return
5858
}
5959

6060
if !gitc.IsInsideWorkTree() {
6161
if st, err := os.Stat(path.Join(wd, ".git")); err == nil && st.IsDir() {
62-
return res, errors.New("buildx: failed to read current commit information with git rev-parse --is-inside-work-tree")
62+
return res, errors.New("failed to read current commit information with git rev-parse --is-inside-work-tree")
6363
}
6464
return res, nil
6565
}
6666

6767
if sha, err := gitc.FullCommit(); err != nil && !gitutil.IsUnknownRevision(err) {
68-
return res, errors.Wrapf(err, "buildx: failed to get git commit")
68+
return res, errors.Wrap(err, "failed to get git commit")
6969
} else if sha != "" {
7070
checkDirty := false
7171
if v, ok := os.LookupEnv("BUILDX_GIT_CHECK_DIRTY"); ok {
@@ -95,7 +95,7 @@ func getGitAttributes(ctx context.Context, contextPath string, dockerfilePath st
9595

9696
if setGitLabels {
9797
if root, err := gitc.RootDir(); err != nil {
98-
return res, errors.Wrapf(err, "buildx: failed to get git root dir")
98+
return res, errors.Wrap(err, "failed to get git root dir")
9999
} else if root != "" {
100100
if dockerfilePath == "" {
101101
dockerfilePath = filepath.Join(wd, "Dockerfile")

util/gitutil/gitutil.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func New(opts ...Option) (*Git, error) {
4949

5050
c.gitpath, err = gitPath(c.wd)
5151
if err != nil {
52-
return nil, errors.New("git not found in PATH")
52+
return nil, err
5353
}
5454

5555
return c, nil

0 commit comments

Comments
 (0)