MCPcopy
hub / github.com/cli/cli / setupGitRun

Function setupGitRun

pkg/cmd/auth/setupgit/setupgit.go:75–120  ·  view source on GitHub ↗
(opts *SetupGitOptions)

Source from the content-addressed store, hash-verified

73}
74
75func setupGitRun(opts *SetupGitOptions) error {
76 cfg, err := opts.Config()
77 if err != nil {
78 return err
79 }
80 authCfg := cfg.Authentication()
81 hostnames := authCfg.Hosts()
82
83 stderr := opts.IO.ErrOut
84 cs := opts.IO.ColorScheme()
85
86 // If a hostname was provided, we'll set up just that one
87 if opts.Hostname != "" {
88 if !opts.Force && !has(opts.Hostname, hostnames) {
89 return fmt.Errorf("You are not logged into the GitHub host %q. Run %s to authenticate or provide `--force`",
90 opts.Hostname,
91 cs.Bold(fmt.Sprintf("gh auth login -h %s", opts.Hostname)),
92 )
93 }
94
95 if err := opts.CredentialsHelperConfig.ConfigureOurs(opts.Hostname); err != nil {
96 return fmt.Errorf("failed to set up git credential helper: %s", err)
97 }
98
99 return nil
100 }
101
102 // Otherwise we'll set up any known hosts
103 if len(hostnames) == 0 {
104 fmt.Fprintf(
105 stderr,
106 "You are not logged into any GitHub hosts. Run %s to authenticate.\n",
107 cs.Bold("gh auth login"),
108 )
109
110 return cmdutil.SilentError
111 }
112
113 for _, hostname := range hostnames {
114 if err := opts.CredentialsHelperConfig.ConfigureOurs(hostname); err != nil {
115 return fmt.Errorf("failed to set up git credential helper: %s", err)
116 }
117 }
118
119 return nil
120}
121
122func has(needle string, haystack []string) bool {
123 for _, s := range haystack {

Callers 2

Test_setupGitRunFunction · 0.85
NewCmdSetupGitFunction · 0.85

Calls 8

hasFunction · 0.85
ColorSchemeMethod · 0.80
BoldMethod · 0.80
ConfigMethod · 0.65
AuthenticationMethod · 0.65
HostsMethod · 0.65
ErrorfMethod · 0.65
ConfigureOursMethod · 0.65

Tested by 1

Test_setupGitRunFunction · 0.68