Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/planner/checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func FirstParentChainStoppingAt(store storer.EncodedObjectStorer, tip plumbing.H
}
commit, err = object.GetCommit(store, parent)
if err != nil {
return nil, fmt.Errorf("load parent commit %s: %w", commit.ParentHashes[0], err)
return nil, fmt.Errorf("load parent commit %s: %w", parent, err)
}
}
// Reverse in-place to get root-to-tip order.
Expand Down
30 changes: 30 additions & 0 deletions internal/planner/checkpoint_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package planner

import (
"strings"
"testing"

git "github.com/go-git/go-git/v6"
"github.com/go-git/go-git/v6/plumbing"
"github.com/go-git/go-git/v6/storage/memory"
)

// When a first-parent is absent from the store, the error path must not
// dereference the (nil) commit it just failed to load, and must name the
// parent hash it could not find.
func TestFirstParentChainStoppingAtMissingParentErrors(t *testing.T) {
repo, err := git.Init(memory.NewStorage(), nil)
if err != nil {
t.Fatalf("init repo: %v", err)
}
missingParent := plumbing.NewHash("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
tip := seedCommit(t, repo, []plumbing.Hash{missingParent})

_, err = FirstParentChainStoppingAt(repo.Storer, tip, map[plumbing.Hash]struct{}{})
if err == nil {
t.Fatal("expected error when first parent is missing from the store")
}
if !strings.Contains(err.Error(), missingParent.String()) {
t.Fatalf("error should name the missing parent %s, got %q", missingParent, err.Error())
}
}
Loading