From 7c0a56bb90ce60d1a2ed3c8c17b2a5d86e60abb8 Mon Sep 17 00:00:00 2001 From: Joaquin Hui Gomez <132194176+joaquinhuigomez@users.noreply.github.com> Date: Sun, 29 Mar 2026 13:04:45 +0100 Subject: [PATCH] fix: use correct empty tree hash for SHA-256 repos Detect the repository's object format by checking the commit hash length and use the appropriate empty tree commit hash. SHA-256 repos use 64-character hashes and a different empty tree hash than SHA-1, which caused the initial commit to show no files in the Commit pane. Closes #5385 --- pkg/commands/models/commit.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/pkg/commands/models/commit.go b/pkg/commands/models/commit.go index 137528ee6e9..beb8156ceac 100644 --- a/pkg/commands/models/commit.go +++ b/pkg/commands/models/commit.go @@ -8,8 +8,11 @@ import ( "github.com/stefanhaller/git-todo-parser/todo" ) -// Special commit hash for empty tree object -const EmptyTreeCommitHash = "4b825dc642cb6eb9a060e54bf8d69288fbee4904" +// Empty tree commit hashes for SHA-1 and SHA-256 object formats +const ( + EmptyTreeCommitHash = "4b825dc642cb6eb9a060e54bf8d69288fbee4904" + EmptyTreeCommitHashSha256 = "6ef19b41225c5369f1c104d45d8d85efa9b057b53b14b4b9b939dd74decc5321" +) type CommitStatus uint8 @@ -122,11 +125,20 @@ func (c *Commit) ShortRefName() string { func (c *Commit) ParentRefName() string { if c.IsFirstCommit() { - return EmptyTreeCommitHash + return emptyTreeCommitHash(c.Hash()) } return c.RefName() + "^" } +// emptyTreeCommitHash returns the empty tree hash matching the object format +// of the given commit hash. SHA-256 repos use 64-character hashes; SHA-1 uses 40. +func emptyTreeCommitHash(commitHash string) string { + if len(commitHash) > 40 { + return EmptyTreeCommitHashSha256 + } + return EmptyTreeCommitHash +} + func (c *Commit) Parents() []string { return lo.Map(c.parents, func(s *string, _ int) string { return *s }) }