aboutsummaryrefslogtreecommitdiffstats
path: root/modules/git/config_submodule_test.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2024-11-20 11:26:12 -0800
committerGitHub <noreply@github.com>2024-11-20 19:26:12 +0000
commit33850a83fe4ebd23a762a7aac81614c42e303bfa (patch)
treedbb95edd9c1c2604d262441b1e236cf107df1327 /modules/git/config_submodule_test.go
parent407b6e6dfc7ee9ebb8a16c7f1a786e4c24d0516e (diff)
downloadgitea-33850a83fe4ebd23a762a7aac81614c42e303bfa.tar.gz
gitea-33850a83fe4ebd23a762a7aac81614c42e303bfa.zip
Fix submodule parsing (#32571)
Fix #32568, parse `.gitmodules` correctly --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'modules/git/config_submodule_test.go')
-rw-r--r--modules/git/config_submodule_test.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/modules/git/config_submodule_test.go b/modules/git/config_submodule_test.go
new file mode 100644
index 0000000000..f0846c7bfb
--- /dev/null
+++ b/modules/git/config_submodule_test.go
@@ -0,0 +1,49 @@
+// Copyright 2024 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package git
+
+import (
+ "strings"
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestConfigSubmodule(t *testing.T) {
+ input := `
+[core]
+path = test
+
+[submodule "submodule1"]
+ path = path1
+ url = https://gitea.io/foo/foo
+ #branch = b1
+
+[other1]
+branch = master
+
+[submodule "submodule2"]
+ path = path2
+ url = https://gitea.io/bar/bar
+ branch = b2
+
+[other2]
+branch = main
+
+[submodule "submodule3"]
+ path = path3
+ url = https://gitea.io/xxx/xxx
+`
+
+ subModules, err := configParseSubModules(strings.NewReader(input))
+ assert.NoError(t, err)
+ assert.Len(t, subModules.cache, 3)
+
+ sm1, _ := subModules.Get("path1")
+ assert.Equal(t, &SubModule{Path: "path1", URL: "https://gitea.io/foo/foo", Branch: ""}, sm1)
+ sm2, _ := subModules.Get("path2")
+ assert.Equal(t, &SubModule{Path: "path2", URL: "https://gitea.io/bar/bar", Branch: "b2"}, sm2)
+ sm3, _ := subModules.Get("path3")
+ assert.Equal(t, &SubModule{Path: "path3", URL: "https://gitea.io/xxx/xxx", Branch: ""}, sm3)
+}