Skip to content

Commit 035832e

Browse files
committed
gitutil: preserve error type when wrapping
Signed-off-by: Stephen Day <[email protected]>
1 parent ee8eeac commit 035832e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

util/gitutil/git_cli.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,23 @@ func (cli *GitCLI) Run(ctx context.Context, args ...string) (_ []byte, err error
210210
}
211211

212212
if err != nil {
213+
select {
214+
case <-ctx.Done():
215+
cerr := context.Cause(ctx)
216+
if cerr != nil {
217+
return buf.Bytes(), errors.Wrapf(cerr, "context completed: git stderr:\n%s", errbuf.String())
218+
}
219+
default:
220+
}
221+
213222
if strings.Contains(errbuf.String(), "--depth") || strings.Contains(errbuf.String(), "shallow") {
214223
if newArgs := argsNoDepth(args); len(args) > len(newArgs) {
215224
args = newArgs
216225
continue
217226
}
218227
}
219-
return buf.Bytes(), errors.Errorf("git error: %s\nstderr:\n%s", err, errbuf.String())
228+
229+
return buf.Bytes(), errors.Wrapf(err, "git stderr:\n%s", errbuf.String())
220230
}
221231
return buf.Bytes(), nil
222232
}

0 commit comments

Comments
 (0)