mirror of
https://gitea.com/gitea/tea.git
synced 2025-02-27 20:21:17 +01:00
Fix helper panic (#676)
Fix helper on get login struct Reviewed-on: https://gitea.com/gitea/tea/pulls/676 Reviewed-by: techknowlogick <techknowlogick@noreply.gitea.com> Co-authored-by: Matheus Sampaio Queiroga <srherobrine20@gmail.com> Co-committed-by: Matheus Sampaio Queiroga <srherobrine20@gmail.com>
This commit is contained in:
parent
fe1928679a
commit
c2ddda6800
@ -91,7 +91,9 @@ var CmdLoginHelper = cli.Command{
|
||||
}
|
||||
|
||||
userConfig := config.GetLoginByHost(wants["host"])
|
||||
if len(userConfig.Token) == 0 {
|
||||
if userConfig == nil {
|
||||
log.Fatal("host not exists")
|
||||
} else if len(userConfig.Token) == 0 {
|
||||
log.Fatal("User no set")
|
||||
}
|
||||
|
||||
|
@ -23,35 +23,24 @@ func SetupHelper(login config.Login) (ok bool, err error) {
|
||||
return false, fmt.Errorf("Invalid gitea url")
|
||||
}
|
||||
|
||||
// get tea binary path
|
||||
var binPath string
|
||||
if binPath, err = os.Executable(); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// get all helper to URL in git config
|
||||
var currentHelpers []byte
|
||||
if currentHelpers, err = exec.Command("git", "config", "--global", "--get-all", fmt.Sprintf("credential.%s.helper", login.URL)).Output(); err != nil {
|
||||
return false, err
|
||||
currentHelpers = []byte{}
|
||||
}
|
||||
|
||||
// Check if ared added tea helper
|
||||
for _, line := range strings.Split(strings.ReplaceAll(string(currentHelpers), "\r", ""), "\n") {
|
||||
if strings.TrimSpace(line) == "" {
|
||||
continue
|
||||
} else if strings.HasPrefix(line, binPath) && strings.Contains(line[len(binPath):], "login helper") {
|
||||
if strings.HasSuffix(strings.TrimSpace(line), "login helper") {
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
|
||||
// Check if tea path have space, if have add quotes
|
||||
if strings.Contains(binPath, " ") {
|
||||
binPath = fmt.Sprintf("%q", binPath)
|
||||
}
|
||||
|
||||
// Add tea helper
|
||||
if _, err = exec.Command("git", "config", "--global", "--add", fmt.Sprintf("credential.%s.helper", login.URL), fmt.Sprintf("!%s login helper", binPath)).Output(); err != nil {
|
||||
return false, err
|
||||
if _, err = exec.Command("git", "config", "--global", fmt.Sprintf("credential.%s.helper", login.URL), "").Output(); err != nil {
|
||||
return false, fmt.Errorf("git config --global %s, error: %s", fmt.Sprintf("credential.%s.helper", login.URL), err)
|
||||
} else if _, err = exec.Command("git", "config", "--global", "--add", fmt.Sprintf("credential.%s.helper", login.URL), "!tea login helper").Output(); err != nil {
|
||||
return false, fmt.Errorf("git config --global --add %s %s, error: %s", fmt.Sprintf("credential.%s.helper", login.URL), "!tea login helper", err)
|
||||
}
|
||||
|
||||
return true, nil
|
||||
|
Loading…
Reference in New Issue
Block a user