|
18 | 18 | * |
19 | 19 | */ |
20 | 20 |
|
21 | | -/*global path*/ |
| 21 | +/*global path, jsPromise*/ |
22 | 22 |
|
23 | 23 | define(function (require, exports, module) { |
24 | 24 | const Dialogs = require("widgets/Dialogs"), |
@@ -388,6 +388,25 @@ define(function (require, exports, module) { |
388 | 388 | }); |
389 | 389 | } |
390 | 390 |
|
| 391 | + async function gitClone(url, cloneDIR) { |
| 392 | + try{ |
| 393 | + const cloneFolderExists = await _dirExists(cloneDIR); |
| 394 | + if(!cloneFolderExists) { |
| 395 | + await Phoenix.VFS.ensureExistsDirAsync(cloneDIR); |
| 396 | + } |
| 397 | + await jsPromise(ProjectManager.openProject(cloneDIR)); |
| 398 | + CommandManager.execute("git-clone-url", url, cloneDIR ); |
| 399 | + } catch (e) { |
| 400 | + setTimeout(async ()=>{ |
| 401 | + // we need this timeout as when user clicks clone in new project dialog, it will immediately |
| 402 | + // close the error dialog too as it dismisses itself. |
| 403 | + showErrorDialogue(Strings.ERROR_CLONING_TITLE, e.message || e); |
| 404 | + }, 100); |
| 405 | + console.error("git clone failed: ", url, cloneDIR, e); |
| 406 | + Metrics.countEvent(Metrics.EVENT_TYPE.NEW_PROJECT, "gitClone", "fail"); |
| 407 | + } |
| 408 | + } |
| 409 | + |
391 | 410 | function _getGitFolderName(gitURL) { |
392 | 411 | if (typeof gitURL !== 'string' || !gitURL.trim()) { |
393 | 412 | return ""; |
@@ -460,6 +479,7 @@ define(function (require, exports, module) { |
460 | 479 | exports.showFolderSelect = showFolderSelect; |
461 | 480 | exports.showErrorDialogue = showErrorDialogue; |
462 | 481 | exports.getGitCloneDir = getGitCloneDir; |
| 482 | + exports.gitClone = gitClone; |
463 | 483 | exports.setupExploreProject = defaultProjects.setupExploreProject; |
464 | 484 | exports.setupStartupProject = defaultProjects.setupStartupProject; |
465 | 485 | exports.alreadyExists = window.Phoenix.VFS.existsAsync; |
|
0 commit comments