diff --git a/internal/config/config.go b/internal/config/config.go index 587cc996b..6f60f14b5 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -176,6 +176,7 @@ func (c *AuthConfig) GitProtocol(hostname string) string { // This should not happen, as we know there is a default value for this key. // Perhaps it says something about our current default abstraction being not quite right? + // The defaults are also currently used to provide information about the config options. return "" } diff --git a/pkg/cmd/gist/clone/clone.go b/pkg/cmd/gist/clone/clone.go index 9b75a309c..cd477a745 100644 --- a/pkg/cmd/gist/clone/clone.go +++ b/pkg/cmd/gist/clone/clone.go @@ -80,10 +80,7 @@ func cloneRun(opts *CloneOptions) error { return err } hostname, _ := cfg.Authentication().DefaultHost() - protocol, err := cfg.GetOrDefault(hostname, "git_protocol") - if err != nil { - return err - } + protocol := cfg.Authentication().GitProtocol(hostname) gistURL = formatRemoteURL(hostname, gistURL, protocol) } diff --git a/pkg/cmd/pr/checkout/checkout.go b/pkg/cmd/pr/checkout/checkout.go index 193eea735..b91fb1765 100644 --- a/pkg/cmd/pr/checkout/checkout.go +++ b/pkg/cmd/pr/checkout/checkout.go @@ -84,7 +84,7 @@ func checkoutRun(opts *CheckoutOptions) error { if err != nil { return err } - protocol, _ := cfg.GetOrDefault(baseRepo.RepoHost(), "git_protocol") + protocol := cfg.Authentication().GitProtocol(baseRepo.RepoHost()) remotes, err := opts.Remotes() if err != nil { diff --git a/pkg/cmd/pr/create/create.go b/pkg/cmd/pr/create/create.go index 8c1047de7..81b2c05f3 100644 --- a/pkg/cmd/pr/create/create.go +++ b/pkg/cmd/pr/create/create.go @@ -761,7 +761,7 @@ func handlePush(opts CreateOptions, ctx CreateContext) error { return err } - cloneProtocol, _ := cfg.GetOrDefault(headRepo.RepoHost(), "git_protocol") + cloneProtocol := cfg.Authentication().GitProtocol(headRepo.RepoHost()) headRepoURL := ghrepo.FormatRemoteURL(headRepo, cloneProtocol) gitClient := ctx.GitClient origin, _ := remotes.FindByName("origin") diff --git a/pkg/cmd/repo/clone/clone.go b/pkg/cmd/repo/clone/clone.go index 174951243..298ca30de 100644 --- a/pkg/cmd/repo/clone/clone.go +++ b/pkg/cmd/repo/clone/clone.go @@ -129,10 +129,7 @@ func cloneRun(opts *CloneOptions) error { return err } - protocol, err = cfg.GetOrDefault(repo.RepoHost(), "git_protocol") - if err != nil { - return err - } + protocol = cfg.Authentication().GitProtocol(repo.RepoHost()) } wantsWiki := strings.HasSuffix(repo.RepoName(), ".wiki") @@ -166,10 +163,7 @@ func cloneRun(opts *CloneOptions) error { // If the repo is a fork, add the parent as an upstream remote and set the parent as the default repo. if canonicalRepo.Parent != nil { - protocol, err := cfg.GetOrDefault(canonicalRepo.Parent.RepoHost(), "git_protocol") - if err != nil { - return err - } + protocol := cfg.Authentication().GitProtocol(canonicalRepo.Parent.RepoHost()) upstreamURL := ghrepo.FormatRemoteURL(canonicalRepo.Parent, protocol) upstreamName := opts.UpstreamName diff --git a/pkg/cmd/repo/create/create.go b/pkg/cmd/repo/create/create.go index c050607ed..c96aeb3f9 100644 --- a/pkg/cmd/repo/create/create.go +++ b/pkg/cmd/repo/create/create.go @@ -395,11 +395,7 @@ func createFromScratch(opts *CreateOptions) error { } if opts.Clone { - protocol, err := cfg.GetOrDefault(repo.RepoHost(), "git_protocol") - if err != nil { - return err - } - + protocol := cfg.Authentication().GitProtocol(repo.RepoHost()) remoteURL := ghrepo.FormatRemoteURL(repo, protocol) if !opts.AddReadme && opts.LicenseTemplate == "" && opts.GitIgnoreTemplate == "" && opts.Template == "" { @@ -496,11 +492,7 @@ func createFromTemplate(opts *CreateOptions) error { } if opts.Clone { - protocol, err := cfg.GetOrDefault(repo.RepoHost(), "git_protocol") - if err != nil { - return err - } - + protocol := cfg.Authentication().GitProtocol(repo.RepoHost()) remoteURL := ghrepo.FormatRemoteURL(repo, protocol) if err := cloneWithRetry(opts, remoteURL, templateRepoMainBranch); err != nil { @@ -622,11 +614,7 @@ func createFromLocal(opts *CreateOptions) error { fmt.Fprintln(stdout, repo.URL) } - protocol, err := cfg.GetOrDefault(repo.RepoHost(), "git_protocol") - if err != nil { - return err - } - + protocol := cfg.Authentication().GitProtocol(repo.RepoHost()) remoteURL := ghrepo.FormatRemoteURL(repo, protocol) if opts.Interactive { diff --git a/pkg/cmd/repo/rename/rename.go b/pkg/cmd/repo/rename/rename.go index 973eb7bd6..8dbc1326d 100644 --- a/pkg/cmd/repo/rename/rename.go +++ b/pkg/cmd/repo/rename/rename.go @@ -149,10 +149,7 @@ func updateRemote(repo ghrepo.Interface, renamed ghrepo.Interface, opts *RenameO return nil, err } - protocol, err := cfg.GetOrDefault(repo.RepoHost(), "git_protocol") - if err != nil { - return nil, err - } + protocol := cfg.Authentication().GitProtocol(repo.RepoHost()) remotes, err := opts.Remotes() if err != nil {