Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes an issue where cloning a SHA-256 repository with SHA-1 submodules results in "object not found" errors. The problem occurs because SHA-1 submodule commit hashes are stored with zero-padding in SHA-256 parent repositories, and go-git attempts to use these padded hashes when checking out submodules.
Changes:
- Added hash adaptation logic to detect and truncate zero-padded hashes when fetching submodules
- Implemented
adaptHashForSubmodule()function to handle hash format mismatches between parent and submodule repositories - Added comprehensive tests including unit tests and an integration test with a real mixed-hash repository
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| submodule.go | Adds adaptHashForSubmodule() function and calls it in fetchAndCheckout() to adapt parent hashes to match submodule object format |
| submodule_test.go | Adds unit test for hash adaptation logic with zero-padded SHA-1 hash in SHA-256 format |
| repository_test.go | Adds integration test that clones a real SHA-256 repository with SHA-1 submodules from GitLab |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Author
|
Hi @pjbgf, can you please review this PR and let me know if any changes are needed? Thanks |
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.
Fixes #1838
Problem:
When cloning a repository that uses hash
SHA-256, if one or more submodules have hashSHA-1thenobject not found erroris displayed. This does not align withgitbehaviour as it clones the submodules correctly.Solution:
Added a function to check the submodule repository object format and adapt the hash to match this before fetching the submodule.
If the parent repo uses
SHA-256but submodule repo uses hash isSHA-1then the hash is truncated to remove the zero-padding. This results in correct hash value and hence object lookups complete successfully.Added unit tests.