gaia-pipeline/gaia

Cloning fails if the host file isn't working and it tries to clone again

Skarlso opened this issue · 1 comments

This part of the code:

	// Clone repo
	_, err = git.PlainClone(repo.LocalDest, false, o)
	if err != nil {
		if strings.Contains(err.Error(), "knownhosts: key is unknown") {
			gaia.Cfg.Logger.Warn("Warning: Unknown host key.", "error", err.Error(), "URL", repo.URL)
			auth, err = getAuthInfo(repo, gossh.InsecureIgnoreHostKey())
			if err != nil {
				return err
			}
			o.Auth = auth
			// Clone repo again with no host key verification.
			_, err = git.PlainClone(repo.LocalDest, false, o)
			if err != nil {
				return err
			}
		} else {
			return err
		}
	}

Causes a second clone and that second clone fails because the storer is not empty ( a git SDK term where they initialise the store with the local folder and doing that again is apparently an error ). The error is:

cannot prepare build: repository already exists

A workaround is to add github to the known_host file for now:

ssh-keyscan github.com >> ~/.ssh/known_hosts