Skip to content

Commit bcc0759

Browse files
committed
Handle missing commits
1 parent 27ef08e commit bcc0759

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

stack/stack.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,17 @@ func Load(
249249
// so this needs more careful thought.
250250
continue
251251
}
252-
commit, err := repo.CommitObject(plumbing.NewHash(linkedRevision.Revision.HeadCommitSHA))
252+
headCommitHash := plumbing.NewHash(linkedRevision.Revision.HeadCommitSHA)
253+
commit, err := repo.CommitObject(headCommitHash)
253254
if err != nil {
254-
return nil, errors.WithStack(err)
255+
if errors.Is(err, plumbing.ErrObjectNotFound) {
256+
// If we haven't yet fetched the commit from the remote then
257+
// we fabricate a commit and hope downstream code doesn't
258+
// try to access anything other than the hash.
259+
commit = &object.Commit{Hash: headCommitHash}
260+
} else {
261+
return nil, errors.WithStack(err)
262+
}
255263
}
256264
review := &linkedRevision.Review
257265
s = append(s, CommitInfo{

0 commit comments

Comments
 (0)