Added function to add submodule indexes
This commit is contained in:
parent
7fa0bc1fbe
commit
6df3da1daf
2 changed files with 15 additions and 7 deletions
|
@ -191,3 +191,16 @@ func GetSubmoduleCommits(repoPath string) []SubModuleCommit {
|
|||
|
||||
return submodules
|
||||
}
|
||||
|
||||
// AddSubmoduleIndexes Adds the given submodules to the git index. Requires the .gitmodules file to be already present.
|
||||
func AddSubmoduleIndexes(repoPath string, submodules []SubModuleCommit) error {
|
||||
for _, submodule := range submodules {
|
||||
if stdout, err := NewCommand("update-index", "--add", "--cacheinfo", "160000", submodule.Commit, submodule.Name).
|
||||
RunInDir(repoPath); err != nil {
|
||||
log.Error("Unable to add %s as submodule to repo %s: stdout %s\nError: %v", submodule.Name, repoPath, stdout, err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -185,13 +185,8 @@ func generateRepoCommit(repo, templateRepo, generateRepo *models.Repository, tmp
|
|||
return fmt.Errorf("git remote add: %v", err)
|
||||
}
|
||||
|
||||
// Reapply the submodules by updating the index
|
||||
for _, submodule := range submodules {
|
||||
if stdout, err := git.NewCommand("update-index", "--add", "--cacheinfo", "160000", submodule.Commit, submodule.Name).
|
||||
RunInDirWithEnv(tmpDir, env); err != nil {
|
||||
log.Error("Unable to add %v as submodule to temporary repo %s: stdout %s\nError: %v", submodule.Name, tmpDir, stdout, err)
|
||||
return fmt.Errorf("git update-index --add --cacheinfo 160000 %s %s: %v", submodule.Commit, submodule.Name, err)
|
||||
}
|
||||
if err := git.AddSubmoduleIndexes(tmpDir, submodules); err != nil {
|
||||
return fmt.Errorf("Failed to add submodules: %v", err)
|
||||
}
|
||||
|
||||
return initRepoCommit(tmpDir, repo, repo.Owner, templateRepo.DefaultBranch)
|
||||
|
|
Loading…
Add table
Reference in a new issue