Skip to content

Commit 05b4838

Browse files
committed
handle special case for authentication failed and mkdir
1 parent b16a41c commit 05b4838

File tree

4 files changed

+23
-11
lines changed

4 files changed

+23
-11
lines changed

pkg/git/GitBaseManager.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func (impl *GitManagerBaseImpl) Fetch(gitCtx GitContext, rootDir string) (respon
120120
}
121121
defer commonLibGitManager.DeleteTlsFiles(tlsPathInfo)
122122
output, errMsg, err := impl.runCommandWithCred(cmd, gitCtx.Username, gitCtx.Password, tlsPathInfo)
123-
if strings.Contains(output, LOCK_REF_MESSAGE) {
123+
if strings.Contains(output, util.LOCK_REF_MESSAGE) {
124124
impl.logger.Info("error in fetch, pruning local refs and retrying", "rootDir", rootDir)
125125
// running git remote prune origin and retrying fetch. gitHub issue - https://github.com/devtron-labs/devtron/issues/4605
126126
pruneCmd, pruneCmdCancel := impl.createCmdWithContext(gitCtx, "git", "-C", rootDir, "remote", "prune", "origin")
@@ -176,7 +176,7 @@ func (impl *GitManagerBaseImpl) LogMergeBase(gitCtx GitContext, rootDir, from st
176176

177177
func (impl *GitManagerBaseImpl) runCommandWithCred(cmd *exec.Cmd, userName, password string, tlsPathInfo *commonLibGitManager.TlsPathInfo) (response, errMsg string, err error) {
178178
cmd.Env = append(os.Environ(),
179-
fmt.Sprintf("GIT_ASKPASS=%s", GIT_ASK_PASS),
179+
fmt.Sprintf("GIT_ASKPASS=%s", util.GIT_ASK_PASS),
180180
fmt.Sprintf("GIT_USERNAME=%s", userName),
181181
fmt.Sprintf("GIT_PASSWORD=%s", password),
182182
)
@@ -205,9 +205,10 @@ func (impl *GitManagerBaseImpl) runCommand(cmd *exec.Cmd) (response, errMsg stri
205205
if !ok {
206206
return output, errMsg, err
207207
}
208-
if strings.Contains(output, AUTHENTICATION_FAILED_ERROR) {
209-
impl.logger.Errorw("authentication failed", "msg", string(outBytes), "err", err.Error())
210-
return output, "authentication failed", errors.New("authentication failed")
208+
customErrMsg := util.GetErrMsgFromCliMessage(output)
209+
if customErrMsg != "" {
210+
impl.logger.Errorw(customErrMsg, "msg", string(outBytes), "err", err.Error())
211+
return output, customErrMsg, errors.New(customErrMsg)
211212
}
212213
if exErr.Stderr == nil {
213214
return output, errMsg, err

pkg/git/GitCliManager.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,6 @@ func NewGitCliManagerImpl(baseManager GitManagerBase, logger *zap.SugaredLogger)
3838
}
3939
}
4040

41-
const (
42-
GIT_ASK_PASS = "/git-ask-pass.sh"
43-
AUTHENTICATION_FAILED_ERROR = "Authentication failed"
44-
LOCK_REF_MESSAGE = "cannot lock ref"
45-
)
46-
4741
func (impl *GitCliManagerImpl) Init(gitCtx GitContext, rootDir string, remoteUrl string, isBare bool) (string, error) {
4842
//-----------------
4943

util/Constants.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package util
2+
3+
const (
4+
GIT_ASK_PASS = "/git-ask-pass.sh"
5+
AUTHENTICATION_FAILED_ERROR = "Authentication failed"
6+
DIRECTORY_NOT_EXISTS_ERROR = "mkdir : no such file or directory"
7+
LOCK_REF_MESSAGE = "cannot lock ref"
8+
CHECK_REPO_MESSAGE_RESPONSE = "Please check if repo url is correct and you have proper access to it"
9+
)

util/ErrorUtil.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,16 @@ package util
1818

1919
import (
2020
"github.com/go-pg/pg"
21+
"strings"
2122
)
2223

2324
func IsErrNoRows(err error) bool {
2425
return pg.ErrNoRows == err
2526
}
27+
28+
func GetErrMsgFromCliMessage(cliMessage string) string {
29+
if strings.Contains(cliMessage, AUTHENTICATION_FAILED_ERROR) || strings.Contains(cliMessage, DIRECTORY_NOT_EXISTS_ERROR) {
30+
return CHECK_REPO_MESSAGE_RESPONSE
31+
}
32+
return ""
33+
}

0 commit comments

Comments
 (0)