Skip to content

Commit 52db4cb

Browse files
committed
fix
1 parent 3661b14 commit 52db4cb

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

modules/git/commit.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -379,24 +379,31 @@ func (c *Commit) GetSubModules() (*ObjectCache, error) {
379379
defer rd.Close()
380380
scanner := bufio.NewScanner(rd)
381381
c.submoduleCache = newObjectCache()
382-
var ismodule bool
383-
var path string
382+
var subModule *SubModule
384383
for scanner.Scan() {
385-
if strings.HasPrefix(scanner.Text(), "[submodule") {
386-
ismodule = true
384+
if strings.HasPrefix(scanner.Text(), "[") {
385+
if subModule != nil {
386+
c.submoduleCache.Set(subModule.Name, subModule)
387+
subModule = nil
388+
}
389+
if strings.HasPrefix(scanner.Text(), "[submodule") {
390+
subModule = &SubModule{}
391+
}
387392
continue
388393
}
389-
if ismodule {
394+
if subModule != nil {
390395
fields := strings.Split(scanner.Text(), "=")
391396
k := strings.TrimSpace(fields[0])
392397
if k == "path" {
393-
path = strings.TrimSpace(fields[1])
398+
subModule.Name = strings.TrimSpace(fields[1])
394399
} else if k == "url" {
395-
c.submoduleCache.Set(path, &SubModule{path, strings.TrimSpace(fields[1])})
396-
ismodule = false
400+
subModule.URL = strings.TrimSpace(fields[1])
397401
}
398402
}
399403
}
404+
if subModule != nil {
405+
c.submoduleCache.Set(subModule.Name, subModule)
406+
}
400407
if err = scanner.Err(); err != nil {
401408
return nil, fmt.Errorf("GetSubModules scan: %w", err)
402409
}

0 commit comments

Comments
 (0)