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: #3818
This commit is contained in:
parent
4fa984a333
commit
e28236a447
1 changed files with 10 additions and 0 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue