From 4c431045378c538f61ea94b55c41451948979abb Mon Sep 17 00:00:00 2001 From: GDS K S Date: Sat, 11 Apr 2026 22:46:44 -0500 Subject: [PATCH] Fix empty tree hash for SHA-256 repos --- pkg/commands/models/commit.go | 14 ++++++++++++-- pkg/gui/presentation/graph/graph.go | 6 +++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/pkg/commands/models/commit.go b/pkg/commands/models/commit.go index 137528ee6..77ad21b4a 100644 --- a/pkg/commands/models/commit.go +++ b/pkg/commands/models/commit.go @@ -8,8 +8,9 @@ import ( "github.com/stefanhaller/git-todo-parser/todo" ) -// Special commit hash for empty tree object +// Empty tree object hashes for SHA-1 and SHA-256 repos. const EmptyTreeCommitHash = "4b825dc642cb6eb9a060e54bf8d69288fbee4904" +const EmptyTreeCommitHashSHA256 = "6ef19b41225c5369f1c104d45d8d85efa9b057b53b14b4b9b939dd74decc5321" type CommitStatus uint8 @@ -122,11 +123,20 @@ func (c *Commit) ShortRefName() string { func (c *Commit) ParentRefName() string { if c.IsFirstCommit() { - return EmptyTreeCommitHash + return c.emptyTreeHash() } return c.RefName() + "^" } +// emptyTreeHash returns the empty tree object hash matching this repo's +// object format. SHA-256 repos produce 64-char hashes; SHA-1 repos 40-char. +func (c *Commit) emptyTreeHash() string { + if len(c.Hash()) > 40 { + return EmptyTreeCommitHashSHA256 + } + return EmptyTreeCommitHash +} + func (c *Commit) Parents() []string { return lo.Map(c.parents, func(s *string, _ int) string { return *s }) } diff --git a/pkg/gui/presentation/graph/graph.go b/pkg/gui/presentation/graph/graph.go index 1639a62e6..8c6a96b5e 100644 --- a/pkg/gui/presentation/graph/graph.go +++ b/pkg/gui/presentation/graph/graph.go @@ -142,7 +142,11 @@ func getNextPipes(prevPipes []Pipe, commit *models.Commit, getStyle func(c *mode var toHash *string if commit.IsFirstCommit() { - toHash = &EmptyTreeCommitHash + emptyHash := EmptyTreeCommitHash + if len(commit.Hash()) > 40 { + emptyHash = models.EmptyTreeCommitHashSHA256 + } + toHash = &emptyHash } else { toHash = commit.ParentPtrs()[0] }