diff --git a/api/git/git.go b/api/git/git.go index 142c1c67a..e79c60009 100644 --- a/api/git/git.go +++ b/api/git/git.go @@ -19,6 +19,10 @@ import ( "github.com/go-git/go-git/v5/storage/memory" ) +var ( + ErrAuthenticationFailure = errors.New("Authentication failed, please ensure that the git credentials are correct.") +) + type fetchOptions struct { repositoryUrl string username string @@ -57,6 +61,9 @@ func (c gitClient) download(ctx context.Context, dst string, opt cloneOptions) e _, err := git.PlainCloneContext(ctx, dst, false, &gitOptions) if err != nil { + if err.Error() == "authentication required" { + return ErrAuthenticationFailure + } return errors.Wrap(err, "failed to clone git repository") } @@ -79,6 +86,9 @@ func (c gitClient) latestCommitID(ctx context.Context, opt fetchOptions) (string refs, err := remote.List(listOptions) if err != nil { + if err.Error() == "authentication required" { + return "", ErrAuthenticationFailure + } return "", errors.Wrap(err, "failed to list repository refs") } diff --git a/api/git/types/types.go b/api/git/types/types.go index d24283b52..5e774d291 100644 --- a/api/git/types/types.go +++ b/api/git/types/types.go @@ -17,4 +17,8 @@ type RepoConfig struct { type GitAuthentication struct { Username string Password string + // Git credentials identifier when the value is not 0 + // When the value is 0, Username and Password are set without using saved credential + // This is introduced since 2.15.0 + GitCredentialID int `example:"0"` }