summaryrefslogtreecommitdiff
path: root/plugins/git4idea/src/git4idea/commands
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/git4idea/src/git4idea/commands')
-rw-r--r--plugins/git4idea/src/git4idea/commands/Git.java4
-rw-r--r--plugins/git4idea/src/git4idea/commands/GitCommandResult.java19
-rw-r--r--plugins/git4idea/src/git4idea/commands/GitHandler.java16
-rw-r--r--plugins/git4idea/src/git4idea/commands/GitHttpAuthService.java5
-rw-r--r--plugins/git4idea/src/git4idea/commands/GitHttpAuthServiceImpl.java7
-rw-r--r--plugins/git4idea/src/git4idea/commands/GitHttpGuiAuthenticator.java21
-rw-r--r--plugins/git4idea/src/git4idea/commands/GitImpl.java21
-rw-r--r--plugins/git4idea/src/git4idea/commands/GitLocalChangesWouldBeOverwrittenDetector.java31
-rw-r--r--plugins/git4idea/src/git4idea/commands/GitSSHGUIHandler.java15
-rw-r--r--plugins/git4idea/src/git4idea/commands/GitTask.java1
10 files changed, 76 insertions, 64 deletions
diff --git a/plugins/git4idea/src/git4idea/commands/Git.java b/plugins/git4idea/src/git4idea/commands/Git.java
index 284ccc1e20c5..830f73b4508f 100644
--- a/plugins/git4idea/src/git4idea/commands/Git.java
+++ b/plugins/git4idea/src/git4idea/commands/Git.java
@@ -22,6 +22,7 @@ import com.intellij.openapi.vfs.VirtualFile;
import git4idea.GitCommit;
import git4idea.push.GitPushSpec;
import git4idea.repo.GitRepository;
+import git4idea.reset.GitResetMode;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -93,7 +94,8 @@ public interface Git {
GitCommandResult branchCreate(@NotNull GitRepository repository, @NotNull String branchName);
@NotNull
- GitCommandResult resetHard(@NotNull GitRepository repository, @NotNull String revision);
+ GitCommandResult reset(@NotNull GitRepository repository, @NotNull GitResetMode mode, @NotNull String target,
+ @NotNull GitLineHandlerListener... listeners);
@NotNull
GitCommandResult resetMerge(@NotNull GitRepository repository, @Nullable String revision);
diff --git a/plugins/git4idea/src/git4idea/commands/GitCommandResult.java b/plugins/git4idea/src/git4idea/commands/GitCommandResult.java
index f89a4890a76b..0683d738a9bf 100644
--- a/plugins/git4idea/src/git4idea/commands/GitCommandResult.java
+++ b/plugins/git4idea/src/git4idea/commands/GitCommandResult.java
@@ -16,10 +16,14 @@
package git4idea.commands;
import com.intellij.openapi.util.text.StringUtil;
+import com.intellij.util.Function;
+import com.intellij.util.containers.ContainerUtil;
+import git4idea.GitUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.List;
@@ -64,9 +68,10 @@ public class GitCommandResult {
@NotNull
public String getErrorOutputAsHtmlString() {
- return StringUtil.join(myErrorOutput, "<br/>");
+ return StringUtil.join(cleanup(myErrorOutput), "<br/>");
}
-
+
+ @NotNull
public String getErrorOutputAsJoinedString() {
return StringUtil.join(myErrorOutput, "\n");
}
@@ -90,4 +95,14 @@ public class GitCommandResult {
return false; // will be implemented later
}
+ @NotNull
+ private static Collection<String> cleanup(@NotNull Collection<String> errorOutput) {
+ return ContainerUtil.map(errorOutput, new Function<String, String>() {
+ @Override
+ public String fun(String errorMessage) {
+ return GitUtil.cleanupErrorPrefixes(errorMessage);
+ }
+ });
+ }
+
}
diff --git a/plugins/git4idea/src/git4idea/commands/GitHandler.java b/plugins/git4idea/src/git4idea/commands/GitHandler.java
index 3350b74b1c6a..c2d85b7e3126 100644
--- a/plugins/git4idea/src/git4idea/commands/GitHandler.java
+++ b/plugins/git4idea/src/git4idea/commands/GitHandler.java
@@ -18,7 +18,6 @@ package git4idea.commands;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.openapi.application.ApplicationManager;
-import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
@@ -103,7 +102,6 @@ public abstract class GitHandler {
private long myStartTime; // git execution start timestamp
private static final long LONG_TIME = 10 * 1000;
- @Nullable private ModalityState myState;
@Nullable private String myUrl;
private boolean myHttpAuthFailed;
@@ -423,7 +421,7 @@ public abstract class GitHandler {
}
else {
LOG.debug("cd " + myWorkingDirectory);
- LOG.debug(printableCommandLine());
+ LOG.debug("[" + myWorkingDirectory.getName() + "] " + printableCommandLine());
}
// setup environment
@@ -431,7 +429,7 @@ public abstract class GitHandler {
if (remoteProtocol == GitRemoteProtocol.SSH && myProjectSettings.isIdeaSsh()) {
GitXmlRpcSshService ssh = ServiceManager.getService(GitXmlRpcSshService.class);
myEnv.put(GitSSHHandler.GIT_SSH_ENV, ssh.getScriptPath().getPath());
- myHandlerNo = ssh.registerHandler(new GitSSHGUIHandler(myProject, myState));
+ myHandlerNo = ssh.registerHandler(new GitSSHGUIHandler(myProject));
myEnvironmentCleanedUp = false;
myEnv.put(GitSSHHandler.SSH_HANDLER_ENV, Integer.toString(myHandlerNo));
int port = ssh.getXmlRcpPort();
@@ -458,7 +456,7 @@ public abstract class GitHandler {
GitHttpAuthService service = ServiceManager.getService(GitHttpAuthService.class);
myEnv.put(GitAskPassXmlRpcHandler.GIT_ASK_PASS_ENV, service.getScriptPath().getPath());
assert myUrl != null : "myUrl can't be null here";
- GitHttpAuthenticator httpAuthenticator = service.createAuthenticator(myProject, myState, myCommand, myUrl);
+ GitHttpAuthenticator httpAuthenticator = service.createAuthenticator(myProject, myCommand, myUrl);
myHandlerNo = service.registerHandler(httpAuthenticator);
myEnvironmentCleanedUp = false;
myEnv.put(GitAskPassXmlRpcHandler.GIT_ASK_PASS_HANDLER_ENV, Integer.toString(myHandlerNo));
@@ -474,7 +472,9 @@ public abstract class GitHandler {
startHandlingStreams();
}
catch (Throwable t) {
- LOG.error(t);
+ if (!ApplicationManager.getApplication().isUnitTestMode() || !myProject.isDisposed()) {
+ LOG.error(t); // will surely happen if called during unit test disposal, because the working dir is simply removed then
+ }
cleanupEnv();
myListeners.getMulticaster().startFailed(t);
}
@@ -715,10 +715,6 @@ public abstract class GitHandler {
myResumeAction.run();
}
- public void setModalityState(@Nullable ModalityState state) {
- myState = state;
- }
-
/**
* @return true if the command line is too big
*/
diff --git a/plugins/git4idea/src/git4idea/commands/GitHttpAuthService.java b/plugins/git4idea/src/git4idea/commands/GitHttpAuthService.java
index 69be489be44b..712582339405 100644
--- a/plugins/git4idea/src/git4idea/commands/GitHttpAuthService.java
+++ b/plugins/git4idea/src/git4idea/commands/GitHttpAuthService.java
@@ -15,10 +15,8 @@
*/
package git4idea.commands;
-import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
import org.jetbrains.git4idea.http.GitAskPassApp;
import org.jetbrains.git4idea.http.GitAskPassXmlRpcHandler;
import org.jetbrains.git4idea.ssh.GitXmlRpcHandlerService;
@@ -47,8 +45,7 @@ public abstract class GitHttpAuthService extends GitXmlRpcHandlerService<GitHttp
* Creates new {@link GitHttpAuthenticator} that will be requested to handle username and password requests from Git.
*/
@NotNull
- public abstract GitHttpAuthenticator createAuthenticator(@NotNull Project project, @Nullable ModalityState state,
- @NotNull GitCommand command, @NotNull String url);
+ public abstract GitHttpAuthenticator createAuthenticator(@NotNull Project project, @NotNull GitCommand command, @NotNull String url);
/**
* Internal handler implementation class, it is made public to be accessible via XML RPC.
diff --git a/plugins/git4idea/src/git4idea/commands/GitHttpAuthServiceImpl.java b/plugins/git4idea/src/git4idea/commands/GitHttpAuthServiceImpl.java
index 06374bf78864..cda188d64e4b 100644
--- a/plugins/git4idea/src/git4idea/commands/GitHttpAuthServiceImpl.java
+++ b/plugins/git4idea/src/git4idea/commands/GitHttpAuthServiceImpl.java
@@ -15,10 +15,8 @@
*/
package git4idea.commands;
-import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
/**
* @author Kirill Likhodedov
@@ -27,9 +25,8 @@ class GitHttpAuthServiceImpl extends GitHttpAuthService {
@Override
@NotNull
- public GitHttpAuthenticator createAuthenticator(@NotNull Project project, @Nullable ModalityState state, @NotNull GitCommand command,
- @NotNull String url) {
- return new GitHttpGuiAuthenticator(project, state, command, url);
+ public GitHttpAuthenticator createAuthenticator(@NotNull Project project, @NotNull GitCommand command, @NotNull String url) {
+ return new GitHttpGuiAuthenticator(project, command, url);
}
}
diff --git a/plugins/git4idea/src/git4idea/commands/GitHttpGuiAuthenticator.java b/plugins/git4idea/src/git4idea/commands/GitHttpGuiAuthenticator.java
index e0312e5471fc..c5931f98df10 100644
--- a/plugins/git4idea/src/git4idea/commands/GitHttpGuiAuthenticator.java
+++ b/plugins/git4idea/src/git4idea/commands/GitHttpGuiAuthenticator.java
@@ -57,7 +57,6 @@ class GitHttpGuiAuthenticator implements GitHttpAuthenticator {
private static final Class<GitHttpAuthenticator> PASS_REQUESTER = GitHttpAuthenticator.class;
@NotNull private final Project myProject;
- @Nullable private final ModalityState myModalityState;
@NotNull private final String myTitle;
@NotNull private final String myUrlFromCommand;
@@ -69,10 +68,8 @@ class GitHttpGuiAuthenticator implements GitHttpAuthenticator {
@Nullable private GitHttpAuthDataProvider myDataProvider;
private boolean myWasCancelled;
- GitHttpGuiAuthenticator(@NotNull Project project, @Nullable ModalityState modalityState, @NotNull GitCommand command,
- @NotNull String url) {
+ GitHttpGuiAuthenticator(@NotNull Project project, @NotNull GitCommand command, @NotNull String url) {
myProject = project;
- myModalityState = modalityState;
myTitle = "Git " + StringUtil.capitalize(command.name());
myUrlFromCommand = url;
}
@@ -87,7 +84,7 @@ class GitHttpGuiAuthenticator implements GitHttpAuthenticator {
return "";
}
url = adjustUrl(url);
- Pair<GitHttpAuthDataProvider, AuthData> authData = findBestAuthData(url, myModalityState);
+ Pair<GitHttpAuthDataProvider, AuthData> authData = findBestAuthData(url);
if (authData != null && authData.second.getPassword() != null) {
String password = authData.second.getPassword();
myDataProvider = authData.first;
@@ -97,7 +94,7 @@ class GitHttpGuiAuthenticator implements GitHttpAuthenticator {
String prompt = "Enter the password for " + url;
myPasswordKey = url;
- String password = PasswordSafePromptDialog.askPassword(myProject, myModalityState, myTitle, prompt, PASS_REQUESTER, url, false, null);
+ String password = PasswordSafePromptDialog.askPassword(myProject, myTitle, prompt, PASS_REQUESTER, url, false, null);
if (password == null) {
myWasCancelled = true;
return "";
@@ -114,7 +111,7 @@ class GitHttpGuiAuthenticator implements GitHttpAuthenticator {
@NotNull
public String askUsername(@NotNull String url) {
url = adjustUrl(url);
- Pair<GitHttpAuthDataProvider, AuthData> authData = findBestAuthData(url, myModalityState);
+ Pair<GitHttpAuthDataProvider, AuthData> authData = findBestAuthData(url);
String login = null;
String password = null;
if (authData != null) {
@@ -152,7 +149,7 @@ class GitHttpGuiAuthenticator implements GitHttpAuthenticator {
dialog.set(new AuthDialog(myProject, myTitle, "Enter credentials for " + url, login, null, true));
dialog.get().show();
}
- }, myModalityState == null ? ModalityState.defaultModalityState() : myModalityState);
+ }, ModalityState.any());
return dialog.get();
}
@@ -223,10 +220,10 @@ class GitHttpGuiAuthenticator implements GitHttpAuthenticator {
// return the first that knows username + password; otherwise return the first that knows just the username
@Nullable
- private Pair<GitHttpAuthDataProvider, AuthData> findBestAuthData(@NotNull String url, @Nullable ModalityState modalityState) {
+ private Pair<GitHttpAuthDataProvider, AuthData> findBestAuthData(@NotNull String url) {
Pair<GitHttpAuthDataProvider, AuthData> candidate = null;
for (GitHttpAuthDataProvider provider : getProviders()) {
- AuthData data = provider.getAuthData(url, modalityState);
+ AuthData data = provider.getAuthData(url);
if (data != null) {
Pair<GitHttpAuthDataProvider, AuthData> pair = Pair.create(provider, data);
if (data.getPassword() != null) {
@@ -268,12 +265,12 @@ class GitHttpGuiAuthenticator implements GitHttpAuthenticator {
@Nullable
@Override
- public AuthData getAuthData(@NotNull String url, @Nullable ModalityState modalityState) {
+ public AuthData getAuthData(@NotNull String url) {
String userName = getUsername(url);
String key = makeKey(url, userName);
final PasswordSafe passwordSafe = PasswordSafe.getInstance();
try {
- String password = passwordSafe.getPassword(myProject, PASS_REQUESTER, key, modalityState);
+ String password = passwordSafe.getPassword(myProject, PASS_REQUESTER, key);
return new AuthData(StringUtil.notNullize(userName), password);
}
catch (PasswordSafeException e) {
diff --git a/plugins/git4idea/src/git4idea/commands/GitImpl.java b/plugins/git4idea/src/git4idea/commands/GitImpl.java
index c873e71ff94b..09e254f5392b 100644
--- a/plugins/git4idea/src/git4idea/commands/GitImpl.java
+++ b/plugins/git4idea/src/git4idea/commands/GitImpl.java
@@ -32,6 +32,7 @@ import git4idea.history.GitHistoryUtils;
import git4idea.push.GitPushSpec;
import git4idea.repo.GitRemote;
import git4idea.repo.GitRepository;
+import git4idea.reset.GitResetMode;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -338,20 +339,26 @@ public class GitImpl implements Git {
@Override
@NotNull
- public GitCommandResult resetHard(@NotNull GitRepository repository, @NotNull String revision) {
- final GitLineHandler handler = new GitLineHandler(repository.getProject(), repository.getRoot(), GitCommand.RESET);
- handler.addParameters("--hard", revision);
- return run(handler);
+ public GitCommandResult reset(@NotNull GitRepository repository, @NotNull GitResetMode mode, @NotNull String target,
+ @NotNull GitLineHandlerListener... listeners) {
+ return reset(repository, mode.getArgument(), target, listeners);
}
@Override
@NotNull
public GitCommandResult resetMerge(@NotNull GitRepository repository, @Nullable String revision) {
+ return reset(repository, "--merge", revision);
+ }
+
+ @NotNull
+ private static GitCommandResult reset(@NotNull GitRepository repository, @NotNull String argument, @Nullable String target,
+ @NotNull GitLineHandlerListener... listeners) {
final GitLineHandler handler = new GitLineHandler(repository.getProject(), repository.getRoot(), GitCommand.RESET);
- handler.addParameters("--merge");
- if (revision != null) {
- handler.addParameters(revision);
+ handler.addParameters(argument);
+ if (target != null) {
+ handler.addParameters(target);
}
+ addListeners(handler, listeners);
return run(handler);
}
diff --git a/plugins/git4idea/src/git4idea/commands/GitLocalChangesWouldBeOverwrittenDetector.java b/plugins/git4idea/src/git4idea/commands/GitLocalChangesWouldBeOverwrittenDetector.java
index b62f12806761..e9d8df89614a 100644
--- a/plugins/git4idea/src/git4idea/commands/GitLocalChangesWouldBeOverwrittenDetector.java
+++ b/plugins/git4idea/src/git4idea/commands/GitLocalChangesWouldBeOverwrittenDetector.java
@@ -40,6 +40,13 @@ public class GitLocalChangesWouldBeOverwrittenDetector extends GitMessageWithFil
".*Your local changes to '(.*)' would be overwritten by merge.*"
);
+ private static final Pattern[] RESET_PATTERNS = new Pattern[]{Pattern.compile(
+ ".*Entry '(.*)' not uptodate. Cannot merge.*"
+ ),
+ Pattern.compile(
+ ".*Entry '(.*)' would be overwritten by merge.*"
+ )};
+
// common for checkout and merge
public static final Event NEW_PATTERN = new Event(
"Your local changes to the following files would be overwritten by",
@@ -49,17 +56,18 @@ public class GitLocalChangesWouldBeOverwrittenDetector extends GitMessageWithFil
public enum Operation {
CHECKOUT(OLD_CHECKOUT_PATTERN),
- MERGE(OLD_MERGE_PATTERN);
+ MERGE(OLD_MERGE_PATTERN),
+ RESET(RESET_PATTERNS);
- @NotNull private final Pattern myPattern;
+ @NotNull private final Pattern[] myPatterns;
- Operation(@NotNull Pattern pattern) {
- myPattern = pattern;
+ Operation(@NotNull Pattern... patterns) {
+ myPatterns = patterns;
}
@NotNull
- public Pattern getPattern() {
- return myPattern;
+ Pattern[] getPatterns() {
+ return myPatterns;
}
}
@@ -71,10 +79,13 @@ public class GitLocalChangesWouldBeOverwrittenDetector extends GitMessageWithFil
@Override
public void onLineAvailable(@NotNull String line, @NotNull Key outputType) {
super.onLineAvailable(line, outputType);
- Matcher m = myOperation.getPattern().matcher(line);
- if (m.matches()) {
- myMessageDetected = true;
- myAffectedFiles.add(m.group(1));
+ for (Pattern pattern : myOperation.getPatterns()) {
+ Matcher m = pattern.matcher(line);
+ if (m.matches()) {
+ myMessageDetected = true;
+ myAffectedFiles.add(m.group(1));
+ break;
+ }
}
}
}
diff --git a/plugins/git4idea/src/git4idea/commands/GitSSHGUIHandler.java b/plugins/git4idea/src/git4idea/commands/GitSSHGUIHandler.java
index 982270421968..4d1c13415ec2 100644
--- a/plugins/git4idea/src/git4idea/commands/GitSSHGUIHandler.java
+++ b/plugins/git4idea/src/git4idea/commands/GitSSHGUIHandler.java
@@ -16,7 +16,6 @@
package git4idea.commands;
import com.intellij.ide.passwordSafe.ui.PasswordSafePromptDialog;
-import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.Messages;
@@ -39,17 +38,9 @@ import java.util.concurrent.atomic.AtomicReference;
*/
public class GitSSHGUIHandler {
@Nullable private final Project myProject;
- @Nullable private final ModalityState myState;
- /**
- * A constructor
- *
- * @param project a project to use
- * @param state modality state using which any prompts initiated by the git process should be shown in the UI.
- */
- GitSSHGUIHandler(@Nullable Project project, @Nullable ModalityState state) {
+ GitSSHGUIHandler(@Nullable Project project) {
myProject = project;
- myState = state;
}
public boolean verifyServerHostKey(final String hostname,
@@ -76,7 +67,7 @@ public class GitSSHGUIHandler {
@Nullable
public String askPassphrase(final String username, final String keyPath, boolean resetPassword, final String lastError) {
String error = processLastError(resetPassword, lastError);
- return PasswordSafePromptDialog.askPassphrase(myProject, myState, GitBundle.getString("ssh.ask.passphrase.title"),
+ return PasswordSafePromptDialog.askPassphrase(myProject, GitBundle.getString("ssh.ask.passphrase.title"),
GitBundle.message("ssh.askPassphrase.message", keyPath, username),
GitSSHGUIHandler.class, "PASSPHRASE:" + keyPath, resetPassword, error
);
@@ -165,7 +156,7 @@ public class GitSSHGUIHandler {
@Nullable
public String askPassword(final String username, boolean resetPassword, final String lastError) {
String error = processLastError(resetPassword, lastError);
- return PasswordSafePromptDialog.askPassword(myProject, myState, GitBundle.getString("ssh.password.title"),
+ return PasswordSafePromptDialog.askPassword(myProject, GitBundle.getString("ssh.password.title"),
GitBundle.message("ssh.password.message", username),
GitSSHGUIHandler.class, "PASSWORD:" + username, resetPassword, error);
}
diff --git a/plugins/git4idea/src/git4idea/commands/GitTask.java b/plugins/git4idea/src/git4idea/commands/GitTask.java
index c22ce07819c9..79f8e33ef55e 100644
--- a/plugins/git4idea/src/git4idea/commands/GitTask.java
+++ b/plugins/git4idea/src/git4idea/commands/GitTask.java
@@ -324,7 +324,6 @@ public class GitTask {
@Override
public final void run(@NotNull ProgressIndicator indicator) {
- myHandler.setModalityState(indicator.getModalityState());
myDelegate.run(indicator);
}