MCPcopy
hub / github.com/cli/cli / ReadBranchConfig

Method ReadBranchConfig

git/client.go:383–403  ·  view source on GitHub ↗

ReadBranchConfig parses the `branch.BRANCH.(remote|merge|pushremote|gh-merge-base)` part of git config. If no branch config is found or there is an error in the command, it returns an empty BranchConfig. Downstream consumers of ReadBranchConfig should consider the behavior they desire if this errors

(ctx context.Context, branch string)

Source from the content-addressed store, hash-verified

381// Downstream consumers of ReadBranchConfig should consider the behavior they desire if this errors,
382// as an empty config is not necessarily breaking.
383func (c *Client) ReadBranchConfig(ctx context.Context, branch string) (BranchConfig, error) {
384 prefix := regexp.QuoteMeta(fmt.Sprintf("branch.%s.", branch))
385 args := []string{"config", "--get-regexp", fmt.Sprintf("^%s(remote|merge|pushremote|%s)$", prefix, MergeBaseConfig)}
386 cmd, err := c.Command(ctx, args...)
387 if err != nil {
388 return BranchConfig{}, err
389 }
390
391 branchCfgOut, err := cmd.Output()
392 if err != nil {
393 // This is the error we expect if the git command does not run successfully.
394 // If the ExitCode is 1, then we just didn't find any config for the branch.
395 var gitError *GitError
396 if ok := errors.As(err, &gitError); ok && gitError.ExitCode != 1 {
397 return BranchConfig{}, err
398 }
399 return BranchConfig{}, nil
400 }
401
402 return parseBranchConfig(outputLines(branchCfgOut)), nil
403}
404
405func parseBranchConfig(branchConfigLines []string) BranchConfig {
406 var cfg BranchConfig

Callers 1

Calls 4

CommandMethod · 0.95
parseBranchConfigFunction · 0.85
outputLinesFunction · 0.85
OutputMethod · 0.65

Tested by 1