diff --git a/bin/win/idea.bat b/bin/win/idea.bat index 632ae9142b2d..b849c97c2729 100644 --- a/bin/win/idea.bat +++ b/bin/win/idea.bat @@ -6,7 +6,7 @@ :: --------------------------------------------------------------------- :: Before you run IntelliJ IDEA specify the location of the -:: JDK 1.5 installation directory which will be used for running IDEA +:: JDK 1.6 installation directory which will be used for running IDEA :: --------------------------------------------------------------------- IF "%IDEA_JDK%" == "" SET IDEA_JDK=%JDK_HOME% IF "%IDEA_JDK%" == "" goto error diff --git a/build/Install-Linux-tar.txt b/build/Install-Linux-tar.txt new file mode 100644 index 000000000000..d51b005ba33d --- /dev/null +++ b/build/Install-Linux-tar.txt @@ -0,0 +1,51 @@ +IntelliJ IDEA + +INSTALLATION INSTRUCTIONS +=============================================================================== + + Linux Installation Instructions + ------------------------------------------------------------------------------ + 1. Unpack the IntelliJ IDEA distribution file that you downloaded to + where you wish to install the program. We will refer to this destination + location as your {installation home} below. + + 2. Open a console and cd into "{installation home}/bin" and type: + + ./idea.sh + + to start the application. + + 3. [OPTIONAL] Add the "{installation home}/bin" to your PATH environmental + variable so that you may start IntelliJ IDEA from any directory. + + 4. [OPTIONAL] To adjust the value of JVM heap size open idea.vmoptions and + modify the -Xms and -Xmx parameters. + + + [OPTIONAL] Changing location of "config" and "system" directory + ------------------------------------------------------------------------------ + By default IDEA stores all your settings under ~/.IntelliJIdea10/config directory + and stores data cache under ~/.IntelliJIdea10/system directory. + If you want to change these settings, + + 1. Open a console and cd into "{installation home}/bin" + + 2. Open file "idea.properties" in an editor. You should find strings like + + idea.system.path=~/.IntelliJIdea10/system + + and + + idea.config.path=~/.IntelliJIdea10/config + + and change them. + + 3. Note that we recommend to store data cache ("system" directory) at a disk + with at least 1G bytes free space + + + + +Enjoy! + +-IntelliJ IDEA Development Team diff --git a/build/scripts/dist.gant b/build/scripts/dist.gant index d2635baf3b05..bd8d82c0364d 100644 --- a/build/scripts/dist.gant +++ b/build/scripts/dist.gant @@ -198,6 +198,7 @@ def layoutLinux(Map args, String home, Paths paths) { fileset(dir: "$home/bin/nix") fileset(dir: "$home/build/images") } + fileset(dir: "$home/build", includes: "Install-Linux-tar.txt") } patchPropertiesFile(paths.distUnix) diff --git a/community-resources/src/idea/IdeaApplicationInfo.xml b/community-resources/src/idea/IdeaApplicationInfo.xml index 1bcdca8d3b40..3ab6ac4dd875 100644 --- a/community-resources/src/idea/IdeaApplicationInfo.xml +++ b/community-resources/src/idea/IdeaApplicationInfo.xml @@ -18,8 +18,8 @@ - + diff --git a/java/java-impl/src/com/intellij/psi/formatter/java/BlockContainingJavaBlock.java b/java/java-impl/src/com/intellij/psi/formatter/java/BlockContainingJavaBlock.java index c8b11d1f9f08..b5c7822cbb01 100644 --- a/java/java-impl/src/com/intellij/psi/formatter/java/BlockContainingJavaBlock.java +++ b/java/java-impl/src/com/intellij/psi/formatter/java/BlockContainingJavaBlock.java @@ -17,12 +17,15 @@ package com.intellij.psi.formatter.java; import com.intellij.formatting.*; import com.intellij.lang.ASTNode; +import com.intellij.psi.JavaTokenType; import com.intellij.psi.codeStyle.CodeStyleSettings; import com.intellij.psi.formatter.FormatterUtil; import com.intellij.psi.impl.source.tree.ElementType; import com.intellij.psi.impl.source.tree.JavaDocElementType; +import com.intellij.psi.impl.source.tree.JavaElementType; import com.intellij.psi.impl.source.tree.StdTokenSets; import com.intellij.psi.tree.IElementType; +import com.intellij.psi.tree.TokenSet; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; @@ -30,6 +33,10 @@ import java.util.List; public class BlockContainingJavaBlock extends AbstractJavaBlock{ + private static final TokenSet TYPES_OF_STATEMENTS_WITH_OPTIONAL_BRACES = TokenSet.create( + JavaElementType.IF_STATEMENT, JavaElementType.WHILE_STATEMENT, JavaElementType.FOR_STATEMENT + ); + private final static int BEFORE_FIRST = 0; private final static int BEFORE_BLOCK = 1; private final static int AFTER_ELSE = 2; @@ -207,12 +214,37 @@ public class BlockContainingJavaBlock extends AbstractJavaBlock{ return new ChildAttributes(getCodeBlockExternalIndent(), null); } + boolean useExternalIndent = false; if (newChildIndex == getSubBlocks().size()) { + useExternalIndent = true; + } + else if (TYPES_OF_STATEMENTS_WITH_OPTIONAL_BRACES.contains(myNode.getElementType())) { + // There is a possible case that we have situation like below: + // if (true) + // + // System.out.println(); + // We would like to indent current caret position then because there is a high probability that the user starts + // typing there (populating statement body). So, we perform dedicated check for that here and use 'external indent' + // if necessary. + Block prevBlock = getSubBlocks().get(newChildIndex - 1); + Block nextBlock = getSubBlocks().get(newChildIndex); + if (prevBlock instanceof ASTBlock && nextBlock instanceof ASTBlock) { + ASTNode prevNode = ((ASTBlock)prevBlock).getNode(); + ASTNode nextNode = ((ASTBlock)nextBlock).getNode(); + if (prevNode != null && nextNode != null && prevNode.getElementType() == JavaTokenType.RPARENTH + && nextNode.getElementType() != JavaTokenType.LBRACE) + { + useExternalIndent = true; + } + } + } + + if (useExternalIndent) { return new ChildAttributes(getCodeBlockChildExternalIndent(newChildIndex), null); } - - return new ChildAttributes(myIndentsBefore.get(newChildIndex), null); - + else { + return new ChildAttributes(myIndentsBefore.get(newChildIndex), null); + } } private boolean isInsideForParens(final int newChildIndex) { diff --git a/java/testFramework/src/com/intellij/codeInsight/CodeInsightTestCase.java b/java/testFramework/src/com/intellij/codeInsight/CodeInsightTestCase.java index 4cbcebdc186a..6028e2bfb1c3 100644 --- a/java/testFramework/src/com/intellij/codeInsight/CodeInsightTestCase.java +++ b/java/testFramework/src/com/intellij/codeInsight/CodeInsightTestCase.java @@ -240,8 +240,7 @@ public abstract class CodeInsightTestCase extends PsiTestCase { } })); - // grand VFS refresh significantly slows down local tests and generally not needed - //VirtualFileManager.getInstance().refresh(false); + toDir.refresh(false, true); } else { editorInfos = new LinkedHashMap(); diff --git a/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java b/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java index 118d3202931d..a47d2d76d7e6 100644 --- a/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java @@ -595,13 +595,6 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro public static File createTempDir(@NonNls final String prefix) throws IOException { final File tempDirectory = FileUtil.createTempDirectory(TEST_DIR_PREFIX + prefix, null); myFilesToDelete.add(tempDirectory); - // grand VFS refresh significantly slows down local tests and generally not needed - //ApplicationManager.getApplication().runWriteAction(new Runnable() { - // @Override - // public void run() { - // VirtualFileManager.getInstance().refresh(false); - // } - //}); return tempDirectory; } diff --git a/plugins/android/src/org/jetbrains/android/run/AndroidRunningState.java b/plugins/android/src/org/jetbrains/android/run/AndroidRunningState.java index a583f1ebb399..38b51eaaa21e 100644 --- a/plugins/android/src/org/jetbrains/android/run/AndroidRunningState.java +++ b/plugins/android/src/org/jetbrains/android/run/AndroidRunningState.java @@ -613,6 +613,29 @@ public abstract class AndroidRunningState implements RunProfileState, AndroidDeb return true; } + private class MyISyncProgressMonitor implements SyncService.ISyncProgressMonitor { + @Override + public void start(int totalWork) { + } + + @Override + public void stop() { + } + + @Override + public boolean isCanceled() { + return myStopped; + } + + @Override + public void startSubTask(String name) { + } + + @Override + public void advance(int work) { + } + } + private boolean uploadApp(IDevice device, String remotePath, String localPath) throws IOException { if (myStopped) return false; getProcessHandler().notifyTextAvailable("Uploading file\n\tlocal path: " + localPath + "\n\tremote path: " + remotePath + '\n', STDOUT); @@ -621,12 +644,57 @@ public abstract class AndroidRunningState implements RunProfileState, AndroidDeb getProcessHandler().notifyTextAvailable("Can't upload file: device is not available.\n", STDERR); return false; } - SyncService.SyncResult result = service.pushFile(localPath, remotePath, SyncService.getNullProgressMonitor()); - if (result.getCode() != SyncService.RESULT_OK) { - getProcessHandler().notifyTextAvailable("Can't upload file: " + result.getMessage() + ".\n", STDERR); - return false; + SyncService.SyncResult result = service.pushFile(localPath, remotePath, new MyISyncProgressMonitor()); + int code = result.getCode(); + String errorMessage; + switch (code) { + case SyncService.RESULT_OK: + return true; + case SyncService.RESULT_CANCELED: + errorMessage = "Command canceled"; + break; + case SyncService.RESULT_CONNECTION_ERROR: + errorMessage = "Connection error"; + break; + case SyncService.RESULT_CONNECTION_TIMEOUT: + errorMessage = "Connection timeout"; + break; + case SyncService.RESULT_FILE_READ_ERROR: + errorMessage = "Cannot read the file"; + break; + case SyncService.RESULT_FILE_WRITE_ERROR: + errorMessage = "Cannot write the file"; + break; + case SyncService.RESULT_LOCAL_IS_DIRECTORY: + errorMessage = "Local is directory"; + break; + case SyncService.RESULT_NO_DIR_TARGET: + errorMessage = "Target directory not found"; + break; + case SyncService.RESULT_NO_LOCAL_FILE: + errorMessage = "Local file not found"; + break; + case SyncService.RESULT_NO_REMOTE_OBJECT: + errorMessage = "No remote object"; + break; + case SyncService.RESULT_REMOTE_IS_FILE: + errorMessage = "Remote is a file"; + break; + case SyncService.RESULT_REMOTE_PATH_ENCODING: + errorMessage = "Incorrect remote path encoding"; + break; + case SyncService.RESULT_REMOTE_PATH_LENGTH: + errorMessage = "Incorrect remote path length"; + break; + case SyncService.RESULT_TARGET_IS_FILE: + errorMessage = "Target is a file"; + break; + default: + errorMessage = "Can't upload file"; } - return true; + getProcessHandler() + .notifyTextAvailable(errorMessage + (result.getMessage() != null ? "\n" + result.getMessage() + "\n" : "\n"), STDERR); + return false; } @SuppressWarnings({"DuplicateThrows"}) @@ -676,13 +744,13 @@ public abstract class AndroidRunningState implements RunProfileState, AndroidDeb executeDeviceCommandAndWriteToConsole(device, "pm install -r \"" + remotePath + '\"', receiver); if (myStopped) return false; }*/ - if (!isSuccess(receiver)) { + /*if (!isSuccess(receiver)) { getProcessHandler().notifyTextAvailable("Can't reinstall application. Installing from scratch.\n", STDOUT); executeDeviceCommandAndWriteToConsole(device, "pm uninstall \"" + remotePath + '\"', receiver); if (myStopped) return false; executeDeviceCommandAndWriteToConsole(device, "pm install \"" + remotePath + '\"', receiver); if (myStopped) return false; - } + }*/ boolean success = isSuccess(receiver); getProcessHandler().notifyTextAvailable(receiver.output.toString(), success ? STDOUT : STDERR); return success; diff --git a/plugins/android/src/org/jetbrains/android/sdk/AndroidSdk.java b/plugins/android/src/org/jetbrains/android/sdk/AndroidSdk.java index 6ccea9c53dda..079fdfc678d1 100644 --- a/plugins/android/src/org/jetbrains/android/sdk/AndroidSdk.java +++ b/plugins/android/src/org/jetbrains/android/sdk/AndroidSdk.java @@ -17,6 +17,7 @@ package org.jetbrains.android.sdk; import com.android.ddmlib.AndroidDebugBridge; +import com.android.ddmlib.DdmPreferences; import com.android.sdklib.IAndroidTarget; import com.android.sdklib.ISdkLog; import com.android.sdklib.SdkConstants; @@ -145,6 +146,7 @@ public abstract class AndroidSdk { String adbPath = getAdbPath(); if (!myDdmLibInitialized) { myDdmLibInitialized = true; + DdmPreferences.setTimeOut(AndroidUtils.TIMEOUT); AndroidDebugBridge.init(AndroidEnableDdmsAction.isDdmsEnabled()); AndroidDebugBridge.createBridge(adbPath, true); } diff --git a/plugins/android/src/org/jetbrains/android/util/AndroidUtils.java b/plugins/android/src/org/jetbrains/android/util/AndroidUtils.java index 38eda83180d4..282462bf5874 100644 --- a/plugins/android/src/org/jetbrains/android/util/AndroidUtils.java +++ b/plugins/android/src/org/jetbrains/android/util/AndroidUtils.java @@ -119,7 +119,7 @@ public class AndroidUtils { public static final String EXT_NATIVE_LIB = "so"; @NonNls public static final String RES_OVERLAY_DIR_NAME = "res-overlay"; - private static final int TIMEOUT = 30000; + public static final int TIMEOUT = 30000; private AndroidUtils() { } diff --git a/plugins/github/src/META-INF/plugin.xml b/plugins/github/src/META-INF/plugin.xml index c001c3a27454..fef2a86bae91 100644 --- a/plugins/github/src/META-INF/plugin.xml +++ b/plugins/github/src/META-INF/plugin.xml @@ -23,6 +23,9 @@ + + + \ No newline at end of file diff --git a/plugins/github/src/org/jetbrains/plugins/github/GithubOpenInBrowserAction.java b/plugins/github/src/org/jetbrains/plugins/github/GithubOpenInBrowserAction.java new file mode 100644 index 000000000000..872557ced4ac --- /dev/null +++ b/plugins/github/src/org/jetbrains/plugins/github/GithubOpenInBrowserAction.java @@ -0,0 +1,136 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.plugins.github; + +import com.intellij.ide.BrowserUtil; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.PlatformDataKeys; +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.project.DumbAwareAction; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.roots.ProjectRootManager; +import com.intellij.openapi.ui.Messages; +import com.intellij.openapi.util.IconLoader; +import com.intellij.openapi.vcs.VcsException; +import com.intellij.openapi.vfs.VirtualFile; +import git4idea.GitRemote; +import git4idea.GitUtil; + +import javax.swing.*; +import java.util.List; + +/** + * Created by IntelliJ IDEA. + * + * @author oleg + * @date 12/10/10 + */ +public class GithubOpenInBrowserAction extends DumbAwareAction { + public static final Icon ICON = IconLoader.getIcon("/icons/github.png"); + private static final Logger LOG = Logger.getInstance(GithubOpenInBrowserAction.class.getName()); + private static final String CANNOT_OPEN_IN_BROWSER = "Cannot open in browser"; + + protected GithubOpenInBrowserAction() { + super("Open in browser", "Open corresponding GitHub link in browser", ICON); + } + + @Override + public void update(final AnActionEvent e) { + final Project project = e.getData(PlatformDataKeys.PROJECT); + final VirtualFile virtualFile = e.getData(PlatformDataKeys.VIRTUAL_FILE); + if (project == null || project.isDefault() || virtualFile == null) { + e.getPresentation().setEnabled(false); + return; + } + if (GithubUtil.getGithubBoundRepository(project) == null){ + e.getPresentation().setEnabled(false); + return; + } + e.getPresentation().setEnabled(true); + } + + @Override + public void actionPerformed(final AnActionEvent e) { + final Project project = e.getData(PlatformDataKeys.PROJECT); + + final VirtualFile[] roots = ProjectRootManager.getInstance(project).getContentRoots(); + if (roots.length == 0) { + Messages.showErrorDialog(project, "Project doesn't have any project roots", CANNOT_OPEN_IN_BROWSER); + return; + } + final VirtualFile root = roots[0]; + // Check if git is already initialized and presence of remote branch + final boolean gitDetected = GitUtil.isUnderGit(root); + if (!gitDetected) { + Messages.showErrorDialog(project, "Cannot find any git repository configured for the project", CANNOT_OPEN_IN_BROWSER); + return; + } + final VirtualFile virtualFile = e.getData(PlatformDataKeys.VIRTUAL_FILE); + final String rootPath = root.getPath(); + final String path = virtualFile.getPath(); + if (!path.startsWith(rootPath)){ + Messages.showErrorDialog(project, "File is not under project root", CANNOT_OPEN_IN_BROWSER); + return; + } + + + try { + // Check that given repository is properly configured git repository + GitRemote githubRemote = null; + final List gitRemotes = GitRemote.list(project, root); + if (gitRemotes.isEmpty()) { + Messages.showErrorDialog(project, "Git repository doesn't have any remotes configured", CANNOT_OPEN_IN_BROWSER); + return; + } + for (GitRemote gitRemote : gitRemotes) { + if (gitRemote.pushUrl().contains("git@github.com")) { + githubRemote = gitRemote; + break; + } + } + if (githubRemote == null) { + Messages.showErrorDialog(project, "Configured own github repository is not found", CANNOT_OPEN_IN_BROWSER); + return; + } + + final String pushUrl = githubRemote.pushUrl(); + final String login = GithubSettings.getInstance().getLogin(); + final int index = pushUrl.lastIndexOf(login); + if (index == -1) { + Messages.showErrorDialog(project, "Github remote repository doesn't seem to be your own repository: " + pushUrl, + CANNOT_OPEN_IN_BROWSER); + return; + } + String repoName = pushUrl.substring(index + login.length() + 1); + if (repoName.endsWith(".git")) { + repoName = repoName.substring(0, repoName.length() - 4); + } + final RepositoryInfo repositoryInfo = GithubUtil.getDetailedRepositoryInfo(project, repoName); + if (repositoryInfo == null) { + Messages + .showErrorDialog(project, "Github repository doesn't seem to be your own repository: " + pushUrl, CANNOT_OPEN_IN_BROWSER); + return; + } + // TODO[oleg] support custom branches here + BrowserUtil.launchBrowser("https://github.com/" + login + "/" + repoName + "/blob/master" + path.substring(rootPath.length())); + + } catch (VcsException e1){ + Messages.showErrorDialog(project, "Error happened during git operation: " + e1.getMessage(), CANNOT_OPEN_IN_BROWSER); + return; + } + + } +} diff --git a/plugins/github/src/org/jetbrains/plugins/github/GithubRebaseAction.java b/plugins/github/src/org/jetbrains/plugins/github/GithubRebaseAction.java index fe1c677fc9e6..89defbbbe16e 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/GithubRebaseAction.java +++ b/plugins/github/src/org/jetbrains/plugins/github/GithubRebaseAction.java @@ -26,7 +26,6 @@ import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.IconLoader; import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vfs.VirtualFile; -import git4idea.GitBranch; import git4idea.GitRemote; import git4idea.GitUtil; import git4idea.actions.BasicAction; @@ -45,6 +44,7 @@ import java.util.List; public class GithubRebaseAction extends DumbAwareAction { public static final Icon ICON = IconLoader.getIcon("/icons/github.png"); private static final Logger LOG = Logger.getInstance(GithubRebaseAction.class.getName()); + private static final String CANNOT_PERFORM_GITHUB_REBASE = "Cannot perform github rebase"; public GithubRebaseAction() { super("Rebase my fork", "Rebase your forked repository relative to the origin", ICON); @@ -56,6 +56,10 @@ public class GithubRebaseAction extends DumbAwareAction { e.getPresentation().setEnabled(false); return; } + if (GithubUtil.getGithubBoundRepository(project) == null){ + e.getPresentation().setEnabled(false); + return; + } e.getPresentation().setEnabled(true); } @@ -64,54 +68,29 @@ public class GithubRebaseAction extends DumbAwareAction { final Project project = e.getData(PlatformDataKeys.PROJECT); final VirtualFile[] roots = ProjectRootManager.getInstance(project).getContentRoots(); if (roots.length == 0) { - Messages.showErrorDialog(project, "Project doesn't have any project roots", "Cannot create new GitHub repository"); + Messages.showErrorDialog(project, "Project doesn't have any project roots", CANNOT_PERFORM_GITHUB_REBASE); return; } final VirtualFile root = roots[0]; // Check if git is already initialized and presence of remote branch final boolean gitDetected = GitUtil.isUnderGit(root); if (!gitDetected) { - Messages.showErrorDialog(project, "Cannot find any git repository configured for the project", "Cannot perform github rebase"); + Messages.showErrorDialog(project, "Cannot find any git repository configured for the project", CANNOT_PERFORM_GITHUB_REBASE); return; } try { - // Check current branch - final GitBranch currentBranch = GitBranch.current(project, root); - if (currentBranch == null) { - Messages.showErrorDialog(project, "Cannot find current branch", "Cannot perform github rebase"); - return; - } - if (!"master".equals(currentBranch.getName())) { - Messages.showErrorDialog(project, "Cannot perform rebase with '" + currentBranch.getName() + "' branch.\nPlease switch to master", - "Cannot perform github rebase"); - return; - } - // Check that given repository is properly configured git repository - GitRemote githubRemote = null; + final GitRemote githubRemote = GithubUtil.getGithubBoundRepository(project); final List gitRemotes = GitRemote.list(project, root); - if (gitRemotes.isEmpty()) { - Messages.showErrorDialog(project, "Git repository doesn't have any remotes configured", "Cannot perform github rebase"); - return; - } - for (GitRemote gitRemote : gitRemotes) { - if (gitRemote.pushUrl().contains("git@github.com")) { - githubRemote = gitRemote; - break; - } - } - if (githubRemote == null) { - Messages.showErrorDialog(project, "Configured own github repository is not found", "Cannot perform github rebase"); - return; - } + LOG.assertTrue(githubRemote != null); final String pushUrl = githubRemote.pushUrl(); final String login = GithubSettings.getInstance().getLogin(); final int index = pushUrl.lastIndexOf(login); if (index == -1) { Messages.showErrorDialog(project, "Github remote repository doesn't seem to be your own repository: " + pushUrl, - "Cannot perform github rebase"); + CANNOT_PERFORM_GITHUB_REBASE); return; } String repoName = pushUrl.substring(index + login.length() + 1); @@ -122,12 +101,12 @@ public class GithubRebaseAction extends DumbAwareAction { final RepositoryInfo repositoryInfo = GithubUtil.getDetailedRepositoryInfo(project, repoName); if (repositoryInfo == null) { Messages - .showErrorDialog(project, "Github repository doesn't seem to be your own repository: " + pushUrl, "Cannot perform github rebase"); + .showErrorDialog(project, "Github repository doesn't seem to be your own repository: " + pushUrl, CANNOT_PERFORM_GITHUB_REBASE); return; } if (!repositoryInfo.isFork()) { - Messages.showErrorDialog(project, "Github repository '" + repoName + "' is not a forked one", "Cannot perform github rebase"); + Messages.showErrorDialog(project, "Github repository '" + repoName + "' is not a forked one", CANNOT_PERFORM_GITHUB_REBASE); return; } @@ -161,7 +140,7 @@ public class GithubRebaseAction extends DumbAwareAction { addRemoteHandler.addParameters("add", repoName, parentRepoUrl); addRemoteHandler.run(); if (addRemoteHandler.getExitCode() != 0) { - Messages.showErrorDialog("Failed to add GitHub remote: '" + parentRepoUrl + "'", "Failed to add GitHub remote"); + Messages.showErrorDialog("Failed to add GitHub remote: '" + parentRepoUrl + "'", CANNOT_PERFORM_GITHUB_REBASE); return; } @@ -175,7 +154,7 @@ public class GithubRebaseAction extends DumbAwareAction { action.actionPerformed(actionEvent); } catch (VcsException e1) { - Messages.showErrorDialog(project, "Error happened during git operation: " + e1.getMessage(), "Cannot perform github rebase"); + Messages.showErrorDialog(project, "Error happened during git operation: " + e1.getMessage(), CANNOT_PERFORM_GITHUB_REBASE); return; } } diff --git a/plugins/github/src/org/jetbrains/plugins/github/GithubUtil.java b/plugins/github/src/org/jetbrains/plugins/github/GithubUtil.java index b9bda80682de..45c2e8585af4 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/GithubUtil.java +++ b/plugins/github/src/org/jetbrains/plugins/github/GithubUtil.java @@ -5,9 +5,14 @@ import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.progress.Task; import com.intellij.openapi.project.Project; +import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.JDOMUtil; import com.intellij.openapi.util.Ref; +import com.intellij.openapi.vcs.VcsException; +import com.intellij.openapi.vfs.VirtualFile; +import git4idea.GitRemote; +import git4idea.GitUtil; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpMethod; import org.apache.commons.httpclient.UsernamePasswordCredentials; @@ -236,4 +241,30 @@ public class GithubUtil { return null; } } + + @Nullable + public static GitRemote getGithubBoundRepository(final Project project){ + final VirtualFile[] roots = ProjectRootManager.getInstance(project).getContentRoots(); + if (roots.length == 0) { + return null; + } + final VirtualFile root = roots[0]; + // Check if git is already initialized and presence of remote branch + final boolean gitDetected = GitUtil.isUnderGit(root); + if (!gitDetected) { + return null; + } + try { + // Check that given repository is properly configured git repository + final List gitRemotes = GitRemote.list(project, root); + for (GitRemote gitRemote : gitRemotes) { + if (gitRemote.pushUrl().contains("git@github.com")) { + return gitRemote; + } + } + } catch (VcsException e){ + // ignore + } + return null; + } }