Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for cloning git submodules #1355

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions pkg/git/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,23 @@ func (f Fetcher) Fetch(dir, gitURL, gitRevision, metadataDir string) error {
return errors.Wrapf(err, "checking out revision")
}

submodules, err := worktree.Submodules()
if err != nil {
return errors.Wrapf(err, "getting submodules")
}

for _, submodule := range submodules {
f.Logger.Printf("Updating submodule %v", submodule.Config().URL)
submoduleAuth, err := f.Keychain.Resolve(submodule.Config().URL)
if err != nil {
return err
}
err = submodule.Update(&gogit.SubmoduleUpdateOptions{Auth: submoduleAuth, Init: true, RecurseSubmodules: gogit.DefaultSubmoduleRecursionDepth })
if err != nil {
return errors.Wrapf(err, "updating submodules")
}
}

projectMetadataFile, err := os.Create(path.Join(metadataDir, "project-metadata.toml"))
if err != nil {
return errors.Wrapf(err, "invalid metadata destination '%s/project-metadata.toml' for git repository: %s", metadataDir, gitURL)
Expand Down
10 changes: 10 additions & 0 deletions pkg/git/fetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ func testGitCheckout(t *testing.T, when spec.G, it spec.S) {
err := fetcher.Fetch(testDir, "[email protected]:org/repo", "main", metadataDir)
require.ErrorContains(t, err, "unable to fetch references for repository")
})

it("initializes submodules", func() {
err := fetcher.Fetch(testDir, "https://github.com/git-fixtures/submodule", "master", metadataDir)
require.NoError(t, err)

_, err = os.Lstat(path.Join(testDir, "basic", ".gitignore"))
require.NoError(t, err)


})
})
}

Expand Down