Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
wxiaoguang committed Nov 20, 2024
1 parent 3661b14 commit 52db4cb
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions modules/git/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,24 +379,31 @@ func (c *Commit) GetSubModules() (*ObjectCache, error) {
defer rd.Close()
scanner := bufio.NewScanner(rd)
c.submoduleCache = newObjectCache()
var ismodule bool
var path string
var subModule *SubModule
for scanner.Scan() {
if strings.HasPrefix(scanner.Text(), "[submodule") {
ismodule = true
if strings.HasPrefix(scanner.Text(), "[") {
if subModule != nil {
c.submoduleCache.Set(subModule.Name, subModule)
subModule = nil
}
if strings.HasPrefix(scanner.Text(), "[submodule") {
subModule = &SubModule{}
}
continue
}
if ismodule {
if subModule != nil {
fields := strings.Split(scanner.Text(), "=")
k := strings.TrimSpace(fields[0])
if k == "path" {
path = strings.TrimSpace(fields[1])
subModule.Name = strings.TrimSpace(fields[1])
} else if k == "url" {
c.submoduleCache.Set(path, &SubModule{path, strings.TrimSpace(fields[1])})
ismodule = false
subModule.URL = strings.TrimSpace(fields[1])
}
}
}
if subModule != nil {
c.submoduleCache.Set(subModule.Name, subModule)
}
if err = scanner.Err(); err != nil {
return nil, fmt.Errorf("GetSubModules scan: %w", err)
}
Expand Down

0 comments on commit 52db4cb

Please sign in to comment.