Validate validates the fields and sets the default values.
()
| 98 | |
| 99 | // Validate validates the fields and sets the default values. |
| 100 | func (m *Submodule) Validate() error { |
| 101 | if err := validSubmoduleName(m.Name); err != nil { |
| 102 | return fmt.Errorf("%w: %q", ErrModuleBadName, m.Name) |
| 103 | } |
| 104 | |
| 105 | if m.Path == "" { |
| 106 | return ErrModuleEmptyPath |
| 107 | } |
| 108 | |
| 109 | if m.URL == "" { |
| 110 | return ErrModuleEmptyURL |
| 111 | } |
| 112 | |
| 113 | if dotdotPath.MatchString(m.Path) { |
| 114 | return ErrModuleBadPath |
| 115 | } |
| 116 | |
| 117 | return nil |
| 118 | } |
| 119 | |
| 120 | // validSubmoduleName mirrors canonical Git's check_submodule_name in |
| 121 | // submodule-config.c [1]: reject empty names and any name with a ".." |