Skip to content

fix: use correct empty tree hash for SHA-256 repos#5434

Open
joaquinhuigomez wants to merge 1 commit intojesseduffield:masterfrom
joaquinhuigomez:fix/sha256-empty-tree-hash
Open

fix: use correct empty tree hash for SHA-256 repos#5434
joaquinhuigomez wants to merge 1 commit intojesseduffield:masterfrom
joaquinhuigomez:fix/sha256-empty-tree-hash

Conversation

@joaquinhuigomez
Copy link
Copy Markdown

When diffing the initial commit in a SHA-256 repository, lazygit passes
the SHA-1 empty tree hash (4b825dc...) to git diff. This hash doesn't
exist in SHA-256 repos, so git fails with "unknown revision" and the
Commit pane shows no files.

The fix detects the object format by checking the commit hash length
(SHA-256 hashes are 64 characters vs 40 for SHA-1) and returns the
correct empty tree hash accordingly. No additional git commands needed.

Changes:

  • Added EmptyTreeCommitHashSha256 constant for the SHA-256 empty tree object
  • Commit.ParentRefName() now selects the right empty tree hash based on the commit's own hash length

Testing:

  • All existing tests pass (go test ./... on affected packages)
  • Verified SHA-256 empty tree hash via git hash-object -t tree /dev/null in a --object-format=sha256 repo

Closes #5385

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 jesseduffield#5385
Copy link
Copy Markdown
Collaborator

@stefanhaller stefanhaller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good. I was surprised that this seems to be the only change needed to make lazygit work with SHA-256 repos.

There's another place in the code that uses the EmptyTreeCommitHash: getNextPipes in graph.go. From a brief look at the code it seems that in that case the hash is not actually used for anything and only needs to be distinct from any real commit hash, so it's probably ok to leave this as is for now. Kind of wondering if we could also have used a string like "ROOT" there...


// 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 {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: I'd probably not bother with a function and simply inline it into ParentRefName.

@stefanhaller stefanhaller added the bug Something isn't working label Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No files shown in Commit pane for the initial commit in SHA-256 repos

2 participants