gitea源码

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2024 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package git
  4. import (
  5. "strings"
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestConfigSubmodule(t *testing.T) {
  10. input := `
  11. [core]
  12. path = test
  13. [submodule "submodule1"]
  14. path = path1
  15. url = https://gitea.io/foo/foo
  16. #branch = b1
  17. [other1]
  18. branch = master
  19. [submodule "submodule2"]
  20. path = path2
  21. url = https://gitea.io/bar/bar
  22. branch = b2
  23. [other2]
  24. branch = main
  25. [submodule "submodule3"]
  26. path = path3
  27. url = https://gitea.io/xxx/xxx
  28. `
  29. subModules, err := configParseSubModules(strings.NewReader(input))
  30. assert.NoError(t, err)
  31. assert.Len(t, subModules.cache, 3)
  32. sm1, _ := subModules.Get("path1")
  33. assert.Equal(t, &SubModule{Path: "path1", URL: "https://gitea.io/foo/foo", Branch: ""}, sm1)
  34. sm2, _ := subModules.Get("path2")
  35. assert.Equal(t, &SubModule{Path: "path2", URL: "https://gitea.io/bar/bar", Branch: "b2"}, sm2)
  36. sm3, _ := subModules.Get("path3")
  37. assert.Equal(t, &SubModule{Path: "path3", URL: "https://gitea.io/xxx/xxx", Branch: ""}, sm3)
  38. }