MCPcopy Index your code
hub / github.com/cli/cli / ConfigureOurs

Method ConfigureOurs

pkg/cmd/auth/shared/gitcredentials/helper_config.go:22–65  ·  view source on GitHub ↗

ConfigureOurs sets up the git credential helper chain to use the GitHub CLI credential helper for git repositories including gists.

(hostname string)

Source from the content-addressed store, hash-verified

20// ConfigureOurs sets up the git credential helper chain to use the GitHub CLI credential helper for git repositories
21// including gists.
22func (hc *HelperConfig) ConfigureOurs(hostname string) error {
23 ctx := context.TODO()
24
25 credHelperKeys := []string{
26 keyFor(hostname),
27 }
28
29 gistHost := strings.TrimSuffix(ghinstance.GistHost(hostname), "/")
30 if strings.HasPrefix(gistHost, "gist.") {
31 credHelperKeys = append(credHelperKeys, keyFor(gistHost))
32 }
33
34 var configErr error
35
36 for _, credHelperKey := range credHelperKeys {
37 if configErr != nil {
38 break
39 }
40 // first use a blank value to indicate to git we want to sever the chain of credential helpers
41 preConfigureCmd, err := hc.GitClient.Command(ctx, "config", "--global", "--replace-all", credHelperKey, "")
42 if err != nil {
43 configErr = err
44 break
45 }
46 if _, err = preConfigureCmd.Output(); err != nil {
47 configErr = err
48 break
49 }
50
51 // second configure the actual helper for this host
52 configureCmd, err := hc.GitClient.Command(ctx,
53 "config", "--global", "--add",
54 credHelperKey,
55 fmt.Sprintf("!%s auth git-credential", shellQuote(hc.SelfExecutablePath)),
56 )
57 if err != nil {
58 configErr = err
59 } else {
60 _, configErr = configureCmd.Output()
61 }
62 }
63
64 return configErr
65}
66
67// A Helper represents a git credential helper configuration.
68type Helper struct {

Callers 2

TestMethod · 0.95

Implementers 2

HelperConfigpkg/cmd/auth/shared/gitcredentials/hel
FakeHelperConfigpkg/cmd/auth/shared/gitcredentials/fak

Calls 5

GistHostFunction · 0.92
keyForFunction · 0.85
shellQuoteFunction · 0.85
CommandMethod · 0.80
OutputMethod · 0.65

Tested by 1