From aecd5e5bb4d1157e732bb3597404a590f5664233 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 7 Nov 2026 23:27:21 +0100 Subject: [PATCH] Add a test showing that .gitmodules keys are found in the middle of a line Co-Authored-By: Claude Opus 5.5 --- pkg/commands/git_commands/submodule_test.go | 68 +++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/pkg/commands/git_commands/submodule_test.go b/pkg/commands/git_commands/submodule_test.go index 2740ecf51..c1bf458c0 100644 --- a/pkg/commands/git_commands/submodule_test.go +++ b/pkg/commands/git_commands/submodule_test.go @@ -14,6 +14,74 @@ import ( "github.com/stretchr/testify/assert" ) +func TestParseGitmodules(t *testing.T) { + scenarios := []struct { + testName string + lines []string + expected []*models.SubmoduleConfig + }{ + { + testName: "two submodules", + lines: []string{ + `[submodule "one"]`, + "\tpath = path/to/one", + "\turl = https://example.com/one.git", + `[submodule "two"]`, + "\tpath = two", + "\turl = ../two", + }, + expected: []*models.SubmoduleConfig{ + {Name: "one", Path: "path/to/one", Url: "https://example.com/one.git"}, + {Name: "two", Path: "two", Url: "../two"}, + }, + }, + { + testName: "url that contains path=", + lines: []string{ + `[submodule "sub"]`, + "\tpath = sub", + "\turl = https://example.com/repo?path=other", + }, + /* EXPECTED: + expected: []*models.SubmoduleConfig{ + {Name: "sub", Path: "sub", Url: "https://example.com/repo?path=other"}, + }, + ACTUAL: */ + expected: []*models.SubmoduleConfig{ + {Name: "sub", Path: "other"}, + }, + }, + { + testName: "commented-out section", + lines: []string{ + `[submodule "sub"]`, + "\tpath = sub", + "\turl = ../sub", + `#[submodule "old"]`, + "#\tpath = old", + "#\turl = ../old", + }, + /* EXPECTED: + expected: []*models.SubmoduleConfig{ + {Name: "sub", Path: "sub", Url: "../sub"}, + }, + ACTUAL: */ + expected: []*models.SubmoduleConfig{ + {Name: "sub", Path: "sub", Url: "../sub"}, + {Name: "old", Path: "old", Url: "../old"}, + }, + }, + } + + for _, s := range scenarios { + t.Run(s.testName, func(t *testing.T) { + configs, err := parseGitmodules(strings.NewReader(strings.Join(s.lines, "\n")), nil) + assert.NoError(t, err) + assert.Equal(t, s.expected, configs) + }) + } +} + func TestIsSuspiciousSubmoduleName(t *testing.T) { scenarios := []struct { name string