# Fix nil-pointer panic in checkpoint parent-load error path

`43a0631`→[main](/content/gh/entireio/git-sync/commits/main/index.html)·  
  
Soph·1mo ago·2 files·+31 added/-1 removed

In FirstParentChainStoppingAt, when object.GetCommit fails to load a first
parent it returns a nil commit, but the error message dereferenced
commit.ParentHashes[0] — a guaranteed nil-pointer panic (and the wrong hash
even if it didn't crash). Use the parent hash we tried to load instead.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

## Sessions

bb21edce625aView transcript

## Changes

2

- internal/planner
  
  - Mcheckpoint.go+1/-1
  
  - Acheckpoint_test.go+30

```
50 unmodified lines

51
52
53
54
54
55
56
57

50 unmodified lines

}
		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.
```

Minternal/planner/checkpoint.go+1/-1

```
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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())
	}
}
```

Ainternal/planner/checkpoint_test.go+30
