Paths returns the config file location for a given scope.
(scope Scope)
| 189 | |
| 190 | // Paths returns the config file location for a given scope. |
| 191 | func Paths(scope Scope) ([]string, error) { |
| 192 | var files []string |
| 193 | switch scope { |
| 194 | case GlobalScope: |
| 195 | xdg := os.Getenv("XDG_CONFIG_HOME") |
| 196 | if xdg != "" { |
| 197 | files = append(files, filepath.Join(xdg, "git/config")) |
| 198 | } |
| 199 | |
| 200 | home, err := os.UserHomeDir() |
| 201 | if err != nil { |
| 202 | return nil, err |
| 203 | } |
| 204 | |
| 205 | files = append(files, |
| 206 | filepath.Join(home, ".gitconfig"), |
| 207 | filepath.Join(home, ".config/git/config"), |
| 208 | ) |
| 209 | case SystemScope: |
| 210 | files = append(files, "/etc/gitconfig") |
| 211 | } |
| 212 | |
| 213 | return files, nil |
| 214 | } |
| 215 | |
| 216 | // Validate validates the fields and sets the default values. |
| 217 | func (c *Config) Validate() error { |