Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions pkg/devspace/dependency/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,25 +118,30 @@ func DownloadDependency(ctx context.Context, workingDirectory string, source *la
Args: source.CloneArgs,
DisableShallow: source.DisableShallow,
})
if err != nil {
if statErr == nil {
log.Warnf("Error cloning or pulling git repository %s: %v", gitPath, err)
return getDependencyConfigPath(localPath, source)
}

if err != nil {
log.Warn("Error cloning repo: ", err)
newGitURL := switchURLType(gitPath)
log.Infof("Switching URL from %s to %s and will try cloning again", gitPath, newGitURL)
err = repo.Clone(ctx, git.CloneOptions{
URL: switchURLType(gitPath),
URL: newGitURL,
Tag: source.Tag,
Branch: source.Branch,
Commit: source.Revision,
Args: source.CloneArgs,
DisableShallow: source.DisableShallow,
})

if err != nil {
log.Warn("Failed to clone repo with both HTTPS and SSH URL. Please make sure if your git login or ssh setup is correct.")
if statErr == nil {
log.Warnf("Error cloning or pulling git repository %s: %v", gitPath, err)
return getDependencyConfigPath(localPath, source)
}

return "", errors.Wrap(err, "clone repository")
}
}

log.Debugf("Pulled %s", gitPath)
}
} else if source.Path != "" {
Expand Down
13 changes: 10 additions & 3 deletions pkg/util/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package git

import (
"context"
"github.com/loft-sh/loft-util/pkg/command"
"mvdan.cc/sh/v3/expand"
"os"
"strings"

"github.com/loft-sh/loft-util/pkg/command"
"mvdan.cc/sh/v3/expand"

"github.com/pkg/errors"
)

Expand Down Expand Up @@ -64,7 +65,13 @@ func (gr *GitCLIRepository) Clone(ctx context.Context, options CloneOptions) err
}

args = append(args, options.Args...)
out, err := command.CombinedOutput(ctx, gr.LocalPath, expand.ListEnviron(os.Environ()...), "git", args...)
// Below envvar are required to prevent git from prompting for user login or ssh
gitEnv := []string{
"GIT_TERMINAL_PROMPT=0",
"GIT_SSH_COMMAND=ssh -oBatchMode=yes",
}
gitEnv = append(gitEnv, os.Environ()...)
out, err := command.CombinedOutput(ctx, gr.LocalPath, expand.ListEnviron(gitEnv...), "git", args...)
if err != nil {
return errors.Errorf("Error running 'git %s': %v -> %s", strings.Join(args, " "), err, string(out))
}
Expand Down