X Tutup
Skip to content

Commit e28236a

Browse files
shaharyarahmed-botmislav
authored andcommitted
Check path for git executable before auth
There was a bug where if git was not installed then gh would do its authentication and try to configure git but would then find out that the git executable was not in PATH. Now gh checks to see if the git executable is in PATH before authenticating the user. If the git executable is in PATH the authentication continues as normal, if it is not in PATH then it prints out an error to the console: $ git executable not found in $PATH Resolves: cli#3818
1 parent 4fa984a commit e28236a

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

pkg/cmd/auth/login/login.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"io/ioutil"
77
"net/http"
8+
"os/exec"
89
"strings"
910

1011
"github.com/AlecAivazis/survey/v2"
@@ -70,6 +71,10 @@ func NewCmdLogin(f *cmdutil.Factory, runF func(*LoginOptions) error) *cobra.Comm
7071
$ gh auth login --hostname enterprise.internal
7172
`),
7273
RunE: func(cmd *cobra.Command, args []string) error {
74+
if !isGitInPath() {
75+
return errors.New("git executable not found in $PATH")
76+
}
77+
7378
if !opts.IO.CanPrompt() && !(tokenStdin || opts.Web) {
7479
return &cmdutil.FlagError{Err: errors.New("--web or --with-token required when not running interactively")}
7580
}
@@ -119,6 +124,11 @@ func NewCmdLogin(f *cmdutil.Factory, runF func(*LoginOptions) error) *cobra.Comm
119124
return cmd
120125
}
121126

127+
func isGitInPath() bool {
128+
_, err := exec.LookPath("git")
129+
return err == nil
130+
}
131+
122132
func loginRun(opts *LoginOptions) error {
123133
cfg, err := opts.Config()
124134
if err != nil {

0 commit comments

Comments
 (0)
X Tutup