From 52db4cbf9a68fb21d30dafdcd87b82079ddf9925 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Wed, 20 Nov 2024 18:55:24 +0800 Subject: [PATCH] fix --- modules/git/commit.go | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/modules/git/commit.go b/modules/git/commit.go index 86adaa79a667c..14ade2737d765 100644 --- a/modules/git/commit.go +++ b/modules/git/commit.go @@ -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) }