Skip to content

Commit

Permalink
chore: git clone working
Browse files Browse the repository at this point in the history
  • Loading branch information
abose committed Jan 13, 2025
1 parent 23b05e9 commit 289fdb9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/assets/new-project/assets/js/new-git-project.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
Expand Down
22 changes: 21 additions & 1 deletion src/extensionsIntegrated/Phoenix/new-project.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
*/

/*global path*/
/*global path, jsPromise*/

define(function (require, exports, module) {
const Dialogs = require("widgets/Dialogs"),
Expand Down Expand Up @@ -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 "";
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/nls/root/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down

0 comments on commit 289fdb9

Please sign in to comment.