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

Method Update

pkg/cmd/auth/shared/gitcredentials/updater.go:18–55  ·  view source on GitHub ↗

Update updates the git credentials for a given hostname, first by rejecting any existing credentials and then approving the new credentials.

(hostname, username, password string)

Source from the content-addressed store, hash-verified

16// Update updates the git credentials for a given hostname, first by rejecting any existing credentials and then
17// approving the new credentials.
18func (u *Updater) Update(hostname, username, password string) error {
19 ctx := context.TODO()
20
21 // clear previous cached credentials
22 rejectCmd, err := u.GitClient.Command(ctx, "credential", "reject")
23 if err != nil {
24 return err
25 }
26
27 rejectCmd.Stdin = bytes.NewBufferString(heredoc.Docf(`
28 protocol=https
29 host=%s
30 `, hostname))
31
32 _, err = rejectCmd.Output()
33 if err != nil {
34 return err
35 }
36
37 approveCmd, err := u.GitClient.Command(ctx, "credential", "approve")
38 if err != nil {
39 return err
40 }
41
42 approveCmd.Stdin = bytes.NewBufferString(heredoc.Docf(`
43 protocol=https
44 host=%s
45 username=%s
46 password=%s
47 `, hostname, username, password))
48
49 _, err = approveCmd.Output()
50 if err != nil {
51 return err
52 }
53
54 return nil
55}

Callers 2

Calls 2

CommandMethod · 0.80
OutputMethod · 0.65

Tested by 2