mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-07-19 09:39:39 +02:00
git/commit: re-implement submodules file reader (#8438)
Reimplement the submodules parser to not depend on the go-git dependency. See #8222 for the full refactor context. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8438 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: oliverpool <git@olivier.pfad.fr> Co-committed-by: oliverpool <git@olivier.pfad.fr>
This commit is contained in:
parent
48cc6e684a
commit
5158493ba6
17 changed files with 220 additions and 166 deletions
|
@ -4,9 +4,11 @@
|
|||
package git
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestGetRefURL(t *testing.T) {
|
||||
|
@ -40,3 +42,74 @@ func TestGetRefURL(t *testing.T) {
|
|||
assert.Equal(t, kase.expect, getRefURL(kase.refURL, kase.prefixURL, kase.parentPath, kase.SSHDomain))
|
||||
}
|
||||
}
|
||||
|
||||
func Test_parseSubmoduleContent(t *testing.T) {
|
||||
submoduleFiles := []struct {
|
||||
fileContent string
|
||||
expectedPath string
|
||||
expected Submodule
|
||||
}{
|
||||
{
|
||||
fileContent: `[submodule "jakarta-servlet"]
|
||||
url = ../../ALP-pool/jakarta-servlet
|
||||
path = jakarta-servlet`,
|
||||
expectedPath: "jakarta-servlet",
|
||||
expected: Submodule{
|
||||
Path: "jakarta-servlet",
|
||||
URL: "../../ALP-pool/jakarta-servlet",
|
||||
},
|
||||
},
|
||||
{
|
||||
fileContent: `[submodule "jakarta-servlet"]
|
||||
path = jakarta-servlet
|
||||
url = ../../ALP-pool/jakarta-servlet`,
|
||||
expectedPath: "jakarta-servlet",
|
||||
expected: Submodule{
|
||||
Path: "jakarta-servlet",
|
||||
URL: "../../ALP-pool/jakarta-servlet",
|
||||
},
|
||||
},
|
||||
{
|
||||
fileContent: `[submodule "about/documents"]
|
||||
path = about/documents
|
||||
url = git@github.com:example/documents.git
|
||||
branch = gh-pages
|
||||
[submodule "custom-name"]
|
||||
path = manifesto
|
||||
url = https://github.com/example/manifesto.git
|
||||
[submodule]
|
||||
path = relative/url
|
||||
url = ../such-relative.git
|
||||
`,
|
||||
expectedPath: "relative/url",
|
||||
expected: Submodule{
|
||||
Path: "relative/url",
|
||||
URL: "../such-relative.git",
|
||||
},
|
||||
},
|
||||
{
|
||||
fileContent: `# .gitmodules
|
||||
# Subsection names are case sensitive
|
||||
[submodule "Seanpm2001/Degoogle-your-life"]
|
||||
path = Its-time-to-cut-WideVine-DRM/DeGoogle-Your-Life/submodule.gitmodules
|
||||
url = https://github.com/seanpm2001/Degoogle-your-life/
|
||||
|
||||
[submodule "seanpm2001/degoogle-your-life"]
|
||||
url = https://github.com/seanpm2001/degoogle-your-life/
|
||||
# This second section should not be merged with the first, because of casing
|
||||
`,
|
||||
expectedPath: "Its-time-to-cut-WideVine-DRM/DeGoogle-Your-Life/submodule.gitmodules",
|
||||
expected: Submodule{
|
||||
Path: "Its-time-to-cut-WideVine-DRM/DeGoogle-Your-Life/submodule.gitmodules",
|
||||
URL: "https://github.com/seanpm2001/Degoogle-your-life/",
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, kase := range submoduleFiles {
|
||||
submodule, err := parseSubmoduleContent(strings.NewReader(kase.fileContent))
|
||||
require.NoError(t, err)
|
||||
v, ok := submodule[kase.expectedPath]
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, kase.expected, v)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue