Skip to content

Fix submodule hash behaviour#1865

Open
mohak1 wants to merge 7 commits intogo-git:mainfrom
mohak1:fix-submodule-hash-behaviour
Open

Fix submodule hash behaviour#1865
mohak1 wants to merge 7 commits intogo-git:mainfrom
mohak1:fix-submodule-hash-behaviour

Conversation

@mohak1
Copy link
Copy Markdown

@mohak1 mohak1 commented Feb 25, 2026

Fixes #1838

Problem:
When cloning a repository that uses hash SHA-256, if one or more submodules have hash SHA-1 then object not found error is displayed. This does not align with git behaviour 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-256 but submodule repo uses hash is SHA-1 then the hash is truncated to remove the zero-padding. This results in correct hash value and hence object lookups complete successfully.

Added unit tests.

Copilot AI review requested due to automatic review settings February 25, 2026 00:08
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment thread submodule.go Outdated
Comment thread submodule_test.go Outdated
Comment thread submodule.go
Comment thread submodule.go
Comment thread submodule.go Outdated
Comment thread submodule.go
Comment thread submodule.go Outdated
@mohak1
Copy link
Copy Markdown
Author

mohak1 commented Mar 8, 2026

Hi @pjbgf, can you please review this PR and let me know if any changes are needed? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Align behaviour for repositories with a different hash algo of its submodules

2 participants