From 348b19e54db0a131d035a3166e7881649d03bc9b Mon Sep 17 00:00:00 2001 From: David Corwin Date: Wed, 14 Jun 2017 02:21:48 -0500 Subject: [PATCH] Try to clone git repositories over SSH on failure (#671) * updated help message for `now switch` to reference the argument for the team as the slug instead of the id * try ssh if https does not work * add editor settings to .gitignore, update yarn.lock * reverting change to teams in separate pr * Removed unused ignored prop --- lib/git.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/git.js b/lib/git.js index 32c1961..2624569 100644 --- a/lib/git.js +++ b/lib/git.js @@ -9,7 +9,7 @@ const download = require('download') const tmp = require('tmp-promise') const isURL = require('is-url') -const cloneRepo = (parts, tmpDir) => +const cloneRepo = (parts, tmpDir, { ssh }) => new Promise((resolve, reject) => { let host @@ -24,7 +24,10 @@ const cloneRepo = (parts, tmpDir) => host = `github.com` } - const url = `https://${host}/${parts.main}` + const url = ssh + ? `git@${host}:${parts.main}` + : `https://${host}/${parts.main}` + const ref = parts.ref || (parts.type === 'Bitbucket' ? 'default' : 'master') const cmd = `git clone ${url} --single-branch ${ref}` @@ -131,7 +134,11 @@ const downloadRepo = async repoPath => { try { await cloneRepo(pathParts, tmpDir) } catch (err) { - gitInstalled = false + try { + await cloneRepo(pathParts, tmpDir, { ssh: true }) + } catch (err) { + gitInstalled = false + } } if (gitInstalled) {