Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix build
  • Loading branch information
wxiaoguang committed Dec 31, 2024
commit 06b9eb3f030b5c2cc499f92fb3768922bfcaa4d5
11 changes: 8 additions & 3 deletions modules/git/commit_submodule_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ func (sf *CommitSubModuleFile) RefID() string {
return sf.refID
}

// SubModuleCommit submodule name and commit from a repository
type SubModuleCommit struct {
Name string
Commit string
}

// GetSubmoduleCommits Returns a list of active submodules in the repository
func GetSubmoduleCommits(ctx context.Context, repoPath string) []SubModuleCommit {
stdoutReader, stdoutWriter := io.Pipe()
Expand Down Expand Up @@ -164,8 +170,7 @@ func GetSubmoduleCommits(ctx context.Context, repoPath string) []SubModuleCommit
}

// If no commit was found for the module skip it
commit, _, err := NewCommand(ctx, "submodule", "status", name).
RunStdString(&RunOpts{Dir: repoPath})
commit, _, err := NewCommand(ctx, "submodule", "status").AddDynamicArguments(name).RunStdString(&RunOpts{Dir: repoPath})
if err != nil {
log.Debug("Submodule %s skipped because it has no commit", name)
continue
Expand Down Expand Up @@ -198,7 +203,7 @@ func GetSubmoduleCommits(ctx context.Context, repoPath string) []SubModuleCommit
// AddSubmoduleIndexes Adds the given submodules to the git index. Requires the .gitmodules file to be already present.
func AddSubmoduleIndexes(ctx context.Context, repoPath string, submodules []SubModuleCommit) error {
for _, submodule := range submodules {
if stdout, _, err := NewCommand(ctx, "update-index", "--add", "--cacheinfo", "160000", submodule.Commit, submodule.Name).
if stdout, _, err := NewCommand(ctx, "update-index", "--add", "--cacheinfo", "160000").AddDynamicArguments(submodule.Commit, submodule.Name).
RunStdString(&RunOpts{Dir: 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
Expand Down
Loading