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

Method Update

pkg/cmd/auth/shared/gitcredentials/updater.go:36–61  ·  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

34// Update updates the git credentials for a given hostname, first by rejecting any existing credentials and then
35// approving the new credentials.
36func (u *Updater) Update(hostname, username, password string) error {
37 // clear previous cached credentials
38 if err := u.RejectExisting(hostname); err != nil {
39 return err
40 }
41
42 ctx := context.TODO()
43 approveCmd, err := u.GitClient.Command(ctx, "credential", "approve")
44 if err != nil {
45 return err
46 }
47
48 approveCmd.Stdin = bytes.NewBufferString(heredoc.Docf(`
49 protocol=https
50 host=%s
51 username=%s
52 password=%s
53 `, hostname, username, password))
54
55 _, err = approveCmd.Output()
56 if err != nil {
57 return err
58 }
59
60 return nil
61}

Callers 2

Calls 3

RejectExistingMethod · 0.95
CommandMethod · 0.80
OutputMethod · 0.65

Tested by 2