MCPcopy Create free account
hub / github.com/cli/cli / ReadBranchConfig

Method ReadBranchConfig

git/client.go:439–459  ·  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

437// Downstream consumers of ReadBranchConfig should consider the behavior they desire if this errors,
438// as an empty config is not necessarily breaking.
439func (c *Client) ReadBranchConfig(ctx context.Context, branch string) (BranchConfig, error) {
440 prefix := regexp.QuoteMeta(fmt.Sprintf("branch.%s.", branch))
441 args := []string{"config", "--get-regexp", fmt.Sprintf("^%s(remote|merge|pushremote|%s)$", prefix, MergeBaseConfig)}
442 cmd, err := c.Command(ctx, args...)
443 if err != nil {
444 return BranchConfig{}, err
445 }
446
447 branchCfgOut, err := cmd.Output()
448 if err != nil {
449 // This is the error we expect if the git command does not run successfully.
450 // If the ExitCode is 1, then we just didn't find any config for the branch.
451 var gitError *GitError
452 if ok := errors.As(err, &gitError); ok && gitError.ExitCode != 1 {
453 return BranchConfig{}, err
454 }
455 return BranchConfig{}, nil
456 }
457
458 return parseBranchConfig(outputLines(branchCfgOut)), nil
459}
460
461func parseBranchConfig(branchConfigLines []string) BranchConfig {
462 var cfg BranchConfig

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected