From 0af0f966ed6a794322d8b62ae5855b9cf5c28b28 Mon Sep 17 00:00:00 2001 From: Igor Vinokur Date: Mon, 29 Feb 2016 11:02:55 +0200 Subject: [PATCH] CHE-521: Perform git init command without initial commit --- .../impl/nativegit/NativeGitConnection.java | 37 ++--- .../commands/BranchRenameCommand.java | 6 +- .../ide/CoreLocalizationConstant.properties | 2 +- .../git/gwt/client/GitServiceClientImpl.java | 1 - .../org/eclipse/che/api/core/ErrorCodes.java | 1 + .../che/api/git/GitProjectImporter.java | 2 +- .../che/api/git/shared/InitRequest.java | 9 +- .../git/client/GitLocalizationConstant.java | 6 +- .../git/client/branch/BranchPresenter.java | 126 ++++++++---------- .../git/client/commit/CommitPresenter.java | 16 ++- .../revisionsList/RevisionListPresenter.java | 11 +- .../git/client/history/HistoryPresenter.java | 30 ++++- .../reset/commit/ResetToCommitPresenter.java | 13 ++ .../client/GitLocalizationConstant.properties | 5 +- .../client/history/HistoryPresenterTest.java | 1 + .../commit/ResetToCommitPresenterTest.java | 1 + .../GitHubLocalizationConstant.properties | 2 +- 17 files changed, 151 insertions(+), 118 deletions(-) diff --git a/core/che-core-git-impl-native/src/main/java/org/eclipse/che/git/impl/nativegit/NativeGitConnection.java b/core/che-core-git-impl-native/src/main/java/org/eclipse/che/git/impl/nativegit/NativeGitConnection.java index 04ae78badf..c261fae0ea 100644 --- a/core/che-core-git-impl-native/src/main/java/org/eclipse/che/git/impl/nativegit/NativeGitConnection.java +++ b/core/che-core-git-impl-native/src/main/java/org/eclipse/che/git/impl/nativegit/NativeGitConnection.java @@ -14,6 +14,7 @@ package org.eclipse.che.git.impl.nativegit; import com.google.common.collect.ImmutableMap; import org.eclipse.che.api.core.ErrorCodes; +import org.eclipse.che.api.core.ServerException; import org.eclipse.che.api.core.UnauthorizedException; import org.eclipse.che.api.core.util.LineConsumerFactory; import org.eclipse.che.api.git.Config; @@ -175,8 +176,15 @@ public class NativeGitConnection implements GitConnection { public Branch branchCreate(BranchCreateRequest request) throws GitException { BranchCreateCommand branchCreateCommand = nativeGit.createBranchCreateCommand(); branchCreateCommand.setBranchName(request.getName()) - .setStartPoint(request.getStartPoint()) - .execute(); + .setStartPoint(request.getStartPoint()); + try { + branchCreateCommand.execute(); + } catch (ServerException exception) { + Pattern errorPattern = Pattern.compile("fatal: Not a valid object name: '.*'.\n"); + if (errorPattern.matcher(exception.getMessage()).find()) { + throw new GitException(exception.getMessage(), ErrorCodes.INIT_COMMIT_WAS_NOT_PERFORMED); + } + } return DtoFactory.getInstance().createDto(Branch.class).withName(getBranchRef(request.getName())).withActive(false) .withDisplayName(request.getName()).withRemote(false); } @@ -358,25 +366,20 @@ public class NativeGitConnection implements GitConnection { InitCommand initCommand = nativeGit.createInitCommand(); initCommand.setBare(request.isBare()); initCommand.execute(); - //make initial commit. - if (!request.isBare() && request.isInitCommit()) { - try { - nativeGit.createAddCommand() - .setFilePattern(new ArrayList<>(Collections.singletonList("."))) - .execute(); - nativeGit.createCommitCommand() - .setCommitter(getLocalCommitter()) - .setMessage("init") - .execute(); - } catch (GitException ignored) { - //if nothing to commit - } - } } @Override public LogPage log(LogRequest request) throws GitException { - return new LogPage(nativeGit.createLogCommand().setFileFilter(request.getFileFilter()).execute()); + 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()) { + throw new GitException(exception.getMessage(), ErrorCodes.INIT_COMMIT_WAS_NOT_PERFORMED); + } else { + throw exception; + } + } } @Override diff --git a/core/che-core-git-impl-native/src/main/java/org/eclipse/che/git/impl/nativegit/commands/BranchRenameCommand.java b/core/che-core-git-impl-native/src/main/java/org/eclipse/che/git/impl/nativegit/commands/BranchRenameCommand.java index d61fe5f3a2..e1fb1fb1d2 100644 --- a/core/che-core-git-impl-native/src/main/java/org/eclipse/che/git/impl/nativegit/commands/BranchRenameCommand.java +++ b/core/che-core-git-impl-native/src/main/java/org/eclipse/che/git/impl/nativegit/commands/BranchRenameCommand.java @@ -65,10 +65,10 @@ public class BranchRenameCommand extends RemoteOperationCommand { commandLine.add("-t"); commandLine.add(branchName); start(); - } catch (GitException e) { - String errorMessage = e.getMessage(); + } catch (GitException exception) { + String errorMessage = exception.getMessage(); if (!checkoutErrorPattern.matcher(errorMessage).find()) { - throw new GitException(errorMessage); + throw exception; } //local branch already exist - so ignore and try perform the next step } diff --git a/core/ide/che-core-ide-app/src/main/resources/org/eclipse/che/ide/CoreLocalizationConstant.properties b/core/ide/che-core-ide-app/src/main/resources/org/eclipse/che/ide/CoreLocalizationConstant.properties index 4a9f220f7e..ee30382bee 100644 --- a/core/ide/che-core-ide-app/src/main/resources/org/eclipse/che/ide/CoreLocalizationConstant.properties +++ b/core/ide/che-core-ide-app/src/main/resources/org/eclipse/che/ide/CoreLocalizationConstant.properties @@ -147,7 +147,7 @@ importProject.message.failure = Failed to import project {0} importProject.message.startWithWhiteSpace = The url can not start with a whitespace. importProject.message.urlInvalid = The URL provided for the project to import is invalid. importProject.message.unableGetSshKey = Unable get private ssh key. \ - You can create a new SSH key pair in Window->Preferences->Keys->SSH Keystore. + You can create a new SSH key pair in Help->Preferences->SSH->Git. importProject.importer.info = Importer Information importProject.project.info = Project Information importProject.name.prompt = Define the name of your project... diff --git a/core/platform-api-client-gwt/che-core-client-gwt-git/src/main/java/org/eclipse/che/api/git/gwt/client/GitServiceClientImpl.java b/core/platform-api-client-gwt/che-core-client-gwt-git/src/main/java/org/eclipse/che/api/git/gwt/client/GitServiceClientImpl.java index 358494b78c..e2cd3a83ca 100644 --- a/core/platform-api-client-gwt/che-core-client-gwt-git/src/main/java/org/eclipse/che/api/git/gwt/client/GitServiceClientImpl.java +++ b/core/platform-api-client-gwt/che-core-client-gwt-git/src/main/java/org/eclipse/che/api/git/gwt/client/GitServiceClientImpl.java @@ -142,7 +142,6 @@ public class GitServiceClientImpl implements GitServiceClient{ InitRequest initRequest = dtoFactory.createDto(InitRequest.class); initRequest.setBare(bare); initRequest.setWorkingDir(project.getName()); - initRequest.setInitCommit(true); String url = "/git/" + workspaceId + INIT + "?projectPath=" + project.getPath(); diff --git a/core/platform-api/che-core-api-core/src/main/java/org/eclipse/che/api/core/ErrorCodes.java b/core/platform-api/che-core-api-core/src/main/java/org/eclipse/che/api/core/ErrorCodes.java index c9915b464c..0267dda372 100644 --- a/core/platform-api/che-core-api-core/src/main/java/org/eclipse/che/api/core/ErrorCodes.java +++ b/core/platform-api/che-core-api-core/src/main/java/org/eclipse/che/api/core/ErrorCodes.java @@ -24,4 +24,5 @@ public class ErrorCodes { public static final int UNAUTHORIZED_GIT_OPERATION = 32080; 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; } diff --git a/core/platform-api/che-core-api-git/src/main/java/org/eclipse/che/api/git/GitProjectImporter.java b/core/platform-api/che-core-api-git/src/main/java/org/eclipse/che/api/git/GitProjectImporter.java index 68245d7c99..2f3c3f0d4f 100644 --- a/core/platform-api/che-core-api-git/src/main/java/org/eclipse/che/api/git/GitProjectImporter.java +++ b/core/platform-api/che-core-api-git/src/main/java/org/eclipse/che/api/git/GitProjectImporter.java @@ -224,7 +224,7 @@ public class GitProjectImporter implements ProjectImporter { } private void initRepository(GitConnection git, DtoFactory dtoFactory) throws GitException { - final InitRequest request = dtoFactory.createDto(InitRequest.class).withInitCommit(false).withBare(false); + final InitRequest request = dtoFactory.createDto(InitRequest.class).withBare(false); git.init(request); } diff --git a/core/platform-api/che-core-api-git/src/main/java/org/eclipse/che/api/git/shared/InitRequest.java b/core/platform-api/che-core-api-git/src/main/java/org/eclipse/che/api/git/shared/InitRequest.java index d17879a37a..1eb03d17c3 100644 --- a/core/platform-api/che-core-api-git/src/main/java/org/eclipse/che/api/git/shared/InitRequest.java +++ b/core/platform-api/che-core-api-git/src/main/java/org/eclipse/che/api/git/shared/InitRequest.java @@ -34,11 +34,4 @@ public interface InitRequest extends GitRequest { void setBare(boolean bare); InitRequest withBare(boolean bare); - - /** @return true then all files in newly initialized repository will be commited with "init" message */ - boolean isInitCommit(); - - void setInitCommit(boolean initCommit); - - InitRequest withInitCommit(boolean initCommit); -} \ No newline at end of file +} diff --git a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/GitLocalizationConstant.java b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/GitLocalizationConstant.java index 4d2e110e06..81a895928e 100644 --- a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/GitLocalizationConstant.java +++ b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/GitLocalizationConstant.java @@ -71,9 +71,6 @@ public interface GitLocalizationConstant extends Messages { String buttonScroll(); // MESSAGES - @Key("messages.unableGetSshKeyTitle") - String messagesUnableGetSshKeyTitle(); - @Key("messages.unableGetSshKey") String messagesUnableGetSshKey(); @@ -121,6 +118,9 @@ public interface GitLocalizationConstant extends Messages { @Key("messages.committer_identity_info_empty") String committerIdentityInfoEmpty(); + + @Key("messages.init_commit_was_not_performed") + String initCommitWasNotPerformed(); @Key("messages.diff.failed") String diffFailed(); diff --git a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/branch/BranchPresenter.java b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/branch/BranchPresenter.java index 38c1c8850f..84e2315059 100644 --- a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/branch/BranchPresenter.java +++ b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/branch/BranchPresenter.java @@ -16,7 +16,7 @@ import com.google.inject.Inject; import com.google.inject.Singleton; import com.google.web.bindery.event.shared.EventBus; -import org.eclipse.che.api.core.rest.shared.dto.ServiceError; +import org.eclipse.che.api.core.ErrorCodes; import org.eclipse.che.api.git.gwt.client.GitServiceClient; import org.eclipse.che.api.git.shared.Branch; import org.eclipse.che.api.git.shared.CheckoutRequest; @@ -49,10 +49,12 @@ import org.eclipse.che.ide.ui.dialogs.DialogFactory; import org.eclipse.che.ide.ui.dialogs.InputCallback; import javax.validation.constraints.NotNull; + import java.util.List; import static org.eclipse.che.api.git.shared.BranchListRequest.LIST_ALL; import static org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL; +import static org.eclipse.che.ide.util.ExceptionUtils.getErrorCode; /** * Presenter for displaying and work with branches. @@ -174,12 +176,7 @@ public class BranchPresenter implements BranchView.ActionDelegate { @Override protected void onFailure(Throwable exception) { - String errorMessage = - (exception.getMessage() != null) ? exception.getMessage() : constant.branchRenameFailed(); - final GitOutputConsole console = gitOutputConsoleFactory.create(BRANCH_RENAME_COMMAND_NAME); - console.printError(errorMessage); - consolesPanelPresenter.addCommandOutput(appContext.getDevMachineId(), console); - notificationManager.notify(constant.branchRenameFailed(), FAIL, true, project.getRootProject()); + handleError(exception, BRANCH_RENAME_COMMAND_NAME); getBranches();//rename of remote branch occurs in three stages, so needs update list of branches on view } }); @@ -205,9 +202,7 @@ public class BranchPresenter implements BranchView.ActionDelegate { @Override protected void onFailure(Throwable exception) { - GitOutputConsole console = gitOutputConsoleFactory.create(BRANCH_DELETE_COMMAND_NAME); - handleError(exception, console); - consolesPanelPresenter.addCommandOutput(appContext.getDevMachineId(), console); + handleError(exception, BRANCH_DELETE_COMMAND_NAME); } }); } @@ -257,9 +252,7 @@ public class BranchPresenter implements BranchView.ActionDelegate { @Override protected void onFailure(Throwable exception) { - final GitOutputConsole console = gitOutputConsoleFactory.create(BRANCH_CHECKOUT_COMMAND_NAME); - printGitMessage(exception.getMessage(), console); - consolesPanelPresenter.addCommandOutput(appContext.getDevMachineId(), console); + handleError(exception, BRANCH_CHECKOUT_COMMAND_NAME); } }); } @@ -302,44 +295,25 @@ public class BranchPresenter implements BranchView.ActionDelegate { } } - private void printGitMessage(String messageText, GitOutputConsole console) { - if (messageText == null || messageText.isEmpty()) { - return; - } - JSONObject jsonObject = JSONParser.parseStrict(messageText).isObject(); - if (jsonObject == null) { - return; - } - String message = ""; - if (jsonObject.containsKey("message")) { - message = jsonObject.get("message").isString().stringValue(); - } - - console.print(""); - String[] lines = message.split("\n"); - for (String line : lines) { - console.printError(line); - } - } - /** Get the list of branches. */ private void getBranches() { service.branchList(workspaceId, project.getRootProject(), LIST_ALL, new AsyncRequestCallback>(dtoUnmarshallerFactory.newListUnmarshaller(Branch.class)) { @Override protected void onSuccess(List result) { - view.setBranches(result); - view.showDialogIfClosed(); + if (result.isEmpty()) { + dialogFactory.createMessageDialog(constant.branchTitle(), + constant.initCommitWasNotPerformed(), + null).show(); + } else { + view.setBranches(result); + view.showDialogIfClosed(); + } } @Override protected void onFailure(Throwable exception) { - final String errorMessage = - (exception.getMessage() != null) ? exception.getMessage() : constant.branchesListFailed(); - final GitOutputConsole console = gitOutputConsoleFactory.create(BRANCH_LIST_COMMAND_NAME); - console.printError(errorMessage); - consolesPanelPresenter.addCommandOutput(appContext.getDevMachineId(), console); - notificationManager.notify(constant.branchesListFailed(), FAIL, true, project.getRootProject()); + handleError(exception, BRANCH_LIST_COMMAND_NAME); } } ); @@ -361,16 +335,10 @@ public class BranchPresenter implements BranchView.ActionDelegate { @Override protected void onFailure(Throwable exception) { - final String errorMessage = (exception.getMessage() != null) - ? exception.getMessage() - : constant.branchCreateFailed(); - final GitOutputConsole console = gitOutputConsoleFactory.create(BRANCH_CREATE_COMMAND_NAME); - console.printError(errorMessage); - consolesPanelPresenter.addCommandOutput(appContext.getDevMachineId(), console); - notificationManager.notify(constant.branchCreateFailed(), FAIL, true, project.getRootProject()); + handleError(exception, BRANCH_CREATE_COMMAND_NAME); } - } - ); + + }); } } @@ -400,32 +368,50 @@ public class BranchPresenter implements BranchView.ActionDelegate { /** * Handler some action whether some exception happened. * - * @param throwable + * @param exception * exception what happened - * @param console - * console for displaying error + * @param commandName + * name of the executed command */ - void handleError(@NotNull Throwable throwable, GitOutputConsole console) { - String errorMessage = throwable.getMessage(); - if (errorMessage == null) { - console.printError(constant.branchDeleteFailed()); - notificationManager.notify(constant.branchDeleteFailed(), FAIL, true, project.getRootProject()); + void handleError(@NotNull Throwable exception, String commandName) { + if (getErrorCode(exception) == ErrorCodes.UNABLE_GET_PRIVATE_SSH_KEY) { + dialogFactory.createMessageDialog(commandName, constant.messagesUnableGetSshKey(), null).show(); return; } - try { - errorMessage = dtoFactory.createDtoFromJson(errorMessage, ServiceError.class).getMessage(); - if (errorMessage.equals("Unable get private ssh key")) { - console.printError(constant.messagesUnableGetSshKey()); - notificationManager.notify(constant.messagesUnableGetSshKeyTitle(), constant.messagesUnableGetSshKey(), FAIL, true, - project.getRootProject()); - return; + String errorMessage = exception.getMessage(); + if (errorMessage == null) { + switch (commandName) { + case BRANCH_CREATE_COMMAND_NAME: + errorMessage = constant.branchCreateFailed(); + break; + case BRANCH_DELETE_COMMAND_NAME: + errorMessage = constant.branchDeleteFailed(); + break; + case BRANCH_LIST_COMMAND_NAME: + errorMessage = constant.branchesListFailed(); + break; + case BRANCH_RENAME_COMMAND_NAME: + errorMessage = constant.branchRenameFailed(); + break; + case BRANCH_CHECKOUT_COMMAND_NAME: + errorMessage = constant.branchCheckoutFailed(); + break; } - console.printError(errorMessage); - notificationManager.notify(errorMessage, FAIL, true, project.getRootProject()); - } catch (Exception e) { - console.printError(errorMessage); - notificationManager.notify(errorMessage, FAIL, true, project.getRootProject()); + } + + GitOutputConsole console = gitOutputConsoleFactory.create(commandName); + printGitMessage(errorMessage, console); + consolesPanelPresenter.addCommandOutput(appContext.getDevMachineId(), console); + notificationManager.notify(errorMessage, FAIL, true, project.getRootProject()); + } + + private void printGitMessage(String messageText, GitOutputConsole console) { + console.print(""); + String[] lines = messageText.split("\n"); + for (String line : lines) { + console.printError(line); } } + } diff --git a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/commit/CommitPresenter.java b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/commit/CommitPresenter.java index a84a73fbe5..d467a4bbea 100644 --- a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/commit/CommitPresenter.java +++ b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/commit/CommitPresenter.java @@ -17,6 +17,7 @@ import org.eclipse.che.api.core.ErrorCodes; import org.eclipse.che.api.git.gwt.client.GitServiceClient; import org.eclipse.che.api.git.shared.LogResponse; import org.eclipse.che.api.git.shared.Revision; +import org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto; import org.eclipse.che.ide.api.app.AppContext; import org.eclipse.che.ide.api.notification.NotificationManager; import org.eclipse.che.ide.api.project.node.HasStorablePath; @@ -43,6 +44,7 @@ import java.util.ArrayList; import java.util.List; import static org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL; +import static org.eclipse.che.ide.util.ExceptionUtils.getErrorCode; /** * Presenter for commit changes on git. @@ -275,8 +277,9 @@ public class CommitPresenter implements CommitView.ActionDelegate { @Override public void setAmendCommitMessage() { + final ProjectConfigDto project = appContext.getCurrentProject().getRootProject(); final Unmarshallable unmarshall = dtoUnmarshallerFactory.newUnmarshaller(LogResponse.class); - this.service.log(workspaceId, appContext.getCurrentProject().getRootProject(), null, false, + this.service.log(workspaceId, project, null, false, new AsyncRequestCallback(unmarshall) { @Override protected void onSuccess(final LogResponse result) { @@ -294,8 +297,15 @@ public class CommitPresenter implements CommitView.ActionDelegate { @Override protected void onFailure(final Throwable exception) { - Log.warn(CommitPresenter.class, "Git log failed", exception); - CommitPresenter.this.view.setMessage(""); + if (getErrorCode(exception) == ErrorCodes.INIT_COMMIT_WAS_NOT_PERFORMED) { + dialogFactory.createMessageDialog(constant.commitTitle(), + constant.initCommitWasNotPerformed(), + null).show(); + } else { + Log.warn(CommitPresenter.class, "Git log failed", exception); + CommitPresenter.this.view.setMessage(""); + notificationManager.notify(constant.logFailed(), FAIL, false, project); + } } }); } diff --git a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/compare/revisionsList/RevisionListPresenter.java b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/compare/revisionsList/RevisionListPresenter.java index 531b91ada0..661863c24c 100644 --- a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/compare/revisionsList/RevisionListPresenter.java +++ b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/compare/revisionsList/RevisionListPresenter.java @@ -13,6 +13,7 @@ package org.eclipse.che.ide.ext.git.client.compare.revisionsList; import com.google.inject.Inject; import com.google.inject.Singleton; +import org.eclipse.che.api.core.ErrorCodes; import org.eclipse.che.api.git.gwt.client.GitServiceClient; import org.eclipse.che.api.git.shared.LogResponse; import org.eclipse.che.api.git.shared.Revision; @@ -36,6 +37,7 @@ import java.util.Collections; import static org.eclipse.che.api.git.shared.DiffRequest.DiffType.NAME_STATUS; import static org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL; +import static org.eclipse.che.ide.util.ExceptionUtils.getErrorCode; /** * Presenter for displaying list of revisions for comparing selected with local changes. @@ -149,7 +151,14 @@ public class RevisionListPresenter implements RevisionListView.ActionDelegate { @Override protected void onFailure(Throwable exception) { - notificationManager.notify(locale.logFailed(), FAIL, false); + if (getErrorCode(exception) == ErrorCodes.INIT_COMMIT_WAS_NOT_PERFORMED) { + dialogFactory.createMessageDialog(locale.compareWithRevisionTitle(), + locale.initCommitWasNotPerformed(), + null).show(); + } else { + notificationManager.notify(locale.logFailed(), FAIL, false); + } + } }); } diff --git a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/history/HistoryPresenter.java b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/history/HistoryPresenter.java index a89552010f..f1b71763f1 100644 --- a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/history/HistoryPresenter.java +++ b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/history/HistoryPresenter.java @@ -17,6 +17,7 @@ import com.google.inject.Inject; import com.google.inject.Singleton; import com.google.web.bindery.event.shared.EventBus; +import org.eclipse.che.api.core.ErrorCodes; import org.eclipse.che.api.git.gwt.client.GitServiceClient; import org.eclipse.che.api.git.shared.LogResponse; import org.eclipse.che.api.git.shared.Revision; @@ -42,15 +43,18 @@ import org.eclipse.che.ide.extension.machine.client.processes.ConsolesPanelPrese import org.eclipse.che.ide.rest.AsyncRequestCallback; import org.eclipse.che.ide.rest.DtoUnmarshallerFactory; import org.eclipse.che.ide.rest.StringUnmarshaller; +import org.eclipse.che.ide.ui.dialogs.DialogFactory; import org.vectomatic.dom.svg.ui.SVGResource; import javax.validation.constraints.NotNull; + import java.util.ArrayList; import java.util.Arrays; import java.util.List; import static org.eclipse.che.api.git.shared.DiffRequest.DiffType.RAW; import static org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL; +import static org.eclipse.che.ide.util.ExceptionUtils.getErrorCode; /** * Presenter for showing git history. @@ -71,6 +75,7 @@ public class HistoryPresenter extends BasePresenter implements HistoryView.Actio private final GitLocalizationConstant constant; private final GitResources resources; private final AppContext appContext; + private final DialogFactory dialogFactory; private final WorkspaceAgent workspaceAgent; private final DateTimeFormatter dateTimeFormatter; private final GitOutputConsoleFactory gitOutputConsoleFactory; @@ -94,12 +99,14 @@ public class HistoryPresenter extends BasePresenter implements HistoryView.Actio GitLocalizationConstant constant, AppContext appContext, NotificationManager notificationManager, + DialogFactory dialogFactory, DtoUnmarshallerFactory dtoUnmarshallerFactory, DateTimeFormatter dateTimeFormatter, SelectionAgent selectionAgent, GitOutputConsoleFactory gitOutputConsoleFactory, ConsolesPanelPresenter consolesPanelPresenter) { this.view = view; + this.dialogFactory = dialogFactory; this.dateTimeFormatter = dateTimeFormatter; this.gitOutputConsoleFactory = gitOutputConsoleFactory; this.consolesPanelPresenter = consolesPanelPresenter; @@ -155,7 +162,7 @@ public class HistoryPresenter extends BasePresenter implements HistoryView.Actio /** Get the log of the commits. If successfully received, then display in revision grid, otherwise - show error in output panel. */ private void getCommitsLog(final ProjectConfigDto project) { - service.log(workspaceId, project, null, false, + service.log(workspaceId, project, null, false, new AsyncRequestCallback(dtoUnmarshallerFactory.newUnmarshaller(LogResponse.class)) { @Override protected void onSuccess(LogResponse result) { @@ -165,12 +172,21 @@ public class HistoryPresenter extends BasePresenter implements HistoryView.Actio @Override protected void onFailure(Throwable exception) { - nothingToDisplay(null); - String errorMessage = exception.getMessage() != null ? exception.getMessage() : constant.logFailed(); - GitOutputConsole console = gitOutputConsoleFactory.create(LOG_COMMAND_NAME); - console.printError(errorMessage); - consolesPanelPresenter.addCommandOutput(appContext.getDevMachineId(), console); - notificationManager.notify(constant.logFailed(), FAIL, true, project); + if (getErrorCode(exception) == ErrorCodes.INIT_COMMIT_WAS_NOT_PERFORMED) { + dialogFactory.createMessageDialog(constant.historyTitle(), + constant.initCommitWasNotPerformed(), + null).show(); + } else { + nothingToDisplay(null); + String errorMessage = exception.getMessage() != null ? exception.getMessage() : constant.logFailed(); + GitOutputConsole console = gitOutputConsoleFactory.create(LOG_COMMAND_NAME); + console.printError(errorMessage); + consolesPanelPresenter.addCommandOutput(appContext.getDevMachineId(), console); + notificationManager.notify(constant.logFailed(), FAIL, true, project); + } + partStack.hidePart(HistoryPresenter.this); + workspaceAgent.removePart(HistoryPresenter.this); + isViewClosed = true; } }); } diff --git a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/reset/commit/ResetToCommitPresenter.java b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/reset/commit/ResetToCommitPresenter.java index 2e788b6283..d2966dcc59 100644 --- a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/reset/commit/ResetToCommitPresenter.java +++ b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/reset/commit/ResetToCommitPresenter.java @@ -14,6 +14,7 @@ import com.google.inject.Inject; import com.google.inject.Singleton; import com.google.web.bindery.event.shared.EventBus; +import org.eclipse.che.api.core.ErrorCodes; import org.eclipse.che.api.git.gwt.client.GitServiceClient; import org.eclipse.che.api.git.shared.LogResponse; import org.eclipse.che.api.git.shared.ResetRequest; @@ -30,13 +31,16 @@ import org.eclipse.che.ide.ext.git.client.outputconsole.GitOutputConsoleFactory; import org.eclipse.che.ide.extension.machine.client.processes.ConsolesPanelPresenter; import org.eclipse.che.ide.rest.AsyncRequestCallback; import org.eclipse.che.ide.rest.DtoUnmarshallerFactory; +import org.eclipse.che.ide.ui.dialogs.DialogFactory; import javax.validation.constraints.NotNull; + import java.util.ArrayList; import java.util.List; import static org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL; import static org.eclipse.che.ide.ext.git.client.history.HistoryPresenter.LOG_COMMAND_NAME; +import static org.eclipse.che.ide.util.ExceptionUtils.getErrorCode; /** * Presenter for resetting head to commit. @@ -50,6 +54,7 @@ public class ResetToCommitPresenter implements ResetToCommitView.ActionDelegate private final DtoUnmarshallerFactory dtoUnmarshallerFactory; private final ResetToCommitView view; private final GitOutputConsoleFactory gitOutputConsoleFactory; + private final DialogFactory dialogFactory; private final ConsolesPanelPresenter consolesPanelPresenter; private final GitServiceClient service; private final AppContext appContext; @@ -68,12 +73,14 @@ public class ResetToCommitPresenter implements ResetToCommitView.ActionDelegate GitLocalizationConstant constant, EventBus eventBus, EditorAgent editorAgent, + DialogFactory dialogFactory, AppContext appContext, NotificationManager notificationManager, DtoUnmarshallerFactory dtoUnmarshallerFactory, GitOutputConsoleFactory gitOutputConsoleFactory, ConsolesPanelPresenter consolesPanelPresenter) { this.view = view; + this.dialogFactory = dialogFactory; this.gitOutputConsoleFactory = gitOutputConsoleFactory; this.consolesPanelPresenter = consolesPanelPresenter; this.view.setDelegate(this); @@ -103,6 +110,12 @@ public class ResetToCommitPresenter implements ResetToCommitView.ActionDelegate @Override protected void onFailure(Throwable exception) { + if (getErrorCode(exception) == ErrorCodes.INIT_COMMIT_WAS_NOT_PERFORMED) { + dialogFactory.createMessageDialog(constant.resetCommitViewTitle(), + constant.initCommitWasNotPerformed(), + null).show(); + return; + } String errorMessage = (exception.getMessage() != null) ? exception.getMessage() : constant.logFailed(); GitOutputConsole console = gitOutputConsoleFactory.create(LOG_COMMAND_NAME); console.printError(errorMessage); diff --git a/plugins/plugin-git/che-plugin-git-ext-git/src/main/resources/org/eclipse/che/ide/ext/git/client/GitLocalizationConstant.properties b/plugins/plugin-git/che-plugin-git-ext-git/src/main/resources/org/eclipse/che/ide/ext/git/client/GitLocalizationConstant.properties index c7b9352291..59ce4317de 100644 --- a/plugins/plugin-git/che-plugin-git-ext-git/src/main/resources/org/eclipse/che/ide/ext/git/client/GitLocalizationConstant.properties +++ b/plugins/plugin-git/che-plugin-git-ext-git/src/main/resources/org/eclipse/che/ide/ext/git/client/GitLocalizationConstant.properties @@ -28,8 +28,8 @@ button.push=Push button.pull=Pull ############MESSAGES################ -messages.unableGetSshKeyTitle=Failed to get private ssh key -messages.unableGetSshKey = You can create a new SSH key pair in Window->Preferences->Keys->SSH Keystore. +messages.unableGetSshKey = Failed to get private ssh key. \ + You can create a new SSH key pair in Help->Preferences->SSH->Git. messages.warningTitle = Warning messages.index_empty=Index is empty messages.add_success=Git index updated @@ -50,6 +50,7 @@ messages.committer_identity_info_empty=Git user name and (or) email was not set. You can set this information in Help -> Preferences -> Git -> Committer. messages.diff.failed=Failed to get diff messages.log_failed=Failed to load commits history +messages.init_commit_was_not_performed=Initial commit is required to perform this operation. messages.init_success=Repository initialized messages.init_failed=Failed to initialize repository messages.initRepoQuestion = Do you want to initialize the local repository {0}? diff --git a/plugins/plugin-git/che-plugin-git-ext-git/src/test/java/org/eclipse/che/ide/ext/git/client/history/HistoryPresenterTest.java b/plugins/plugin-git/che-plugin-git-ext-git/src/test/java/org/eclipse/che/ide/ext/git/client/history/HistoryPresenterTest.java index e6de5b5d70..eb70661d17 100644 --- a/plugins/plugin-git/che-plugin-git-ext-git/src/test/java/org/eclipse/che/ide/ext/git/client/history/HistoryPresenterTest.java +++ b/plugins/plugin-git/che-plugin-git-ext-git/src/test/java/org/eclipse/che/ide/ext/git/client/history/HistoryPresenterTest.java @@ -98,6 +98,7 @@ public class HistoryPresenterTest extends BaseTest { constant, appContext, notificationManager, + dialogFactory, dtoUnmarshallerFactory, dateTimeFormatter, selectionAgent, diff --git a/plugins/plugin-git/che-plugin-git-ext-git/src/test/java/org/eclipse/che/ide/ext/git/client/reset/commit/ResetToCommitPresenterTest.java b/plugins/plugin-git/che-plugin-git-ext-git/src/test/java/org/eclipse/che/ide/ext/git/client/reset/commit/ResetToCommitPresenterTest.java index 27674ad10d..9c01e32f4c 100644 --- a/plugins/plugin-git/che-plugin-git-ext-git/src/test/java/org/eclipse/che/ide/ext/git/client/reset/commit/ResetToCommitPresenterTest.java +++ b/plugins/plugin-git/che-plugin-git-ext-git/src/test/java/org/eclipse/che/ide/ext/git/client/reset/commit/ResetToCommitPresenterTest.java @@ -83,6 +83,7 @@ public class ResetToCommitPresenterTest extends BaseTest { constant, eventBus, editorAgent, + dialogFactory, appContext, notificationManager, dtoUnmarshallerFactory, diff --git a/plugins/plugin-github/che-plugin-github-ext-github/src/main/resources/org/eclipse/che/ide/ext/github/client/GitHubLocalizationConstant.properties b/plugins/plugin-github/che-plugin-github-ext-github/src/main/resources/org/eclipse/che/ide/ext/github/client/GitHubLocalizationConstant.properties index fa460cfdb2..32cf7e72c3 100644 --- a/plugins/plugin-github/che-plugin-github-ext-github/src/main/resources/org/eclipse/che/ide/ext/github/client/GitHubLocalizationConstant.properties +++ b/plugins/plugin-github/che-plugin-github-ext-github/src/main/resources/org/eclipse/che/ide/ext/github/client/GitHubLocalizationConstant.properties @@ -16,7 +16,7 @@ authorization.dialog.title = Authorization authorization.dialog.text = {0} requests authorization through OAuth2 protocol authorization.generateKeyLabel = generate ssh key and upload it on GitHub authorization.message.unableCreateSshKey = Unable create private ssh key. \ - You can create a new SSH key pair in Window->Preferences->Keys->SSH Keystore. + You can create a new SSH key pair in Help->Preferences->SSH->Git. authorization.message.keyUploadSuccess = Ssh key uploaded ############### SamplesListGrid ############### samplesListGrid.column.name=Project