MCPcopy Create free account
hub / github.com/go-git/go-git / LoadConfig

Function LoadConfig

config/config.go:163–188  ·  view source on GitHub ↗

LoadConfig loads a config file from a given scope. The returned Config, contains exclusively information from the given scope. If it couldn't find a config file to the given scope, an empty one is returned.

(scope Scope)

Source from the content-addressed store, hash-verified

161// contains exclusively information from the given scope. If it couldn't find a
162// config file to the given scope, an empty one is returned.
163func LoadConfig(scope Scope) (*Config, error) {
164 if scope == LocalScope {
165 return nil, fmt.Errorf("LocalScope should be read from the a ConfigStorer")
166 }
167
168 files, err := Paths(scope)
169 if err != nil {
170 return nil, err
171 }
172
173 for _, file := range files {
174 f, err := osfs.Default.Open(file)
175 if err != nil {
176 if os.IsNotExist(err) {
177 continue
178 }
179
180 return nil, err
181 }
182
183 defer f.Close()
184 return ReadConfig(f)
185 }
186
187 return NewConfig(), nil
188}
189
190// Paths returns the config file location for a given scope.
191func Paths(scope Scope) ([]string, error) {

Callers 2

TestLoadConfigXDGMethod · 0.85

Calls 5

PathsFunction · 0.85
ReadConfigFunction · 0.85
NewConfigFunction · 0.85
CloseMethod · 0.65
OpenMethod · 0.45

Tested by 2

TestLoadConfigXDGMethod · 0.68