Skip to content

Commit 0bb10af

Browse files
authored
Fix bad parsing for some .gitmodules that path and url not ordered (#61)
for example, the .gitmodules in https://git.zx2c4.com/cgit is like this: ```.gitmodules [submodule "git"] url = https://git.kernel.org/pub/scm/git/git.git path = git ```
1 parent 5db3510 commit 0bb10af

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

commit_submodule.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,12 @@ func (c *Commit) Submodules() (Submodules, error) {
4242
c.submodules = newObjectCache()
4343
var inSection bool
4444
var path string
45+
var url string
4546
for scanner.Scan() {
4647
if strings.HasPrefix(scanner.Text(), "[submodule") {
4748
inSection = true
49+
path = ""
50+
url = ""
4851
continue
4952
} else if !inSection {
5053
continue
@@ -55,9 +58,13 @@ func (c *Commit) Submodules() (Submodules, error) {
5558
case "path":
5659
path = strings.TrimSpace(fields[1])
5760
case "url":
61+
url = strings.TrimSpace(fields[1])
62+
}
63+
64+
if len(path) > 0 && len(url) > 0 {
5865
mod := &Submodule{
5966
Name: path,
60-
URL: strings.TrimSpace(fields[1]),
67+
URL: url,
6168
}
6269

6370
mod.Commit, c.submodulesErr = c.repo.RevParse(c.id.String() + ":" + mod.Name)

0 commit comments

Comments
 (0)