ConfiguredHelper returns the configured git credential helper for a given hostname.
(hostname string)
| 90 | |
| 91 | // ConfiguredHelper returns the configured git credential helper for a given hostname. |
| 92 | func (hc *HelperConfig) ConfiguredHelper(hostname string) (Helper, error) { |
| 93 | ctx := context.TODO() |
| 94 | |
| 95 | hostHelperCmd, err := hc.GitClient.Config(ctx, keyFor(hostname)) |
| 96 | if hostHelperCmd != "" { |
| 97 | // TODO: This is a direct refactoring removing named and naked returns |
| 98 | // but we should probably look closer at the error handling here |
| 99 | return Helper{ |
| 100 | Cmd: hostHelperCmd, |
| 101 | }, err |
| 102 | } |
| 103 | |
| 104 | globalHelperCmd, err := hc.GitClient.Config(ctx, "credential.helper") |
| 105 | if globalHelperCmd != "" { |
| 106 | return Helper{ |
| 107 | Cmd: globalHelperCmd, |
| 108 | }, err |
| 109 | } |
| 110 | |
| 111 | return Helper{}, nil |
| 112 | } |
| 113 | |
| 114 | func keyFor(hostname string) string { |
| 115 | host := strings.TrimSuffix(ghinstance.HostPrefix(hostname), "/") |
no test coverage detected