Skip to content
This repository was archived by the owner on May 8, 2024. It is now read-only.

Commit c22a59f

Browse files
authoredMar 30, 2021
Support CIRRUS_CLONE_SUBMODULES (#114)
1 parent d497055 commit c22a59f

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
 

‎internal/executor/executor.go

+27
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ func (executor *Executor) CloneRepository(env map[string]string) bool {
367367
branch := env["CIRRUS_BRANCH"]
368368
pr_number, is_pr := env["CIRRUS_PR"]
369369
tag, is_tag := env["CIRRUS_TAG"]
370+
_, is_clone_modules := env["CIRRUS_CLONE_SUBMODULES"]
370371

371372
clone_url := env["CIRRUS_REPO_CLONE_URL"]
372373
if _, has_clone_token := env["CIRRUS_REPO_CLONE_TOKEN"]; has_clone_token {
@@ -498,6 +499,32 @@ func (executor *Executor) CloneRepository(env map[string]string) bool {
498499
return false
499500
}
500501

502+
if is_clone_modules {
503+
logUploader.Write([]byte("\nUpdating submodules..."))
504+
505+
workTree, err := repo.Worktree()
506+
if err != nil {
507+
logUploader.Write([]byte(fmt.Sprintf("\nFailed to get work tree: %s!", err)))
508+
return false
509+
}
510+
511+
submodules, err := workTree.Submodules()
512+
if err != nil {
513+
logUploader.Write([]byte(fmt.Sprintf("\nFailed to get submodules: %s!", err)))
514+
return false
515+
}
516+
517+
if err := submodules.Update(&git.SubmoduleUpdateOptions{
518+
Init: true,
519+
RecurseSubmodules: git.DefaultSubmoduleRecursionDepth,
520+
}); err != nil {
521+
logUploader.Write([]byte(fmt.Sprintf("\nFailed to update submodules: %s!", err)))
522+
return false
523+
}
524+
525+
logUploader.Write([]byte("\nSucessfully updated submodules!"))
526+
}
527+
501528
if ref.Hash() != plumbing.NewHash(change) {
502529
logUploader.Write([]byte(fmt.Sprintf("\nHEAD is at %s.", ref.Hash())))
503530
logUploader.Write([]byte(fmt.Sprintf("\nHard resetting to %s...", change)))

0 commit comments

Comments
 (0)
This repository has been archived.