@Override
protected void perform() {
String projName = (projFile != null)
? GitProjectUtils.getProjectName(projFile)
: null;
OutputLogger logger = getLogger();
try {
if (projName != null) {
logger.outputInRed(
NbBundle.getMessage(CloneAction.class,
"MSG_CLONE_FROM", projName, source)); // NOI18N
logger.outputInRed(
NbBundle.getMessage(CloneAction.class,
"MSG_CLONE_TO", projName, target)); // NOI18N
} else {
logger.outputInRed(
NbBundle.getMessage(CloneAction.class,
"MSG_EXTERNAL_CLONE_FROM", source)); // NOI18N
logger.outputInRed(
NbBundle.getMessage(CloneAction.class,
"MSG_EXTERNAL_CLONE_TO", target)); // NOI18N
}
logger.output(""); // NOI18N
doInit(repo, source, logger);
FetchResult r = doFetch(repo, logger);
Ref branch = r.getAdvertisedRef(Constants.HEAD);
if (branch == null) {
this.cancel();
}
doCheckout(repo, branch, logger);
if (isLocalClone) {
Git git = Git.getInstance();
ProjectManager projectManager = ProjectManager.getDefault();
File normalizedCloneFolder = FileUtil.normalizeFile(target);
File cloneProjFile;
if (!projIsRepos) {
String name = (projFile != null)
? projFile.getAbsolutePath().substring(source.getPath().length() + 1)
: target.getAbsolutePath();
cloneProjFile = new File(normalizedCloneFolder, name);
} else {
cloneProjFile = normalizedCloneFolder;
}
openProject(cloneProjFile, projectManager, git);
} else if (scanForProjects) {
CloneCompleted cc = new CloneCompleted(target);
if (isCanceled()) {
return;
}
cc.scanForProjects(this);
}
} catch (URISyntaxException usex) {
notifyLater(usex);
} catch (IOException ex) {
notifyLater(ex);
} finally {
if (!isLocalClone) {
logger.outputInRed(NbBundle.getMessage(CloneAction.class, "MSG_CLONE_DONE")); // NOI18N
logger.output(""); // NOI18N
}
}
}
private void openProject(final File cloneProjFile, final ProjectManager projectManager, final Git git) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
// Open and set focus on the cloned project if possible
OutputLogger logger = getLogger();
try {
FileObject cloneProj = FileUtil.toFileObject(cloneProjFile);
Project proj = null;
if (cloneProjFile != null && cloneProj != null) {
proj = projectManager.findProject(cloneProj);
}
if (proj != null) {
GitProjectUtils.openProject(proj, this, false);
// TODO: GitModuleConfig.getDefault().getSetMainProject()
git.versionedFilesChanged();
git.refreshAllAnnotations();
} else {
logger.outputInRed(NbBundle.getMessage(CloneAction.class, "MSG_EXTERNAL_CLONE_PRJ_NOT_FOUND_CANT_SETASMAIN")); // NOI18N
}
} catch (IOException ioe) {
notifyLater(ioe);
} finally {
logger.outputInRed(NbBundle.getMessage(CloneAction.class, "MSG_CLONE_DONE")); // NOI18N
logger.output(""); // NOI18N
}
}
});
}
};