MCPcopy Index your code
hub / github.com/go-git/go-git / validSubmoduleName

Function validSubmoduleName

config/modules.go:140–160  ·  view source on GitHub ↗

validSubmoduleName mirrors canonical Git's check_submodule_name in submodule-config.c [1]: reject empty names and any name with a ".." path component, using both '/' and '\\' as separators so the rule is consistent across platforms. The component check is delegated to `pathutil.IsHFSDot` and `pathut

(name string)

Source from the content-addressed store, hash-verified

138//
139// [1]: https://github.com/git/git/blob/v2.54.0/submodule-config.c#L214-L237
140func validSubmoduleName(name string) error {
141 if name == "" || name == "." {
142 return ErrModuleBadName
143 }
144 for _, seg := range strings.FieldsFunc(name, isPathSep) {
145 if pathutil.IsHFSDot(seg, ".") || pathutil.IsNTFSDot(seg, ".", "") {
146 return ErrModuleBadName
147 }
148 }
149 // go-git-specific defensive checks beyond canonical Git.
150 if strings.ContainsRune(name, 0) {
151 return ErrModuleBadName
152 }
153 if isPathSep(rune(name[0])) || isPathSep(rune(name[len(name)-1])) {
154 return ErrModuleBadName
155 }
156 if len(name) >= 2 && name[1] == ':' {
157 return ErrModuleBadName
158 }
159 return nil
160}
161
162func isPathSep(r rune) bool { return r == '/' || r == '\\' }
163

Callers 1

ValidateMethod · 0.85

Calls 3

IsHFSDotFunction · 0.92
IsNTFSDotFunction · 0.92
isPathSepFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…