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)
| 138 | // |
| 139 | // [1]: https://github.com/git/git/blob/v2.54.0/submodule-config.c#L214-L237 |
| 140 | func 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 | |
| 162 | func isPathSep(r rune) bool { return r == '/' || r == '\\' } |
| 163 |