Skip to content

Commit

Permalink
fix ssh
Browse files Browse the repository at this point in the history
  • Loading branch information
konradjniemiec committed Jul 10, 2024
1 parent 0c834ba commit 5133767
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions pkg/repo/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,23 +156,30 @@ func PrepareGithubRepo() (string, error) {
shouldClone = true
}
}

repoOwner, repoName := dot.GetRepoInfo()
githubRepoURL := fmt.Sprintf("https://github.com/%s/%s.git", repoOwner, repoName)

githubRepoURLSSH := fmt.Sprintf("git@github.com:%s/%s.git", repoOwner, repoName)
if shouldClone {
cloneOut, err := gitcli.Clone(githubRepoURL, repoPath)
// first try ssh clone
cloneOut, err := gitcli.Clone(githubRepoURLSSH, repoPath)
if err != nil {
fmt.Println(string(cloneOut))
return "", errors.Wrapf(err, "git clone %s to %s", githubRepoURL, repoPath)
// next try https
cloneOut2, err2 := gitcli.Clone(githubRepoURL, repoPath)
if err2 != nil {
fmt.Println("failed to clone via ssh, trying via https")
fmt.Println(string(cloneOut))
fmt.Println(string(cloneOut2))
return "", errors.Wrapf(err2, "git cloning %s to %s with both https and ssh, your git setup may be unreachable, or you haven't created a Lekko account and linked to github Help @ https://docs.lekko.com", githubRepoURL, repoPath)

}

Check failure on line 174 in pkg/repo/cmd.go

View workflow job for this annotation

GitHub Actions / build

unnecessary trailing newline (whitespace)
}
} else {
gitRepo, err := git.PlainOpen(repoPath)
if err == nil {
remote, err := gitRepo.Remote("origin")
if err == nil {
// TODO: support comparing ssh and https urls
if len(remote.Config().URLs) == 0 || remote.Config().URLs[0] != githubRepoURL {
if len(remote.Config().URLs) == 0 || (remote.Config().URLs[0] != githubRepoURL && remote.Config().URLs[0] != githubRepoURLSSH) {
return "", errors.Errorf("repo already exists at %s but with different origin: %s", repoPath, remote.Config().URLs[0])
}
if err := ResetAndClean(gitRepo); err != nil {
Expand All @@ -190,6 +197,8 @@ func PrepareGithubRepo() (string, error) {
return "", errors.Wrap(err, "checkout main")
}
if pullOut, err := gitcli.Pull(repoPath); err != nil {
fmt.Println("asdfjklasdfjklasdfjkl")
fmt.Println(remote.Config().URLs)
fmt.Println(string(pullOut))
return "", errors.Wrap(err, "pull")
}
Expand Down

0 comments on commit 5133767

Please sign in to comment.