mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-100279 git init
This commit is contained in:
@@ -18,7 +18,6 @@ package git4idea.actions;
|
||||
import com.intellij.notification.NotificationType;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.actionSystem.PlatformDataKeys;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.fileChooser.FileChooser;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
@@ -33,6 +32,7 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vcs.ProjectLevelVcsManager;
|
||||
import com.intellij.openapi.vcs.VcsDirectoryMapping;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.vcsUtil.VcsFileUtil;
|
||||
import git4idea.GitUtil;
|
||||
import git4idea.GitVcs;
|
||||
@@ -51,6 +51,7 @@ import java.util.List;
|
||||
*/
|
||||
public class GitInit extends DumbAwareAction {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(final AnActionEvent e) {
|
||||
Project project = e.getData(CommonDataKeys.PROJECT);
|
||||
if (project == null) {
|
||||
@@ -65,40 +66,41 @@ public class GitInit extends DumbAwareAction {
|
||||
if (baseDir == null) {
|
||||
baseDir = project.getBaseDir();
|
||||
}
|
||||
final VirtualFile root = FileChooser.chooseFile(fcd, project, baseDir);
|
||||
if (root == null) {
|
||||
return;
|
||||
}
|
||||
if (GitUtil.isUnderGit(root)) {
|
||||
final int v = Messages.showYesNoDialog(project,
|
||||
GitBundle.message("init.warning.already.under.git",
|
||||
StringUtil.escapeXml(root.getPresentableUrl())),
|
||||
GitBundle.getString("init.warning.title"),
|
||||
Messages.getWarningIcon());
|
||||
if (v != 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
doInit(project, fcd, baseDir, baseDir);
|
||||
}
|
||||
|
||||
Git git = ServiceManager.getService(Git.class);
|
||||
GitVcs vcs = GitVcs.getInstance(project);
|
||||
GitCommandResult result = git.init(project, root);
|
||||
if (!result.success()) {
|
||||
if (vcs != null && vcs.getExecutableValidator().checkExecutableAndNotifyIfNeeded()) {
|
||||
GitUIUtil.notify(GitVcs.IMPORTANT_ERROR_NOTIFICATION, project, "Git init failed", result.getErrorOutputAsHtmlString(),
|
||||
NotificationType.ERROR, null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
private static void doInit(final Project project, FileChooserDescriptor fcd, VirtualFile baseDir, final VirtualFile finalBaseDir) {
|
||||
FileChooser.chooseFile(fcd, project, baseDir, new Consumer<VirtualFile>() {
|
||||
@Override
|
||||
public void consume(final VirtualFile root) {
|
||||
if (GitUtil.isUnderGit(root) && Messages.showYesNoDialog(project,
|
||||
GitBundle.message("init.warning.already.under.git",
|
||||
StringUtil.escapeXml(root.getPresentableUrl())),
|
||||
GitBundle.getString("init.warning.title"),
|
||||
Messages.getWarningIcon()) != Messages.YES) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (project.isDefault()) {
|
||||
return;
|
||||
}
|
||||
final String path = root.equals(baseDir) ? "" : root.getPath();
|
||||
final Project finalProject = project;
|
||||
GitVcs.runInBackground(new Task.Backgroundable(finalProject, GitBundle.getString("common.refreshing")) {
|
||||
public void run(@NotNull ProgressIndicator indicator) {
|
||||
refreshAndConfigureVcsMappings(finalProject, root, path);
|
||||
GitCommandResult result = ServiceManager.getService(Git.class).init(project, root);
|
||||
if (!result.success()) {
|
||||
GitVcs vcs = GitVcs.getInstance(project);
|
||||
if (vcs != null && vcs.getExecutableValidator().checkExecutableAndNotifyIfNeeded()) {
|
||||
GitUIUtil.notify(GitVcs.IMPORTANT_ERROR_NOTIFICATION, project, "Git init failed", result.getErrorOutputAsHtmlString(),
|
||||
NotificationType.ERROR, null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (project.isDefault()) {
|
||||
return;
|
||||
}
|
||||
final String path = root.equals(finalBaseDir) ? "" : root.getPath();
|
||||
GitVcs.runInBackground(new Task.Backgroundable(project, GitBundle.getString("common.refreshing")) {
|
||||
@Override
|
||||
public void run(@NotNull ProgressIndicator indicator) {
|
||||
refreshAndConfigureVcsMappings(project, root, path);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user