diff --git a/pkg/cmd/auth/login/login.go b/pkg/cmd/auth/login/login.go index 995405021..7866682bf 100644 --- a/pkg/cmd/auth/login/login.go +++ b/pkg/cmd/auth/login/login.go @@ -5,6 +5,7 @@ import ( "fmt" "io/ioutil" "net/http" + "os/exec" "strings" "github.com/AlecAivazis/survey/v2" @@ -70,6 +71,10 @@ func NewCmdLogin(f *cmdutil.Factory, runF func(*LoginOptions) error) *cobra.Comm $ gh auth login --hostname enterprise.internal `), RunE: func(cmd *cobra.Command, args []string) error { + if !isGitInPath() { + return errors.New("git executable not found in $PATH") + } + if !opts.IO.CanPrompt() && !(tokenStdin || opts.Web) { return &cmdutil.FlagError{Err: errors.New("--web or --with-token required when not running interactively")} } @@ -119,6 +124,11 @@ func NewCmdLogin(f *cmdutil.Factory, runF func(*LoginOptions) error) *cobra.Comm return cmd } +func isGitInPath() bool { + _, err := exec.LookPath("git") + return err == nil +} + func loginRun(opts *LoginOptions) error { cfg, err := opts.Config() if err != nil {