Skip to content

Commit

Permalink
Add support for cloning git submodules (#1355)
Browse files Browse the repository at this point in the history
Add support for git submodules

Signed-off-by: Tom Kennedy <[email protected]>
  • Loading branch information
tomkennedy513 authored Oct 17, 2023
1 parent 41841a4 commit 4bbd92e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
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

0 comments on commit 4bbd92e

Please sign in to comment.