in plugin/src/com/microsoft/alm/plugin/idea/git/ui/vcsimport/ImportPageModelImpl.java [211:287]
private void doImport(final Project project, final ServerContext context, final String repositoryName) {
new Task.Backgroundable(project, TfPluginBundle.message(TfPluginBundle.KEY_IMPORT_IMPORTING_PROJECT), true, PerformInBackgroundOption.DEAF) {
@Override
public void run(@NotNull final ProgressIndicator indicator) {
// Local context can change if the creation of the repo succeeds
ServerContext localContext = context;
String remoteUrlForDisplay = "";
try {
if (!projectSupportsGitRepos(project, context, indicator)) {
logger.error("doImport: the team project {} on collection {} , " +
"server {} does not support Git repositories or is not a hybrid project",
localContext.getTeamProjectReference().getName(),
localContext.getTeamProjectCollectionReference().getName(), localContext.getUri());
return;
}
final GitRepository repo = getRepositoryForProject(project);
final VirtualFile rootVirtualFile = repo != null ? repo.getRoot() : project.getBaseDir();
final GitRepository localRepository = repo != null ? repo :
setupGitRepositoryForProject(project, rootVirtualFile, localContext, indicator);
if (localRepository == null) {
logger.error("doImport: current project {} is not in a Git repository", project.getName());
return;
}
if (!doFirstCommitIfRequired(project, localRepository, rootVirtualFile, localContext, indicator)) {
logger.error("doImport: failed to do first commit on the local repository at: {}", localRepository.getRoot().getUrl());
return;
}
final com.microsoft.alm.sourcecontrol.webapi.model.GitRepository remoteRepository =
createRemoteGitRepo(project, context, localContext, indicator);
if (remoteRepository != null) {
//remote repo creation succeeded, save active context with the repository information
localContext = new ServerContextBuilder(localContext).uri(remoteRepository.getRemoteUrl()).repository(remoteRepository).build();
ServerContextManager.getInstance().add(localContext);
} else {
logger.error("doImport: failed to create remote repository with name: {} on server: {}, collection: {}",
repositoryName, localContext.getUri(), localContext.getTeamProjectCollectionReference().getName());
return;
}
if (!setupRemoteOnLocalRepo(project, localRepository, remoteRepository, localContext, indicator)) {
logger.error("doImport: failed to setup remote origin on local repository at: {} to point to remote repository: {}",
localRepository.getRoot().getUrl(), remoteRepository.getRemoteUrl());
return;
}
if (!pushChangesToRemoteRepo(project, localRepository, remoteRepository, localContext, indicator)) {
logger.error("doImport: failed to push changes to remote repository: {}", remoteRepository.getRemoteUrl());
return;
}
//all steps completed successfully
remoteUrlForDisplay = remoteRepository.getRemoteUrl();
} catch (Throwable unexpectedError) {
remoteUrlForDisplay = "";
logger.error("doImport: Unexpected error during import");
logger.warn("doImport", unexpectedError);
notifyImportError(project, TfPluginBundle.message(TfPluginBundle.KEY_IMPORT_ERRORS_UNEXPECTED, unexpectedError.getLocalizedMessage()));
} finally {
if (StringUtils.isNotEmpty(remoteUrlForDisplay)) {
// Notify the user that we are done and provide a link to the repo
VcsNotifier.getInstance(project).notifyImportantInfo(TfPluginBundle.message(TfPluginBundle.KEY_IMPORT_SUCCEEDED),
TfPluginBundle.message(TfPluginBundle.KEY_IMPORT_SUCCEEDED_MESSAGE, project.getName(), remoteUrlForDisplay, repositoryName),
NotificationListener.URL_OPENING_LISTENER);
}
}
}
}.queue();
}