Skip to content

Conversation

@bjornrobertsson
Copy link

Add submodule cloning support via native Go implementation

Summary

This PR resolves/mitigates #74

Changes

Since the existing submodule support in git.go depends on execution of the git binary, this implementation circumvents that limitation by traversing the tree to clone submodules natively in Go.

Behavior

  • Functionality can be toggled via a parameter (ENVBUILDER_GIT_CLONE_SUBMODULES)
  • Only runs on initial workspace start
  • Does not repeat on subsequent starts (unless the repository is deleted)

Add support for initializing and updating git submodules during repository cloning.
Added GitCloneSubmodules option to support recursive submodule initialization.
Resolved issues with git submodule handling for better cloning and URL resolution.
Resolved issues with git submodule handling to ensure robust cloning and URL resolution without relying on git binary calls.
Adding tests for Submodules and two missing
@bjornrobertsson bjornrobertsson linked an issue Dec 11, 2025 that may be closed by this pull request
@bjornrobertsson
Copy link
Author

I have read the CLA Document and I hereby sign the CLA
recheck

Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

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

Thanks for working on this @bjornrobertsson !
I have some comments below, and I think it would also be worthwhile adding an integration test (see: integration/integration_test.go and testutil/gittest/gittest.go).

Comment on lines +436 to +438
// resolveSubmoduleURL resolves a potentially relative submodule URL against the parent repository URL
// ResolveSubmoduleURLForTest is exported for testing resolveSubmoduleURL logic
func ResolveSubmoduleURLForTest(parentURL, submoduleURL string) (string, error) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: the naming of this function implies that it is only used in tests, which is false. suggestion: ResolveSubmoduleURL.

Comment on lines +505 to +528
{
name: "absolute",
parentURL: "https://example.com/org/main.git",
subURL: "https://github.com/other/repo.git",
expect: "https://github.com/other/repo.git",
},
{
name: "relativeSibling",
parentURL: "https://example.com/org/main.git",
subURL: "../deps/lib.git",
expect: "https://example.com/org/deps/lib.git",
},
{
name: "relativeChild",
parentURL: "https://example.com/org/main.git",
subURL: "./extras/tool.git",
expect: "https://example.com/org/main.git/extras/tool.git",
},
{
name: "badParent",
parentURL: "://bad",
subURL: "./child",
expectErr: "parse parent URL",
},
Copy link
Member

Choose a reason for hiding this comment

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

Please also test with the URL schemes from TestSetupRepoAuth:

  • SSH with scheme (ssh://host.tld/repo)
  • SSH without scheme ([email protected]:repo/path)
  • Git scheme (git://[email protected]:repo/path)
  • Absolute local path (/path/to/repo)
  • Relative paths without ./.. (path/to/repo)

Comment on lines +145 to +150
if opts.Submodules {
err = initSubmodules(ctx, logf, repo, opts)
if err != nil {
return true, fmt.Errorf("init submodules: %w", err)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

We can detect the presence/absence of submodules via .gitmodules after cloning the remote. This would remove the need to have a separate config option.

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.

Git submodule support

2 participants