From 0a73192ace090d1ef288dcc00e12125a389c3379 Mon Sep 17 00:00:00 2001 From: Ilya Trushchenko Date: Mon, 15 Aug 2022 14:12:19 -0400 Subject: [PATCH] fix protocol not being set when token is read from stdin --- pkg/cmd/auth/login/login.go | 4 +++- pkg/cmd/auth/login/login_test.go | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pkg/cmd/auth/login/login.go b/pkg/cmd/auth/login/login.go index 474c21588..6d88873e5 100644 --- a/pkg/cmd/auth/login/login.go +++ b/pkg/cmd/auth/login/login.go @@ -152,7 +152,9 @@ func loginRun(opts *LoginOptions) error { if err := shared.HasMinimumScopes(httpClient, hostname, opts.Token); err != nil { return fmt.Errorf("error validating token: %w", err) } - + if opts.GitProtocol != "" { + cfg.Set(hostname, "git_protocol", opts.GitProtocol) + } return cfg.Write() } diff --git a/pkg/cmd/auth/login/login_test.go b/pkg/cmd/auth/login/login_test.go index 4a48aece7..376ddf10e 100644 --- a/pkg/cmd/auth/login/login_test.go +++ b/pkg/cmd/auth/login/login_test.go @@ -232,6 +232,18 @@ func Test_loginRun_nontty(t *testing.T) { }, wantHosts: "github.com:\n oauth_token: abc123\n", }, + { + name: "with token and https git-protocol", + opts: &LoginOptions{ + Hostname: "github.com", + Token: "abc123", + GitProtocol: "https", + }, + httpStubs: func(reg *httpmock.Registry) { + reg.Register(httpmock.REST("GET", ""), httpmock.ScopesResponder("repo,read:org")) + }, + wantHosts: "github.com:\n oauth_token: abc123\n git_protocol: https\n", + }, { name: "with token and non-default host", opts: &LoginOptions{