fix: use correct empty tree hash for SHA-256 repos#5434
Open
joaquinhuigomez wants to merge 1 commit intojesseduffield:masterfrom
Open
fix: use correct empty tree hash for SHA-256 repos#5434joaquinhuigomez wants to merge 1 commit intojesseduffield:masterfrom
joaquinhuigomez wants to merge 1 commit intojesseduffield:masterfrom
Conversation
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
Collaborator
stefanhaller
left a comment
There was a problem hiding this comment.
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 { |
Collaborator
There was a problem hiding this comment.
Nitpick: I'd probably not bother with a function and simply inline it into ParentRefName.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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'texist 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:
EmptyTreeCommitHashSha256constant for the SHA-256 empty tree objectCommit.ParentRefName()now selects the right empty tree hash based on the commit's own hash lengthTesting:
go test ./...on affected packages)git hash-object -t tree /dev/nullin a--object-format=sha256repoCloses #5385