diff --git a/src/assets/new-project/assets/js/new-git-project.js b/src/assets/new-project/assets/js/new-git-project.js index f21761b0d..76d51f91c 100644 --- a/src/assets/new-project/assets/js/new-git-project.js +++ b/src/assets/new-project/assets/js/new-git-project.js @@ -74,7 +74,7 @@ function desktopInit() { return; } const {clonePath, error} = await newProjectExtension.getGitCloneDir(newPath, websiteURLInput.value); - locationInput.fullPath = clonePath; + locationInput.clonePath = clonePath; locationInput.value = window.top.Phoenix.fs.getTauriPlatformPath(clonePath); locationInput.error = error; locationInput.originalPath = newPath; @@ -91,7 +91,7 @@ function desktopInit() { function _createProjectClicked() { localStorage.setItem(LAST_GIT_CLONE_BASE_DIR, locationInput.originalPath); - //newProjectExtension.gitClone(websiteURLInput.value, locationInput.value); + newProjectExtension.gitClone(websiteURLInput.value, locationInput.clonePath); Metrics.countEvent(Metrics.EVENT_TYPE.NEW_PROJECT, "git.Click", "create"); newProjectExtension.closeDialogue(); } diff --git a/src/extensionsIntegrated/Phoenix/new-project.js b/src/extensionsIntegrated/Phoenix/new-project.js index c9543d10f..09a126a34 100644 --- a/src/extensionsIntegrated/Phoenix/new-project.js +++ b/src/extensionsIntegrated/Phoenix/new-project.js @@ -18,7 +18,7 @@ * */ -/*global path*/ +/*global path, jsPromise*/ define(function (require, exports, module) { const Dialogs = require("widgets/Dialogs"), @@ -388,6 +388,25 @@ define(function (require, exports, module) { }); } + async function gitClone(url, cloneDIR) { + try{ + const cloneFolderExists = await _dirExists(cloneDIR); + if(!cloneFolderExists) { + await Phoenix.VFS.ensureExistsDirAsync(cloneDIR); + } + await jsPromise(ProjectManager.openProject(cloneDIR)); + CommandManager.execute("git-clone-url", url, cloneDIR ); + } catch (e) { + setTimeout(async ()=>{ + // we need this timeout as when user clicks clone in new project dialog, it will immediately + // close the error dialog too as it dismisses itself. + showErrorDialogue(Strings.ERROR_CLONING_TITLE, e.message || e); + }, 100); + console.error("git clone failed: ", url, cloneDIR, e); + Metrics.countEvent(Metrics.EVENT_TYPE.NEW_PROJECT, "gitClone", "fail"); + } + } + function _getGitFolderName(gitURL) { if (typeof gitURL !== 'string' || !gitURL.trim()) { return ""; @@ -460,6 +479,7 @@ define(function (require, exports, module) { exports.showFolderSelect = showFolderSelect; exports.showErrorDialogue = showErrorDialogue; exports.getGitCloneDir = getGitCloneDir; + exports.gitClone = gitClone; exports.setupExploreProject = defaultProjects.setupExploreProject; exports.setupStartupProject = defaultProjects.setupStartupProject; exports.alreadyExists = window.Phoenix.VFS.existsAsync; diff --git a/src/nls/root/strings.js b/src/nls/root/strings.js index 201b3ea73..e94739146 100644 --- a/src/nls/root/strings.js +++ b/src/nls/root/strings.js @@ -1198,6 +1198,7 @@ define({ "ERROR_GIT_URL_INVALID": "Please enter a valid Git clone URL.", "ERROR_GIT_FOLDER_NOT_EMPTY": "The Selected folder cannot be used for Git clone as it is not empty or is unreadable.", "ERROR_GIT_FOLDER_NOT_EXIST": "The Selected folder cannot be used for Git clone as it does not exist.", + "ERROR_CLONING_TITLE": "Git clone Failed", "DOWNLOADING": "Downloading...", "DOWNLOADING_FILE": "Downloading {0}...", "EXTRACTING_FILES_PROGRESS": "Extracting {0} of {1} files.",