Skip to content

Commit

Permalink
CHE-414: Display staged changes in green when status called
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Vinokur committed Mar 2, 2016
1 parent 9b55d56 commit 2dd77ec
Show file tree
Hide file tree
Showing 35 changed files with 246 additions and 203 deletions.
Expand Up @@ -88,8 +88,6 @@

import java.io.File;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.regex.Pattern;
Expand All @@ -104,14 +102,19 @@
*/
public class NativeGitConnection implements GitConnection {

private static final Pattern authErrorPattern =
Pattern.compile(
".*fatal: could not read (Username|Password) for '.*': No such device or address.*|" +
".*fatal: could not read (Username|Password) for '.*': Input/output error.*|" +
".*fatal: Authentication failed for '.*'.*|.*fatal: Could not read from remote repository\\.\\n\\nPlease make sure " +
"you have the correct access rights\\nand the repository exists\\.\\n.*",
Pattern.MULTILINE);
private static final Pattern notInGitRepoErrorPattern = Pattern.compile("^fatal: Not a git repository.*(\\n.*)*$", Pattern.MULTILINE);
private static final Pattern authErrorPattern =
Pattern.compile(
".*fatal: could not read (Username|Password) for '.*': No such device or address.*|" +
".*fatal: could not read (Username|Password) for '.*': Input/output error.*|" +
".*fatal: Authentication failed for '.*'.*|.*fatal: Could not read from remote repository\\.\\n\\nPlease make sure " +
"you have the correct access rights\\nand the repository exists\\.\\n.*",
Pattern.MULTILINE);
private static final Pattern notInGitRepoErrorPattern =
Pattern.compile("^fatal: Not a git repository.*(\\n.*)*$", Pattern.MULTILINE);
private static final Pattern noInitCommitWhenBranchCreateErrorPattern = Pattern.compile("fatal: Not a valid object name: '.*'.\n");
private static final Pattern noInitCommitWhenLogErrorPattern =
Pattern.compile("fatal: your current branch '.*' does not have any commits yet\n");
private static final Pattern noInitCommitWhenPullErrorPattern = Pattern.compile("fatal: empty ident name .* not allowed\n");
private final NativeGit nativeGit;
private final CredentialsLoader credentialsLoader;
private final GitUserResolver userResolver;
Expand Down Expand Up @@ -180,8 +183,7 @@ public Branch branchCreate(BranchCreateRequest request) throws GitException {
try {
branchCreateCommand.execute();
} catch (ServerException exception) {
Pattern errorPattern = Pattern.compile("fatal: Not a valid object name: '.*'.\n");
if (errorPattern.matcher(exception.getMessage()).find()) {
if (noInitCommitWhenBranchCreateErrorPattern.matcher(exception.getMessage()).find()) {
throw new GitException(exception.getMessage(), ErrorCodes.INIT_COMMIT_WAS_NOT_PERFORMED);
}
}
Expand Down Expand Up @@ -373,8 +375,7 @@ public LogPage log(LogRequest request) throws GitException {
try {
return new LogPage(nativeGit.createLogCommand().setFileFilter(request.getFileFilter()).execute());
} catch (ServerException exception) {
Pattern errorPattern = Pattern.compile("fatal: your current branch '.*' does not have any commits yet\n");
if (errorPattern.matcher(exception.getMessage()).find()) {
if (noInitCommitWhenLogErrorPattern.matcher(exception.getMessage()).find()) {
throw new GitException(exception.getMessage(), ErrorCodes.INIT_COMMIT_WAS_NOT_PERFORMED);
} else {
throw exception;
Expand Down Expand Up @@ -422,7 +423,20 @@ public PullResponse pull(PullRequest request) throws GitException, UnauthorizedE
.setRemoteUri(remoteUri)
.setTimeout(request.getTimeout());

executeRemoteCommand(pullCommand);
try {
executeRemoteCommand(pullCommand);
} catch (GitException exception) {
if (noInitCommitWhenPullErrorPattern.matcher(exception.getMessage()).find()) {
throw new GitException(exception.getMessage(), ErrorCodes.NO_COMMITTER_NAME_OR_EMAIL_DEFINED);
} else if ("Unable get private ssh key".equals(exception.getMessage())) {
throw new GitException(exception.getMessage(), ErrorCodes.UNABLE_GET_PRIVATE_SSH_KEY);
} else if (("Auto-merging file\nCONFLICT (content): Merge conflict in file\n" +
"Automatic merge failed; fix conflicts and then commit the result.\n").equals(exception.getMessage())) {
throw new GitException(exception.getMessage(), ErrorCodes.MERGE_CONFLICT);
} else {
throw exception;
}
}

return pullCommand.getPullResponse();
}
Expand Down
Expand Up @@ -564,4 +564,16 @@ public static String getListBoxDropdownBackgroundColor() {
return theme.getListBoxDropdownBackgroundColor();
}

public static String getGitConsoleStagedFilesColor() {
return theme.gitConsoleStagedFilesColor();
}

public static String getGitConsoleUnstagedFilesColor() {
return theme.gitConsoleUnstagedFilesColor();
}

public static String getGitConsoleErrorColor() {
return theme.gitConsoleErrorColor();
}

}
Expand Up @@ -1457,4 +1457,12 @@ public interface Theme {
String toolButtonHoverBoxShadow();
String toolButtonActiveBoxShadow();

/********************************************************************************************
*
* Git output console
*
********************************************************************************************/
String gitConsoleStagedFilesColor();
String gitConsoleUnstagedFilesColor();
String gitConsoleErrorColor();
}
Expand Up @@ -1439,4 +1439,19 @@ public String toolButtonHoverBoxShadow() {
public String toolButtonActiveBoxShadow() {
return "inset 1px 1px 0 0 #3c3c3c";
}

@Override
public String gitConsoleStagedFilesColor() {
return "lightgreen";
}

@Override
public String gitConsoleUnstagedFilesColor() {
return "#F62217";
}

@Override
public String gitConsoleErrorColor() {
return "#F62217";
}
}
Expand Up @@ -1416,4 +1416,19 @@ public String toolButtonHoverBoxShadow() {
public String toolButtonActiveBoxShadow() {
return "inset 1px 1px 0 0 #6F6E6E";
}

@Override
public String gitConsoleStagedFilesColor() {
return "green";
}

@Override
public String gitConsoleUnstagedFilesColor() {
return "red";
}

@Override
public String gitConsoleErrorColor() {
return "red";
}
}
Expand Up @@ -22,6 +22,7 @@ private ErrorCodes() {
public static final int NO_COMMITTER_NAME_OR_EMAIL_DEFINED = 15216;
public static final int UNABLE_GET_PRIVATE_SSH_KEY = 32068;
public static final int UNAUTHORIZED_GIT_OPERATION = 32080;
public static final int MERGE_CONFLICT = 32062;
public static final int FAILED_CHECKOUT = 32063;
public static final int FAILED_CHECKOUT_WITH_START_POINT = 32064;
public static final int INIT_COMMIT_WAS_NOT_PERFORMED = 32082;
Expand Down
Expand Up @@ -29,34 +29,59 @@ public interface Status {

void setBranchName(String branchName);

/**
* New files that are staged in index.
*/
List<String> getAdded();

void setAdded(List<String> added);

/**
* New files that are not staged in index.
*/
List<String> getUntracked();

void setUntracked(List<String> untracked);

/**
* Modified files that are staged in index.
*/
List<String> getChanged();

void setChanged(List<String> changed);

/**
* Modified files that are not staged in index.
*/
List<String> getModified();

void setModified(List<String> modified);

/**
* Deleted files that are staged in index.
*/
List<String> getRemoved();

void setRemoved(List<String> removed);

/**
* Deleted files that are not staged in index.
*/
List<String> getMissing();

void setMissing(List<String> missing);

List<String> getModified();

void setModified(List<String> modified);

List<String> getUntracked();

void setUntracked(List<String> untracked);

/**
* Folders that contain only untracked files.
* @see #getUntracked()
*/
List<String> getUntrackedFolders();

void setUntrackedFolders(List<String> untrackedFolders);

/**
* Files that have conflicts.
*/
List<String> getConflicting();

void setConflicting(List<String> added);
Expand Down
Expand Up @@ -115,7 +115,7 @@ protected void onSuccess(final Status result) {
if (!result.isClean()) {
addSelection();
} else {
console.printInfo(constant.nothingAddToIndex());
console.print(constant.nothingAddToIndex());
consolesPanelPresenter.addCommandOutput(appContext.getDevMachineId(), console);
notificationManager.notify(constant.nothingAddToIndex(), project.getRootProject());
}
Expand Down Expand Up @@ -181,7 +181,7 @@ public void onAddClicked() {
@Override
protected void onSuccess(final Void result) {

console.printInfo(constant.addSuccess());
console.print(constant.addSuccess());
consolesPanelPresenter.addCommandOutput(appContext.getDevMachineId(), console);
notificationManager.notify(constant.addSuccess(), project.getRootProject());
}
Expand Down
Expand Up @@ -10,8 +10,6 @@
*******************************************************************************/
package org.eclipse.che.ide.ext.git.client.branch;

import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONParser;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.google.web.bindery.event.shared.EventBus;
Expand Down
Expand Up @@ -231,7 +231,7 @@ private void onCommitSuccess(@NotNull final Revision revision) {
message += " " + constant.commitUser(revision.getCommitter().getName());
}
GitOutputConsole console = gitOutputConsoleFactory.create(COMMIT_COMMAND_NAME);
console.printInfo(message);
console.print(message);
consolesPanelPresenter.addCommandOutput(appContext.getDevMachineId(), console);
notificationManager.notify(message, appContext.getCurrentProject().getRootProject());
view.setMessage("");
Expand Down
Expand Up @@ -88,7 +88,7 @@ public void deleteRepository() {
service.deleteRepository(workspaceId, project.getRootProject(), new AsyncRequestCallback<Void>() {
@Override
protected void onSuccess(Void result) {
console.printInfo(constant.deleteGitRepositorySuccess());
console.print(constant.deleteGitRepositorySuccess());
consolesPanelPresenter.addCommandOutput(appContext.getDevMachineId(), console);
notificationManager.notify(constant.deleteGitRepositorySuccess(), project.getRootProject());
getRootProject(project.getRootProject());
Expand Down
Expand Up @@ -178,7 +178,7 @@ public void onFetchClicked() {
new RequestCallback<String>() {
@Override
protected void onSuccess(String result) {
console.printInfo(constant.fetchSuccess(remoteUrl));
console.print(constant.fetchSuccess(remoteUrl));
consolesPanelPresenter.addCommandOutput(appContext.getDevMachineId(), console);
notification.setStatus(SUCCESS);
notification.setTitle(constant.fetchSuccess(remoteUrl));
Expand Down
Expand Up @@ -92,7 +92,7 @@ public void onFailure(Throwable caught) {

@Override
public void onSuccess(Void result) {
console.printInfo(constant.initSuccess());
console.print(constant.initSuccess());
consolesPanelPresenter.addCommandOutput(appContext.getDevMachineId(), console);
notificationManager.notify(constant.initSuccess(), currentProject.getRootProject());
getRootProject(currentProject.getRootProject());
Expand Down
Expand Up @@ -179,7 +179,7 @@ public void onMergeClicked() {
new AsyncRequestCallback<MergeResult>(dtoUnmarshallerFactory.newUnmarshaller(MergeResult.class)) {
@Override
protected void onSuccess(final MergeResult result) {
console.printInfo(formMergeMessage(result));
console.print(formMergeMessage(result));
consolesPanelPresenter.addCommandOutput(appContext.getDevMachineId(), console);
notificationManager.notify(formMergeMessage(result), appContext.getCurrentProject().getRootProject());
refreshProject(openedEditors);
Expand Down
Expand Up @@ -21,35 +21,31 @@
* @author Roman Nikitenko
*/
public interface GitOutputConsole extends OutputConsole {

/**
* Print text on console.
* Print text in console.
*
* @param text
* text that need to be shown
*/
void print(@NotNull String text);

/**
* [INFO] text
*
* @param text
*/
void printInfo(String text);

/**
* [ERROR] text
* Print colored text in console.
*
* @param text
* text that need to be shown
* @param color
* color of printed text
*/
void printError(String text);
void print(@NotNull String text, @NotNull String color);

/**
* [WARNING] text
* Print error in console.
*
* @param text
* text that need to be shown as error
*/
void printWarn(String text);
void printError(@NotNull String text);

/** Clear console. Remove all messages. */
void clear();
Expand Down

0 comments on commit 2dd77ec

Please sign in to comment.