diff --git a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/git/GitServiceClient.java b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/git/GitServiceClient.java index b29bafd0034..0ca64c7ae78 100644 --- a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/git/GitServiceClient.java +++ b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/git/GitServiceClient.java @@ -758,6 +758,24 @@ void commit(DevMachine devMachine, */ Promise commit(DevMachine devMachine, Path project, String message, Path[] files, boolean amend); + /** + * Performs commit changes from index to repository. + * + * @param devMachine + * current machine + * @param project + * project (root of GIT repository) + * @param message + * commit log message + * @param all + * automatically stage files that have been modified and deleted + * @param files + * the list of files that are committed, ignoring the index + * @param amend + * indicates that previous commit must be overwritten + */ + Promise commit(DevMachine devMachine, Path project, String message, boolean all, Path[] files, boolean amend); + /** * Get repository options. * diff --git a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/git/GitServiceClientImpl.java b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/git/GitServiceClientImpl.java index d74b72f5a19..32d600c9f46 100644 --- a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/git/GitServiceClientImpl.java +++ b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/git/GitServiceClientImpl.java @@ -339,7 +339,11 @@ public void commit(final DevMachine devMachine, @Override public Promise commit(DevMachine devMachine, Path project, String message, Path[] files, boolean amend) { + return commit(devMachine, project, message, false, files, amend); + } + @Override + public Promise commit(DevMachine devMachine, Path project, String message, boolean all, Path[] files, boolean amend) { List paths = new ArrayList<>(files.length); for (Path file : files) { @@ -349,7 +353,7 @@ public Promise commit(DevMachine devMachine, Path project, String mess CommitRequest commitRequest = dtoFactory.createDto(CommitRequest.class) .withMessage(message) .withAmend(amend) - .withAll(false) + .withAll(all) .withFiles(paths); String url = devMachine.getWsAgentBaseUrl() + COMMIT + "?projectPath=" + project; diff --git a/ide/che-core-ide-ui/src/main/java/org/eclipse/che/ide/ui/smartTree/SelectionModel.java b/ide/che-core-ide-ui/src/main/java/org/eclipse/che/ide/ui/smartTree/SelectionModel.java index 80082329d3d..5cefffabee6 100644 --- a/ide/che-core-ide-ui/src/main/java/org/eclipse/che/ide/ui/smartTree/SelectionModel.java +++ b/ide/che-core-ide-ui/src/main/java/org/eclipse/che/ide/ui/smartTree/SelectionModel.java @@ -782,7 +782,9 @@ protected void onUpdate(Node model) { } protected void onRemove(Node model) { - selectionStorage.remove(model); + if(selectionStorage.remove(model)) { + fireSelectionChange(); + } } public List getSelectedNodes() { diff --git a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/GitExtension.java b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/GitExtension.java index b072a15c9f9..96b72356b09 100644 --- a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/GitExtension.java +++ b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/GitExtension.java @@ -154,14 +154,23 @@ public GitExtension(GitResources resources, actionManager.registerAction("gitCompareWithRevision", compareWithRevisionAction); compareGroup.add(compareWithRevisionAction); - DefaultActionGroup gitCompareContextMenuGroup = new DefaultActionGroup("Git", true, actionManager); - actionManager.registerAction("gitCompareContextMenu", gitCompareContextMenuGroup); - gitCompareContextMenuGroup.add(compareWithLatestAction); - gitCompareContextMenuGroup.add(compareWithBranchAction); - gitCompareContextMenuGroup.add(compareWithRevisionAction); - - DefaultActionGroup mainContextMenuGroup = (DefaultActionGroup)actionManager.getAction("resourceOperation"); - mainContextMenuGroup.add(gitCompareContextMenuGroup); + DefaultActionGroup gitContextMenuGroup = new DefaultActionGroup("Git", true, actionManager); + actionManager.registerAction("gitCompareContextMenu", gitContextMenuGroup); + gitContextMenuGroup.add(addToIndexAction); + gitContextMenuGroup.add(removeFromIndexAction); + gitContextMenuGroup.add(resetFilesAction); + gitContextMenuGroup.add(commitAction); + gitContextMenuGroup.addSeparator(); + gitContextMenuGroup.add(compareWithLatestAction); + gitContextMenuGroup.add(compareWithBranchAction); + gitContextMenuGroup.add(compareWithRevisionAction); + + DefaultActionGroup projectExplorerContextMenuGroup = (DefaultActionGroup)actionManager.getAction("resourceOperation"); + projectExplorerContextMenuGroup.add(gitContextMenuGroup); + + DefaultActionGroup editorContextMenuGroup = (DefaultActionGroup)actionManager.getAction("editorContextMenu"); + editorContextMenuGroup.addSeparator(); + editorContextMenuGroup.add(gitContextMenuGroup); keyBinding.getGlobal().addKey(new KeyBuilder().action().alt().charCode('d').build(), "gitCompareWithLatest"); } 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 676bddfcf14..a328eee69ab 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 @@ -11,7 +11,6 @@ package org.eclipse.che.ide.ext.git.client; import com.google.gwt.i18n.client.Messages; -import com.google.gwt.safehtml.shared.SafeHtml; /** @author Evgen Vidolob */ public interface GitLocalizationConstant extends Messages { @@ -95,6 +94,9 @@ public interface GitLocalizationConstant extends Messages { @Key("messages.nothingAddToIndex") String nothingAddToIndex(); + @Key("messages.nothingAddToIndexMultiSelect") + String nothingAddToIndexMultiSelect(); + @Key("messages.add_failed") String addFailed(); @@ -294,14 +296,14 @@ public interface GitLocalizationConstant extends Messages { @Key("view.add_to_index.all_changes") String addToIndexAllChanges(); - @Key("view.add_to_index.multiple") - String addToIndexMultiple(); + @Key("view.add_to_index.multiselect") + String addToIndexMultiSelect(); @Key("view.add_to_index.folder") - SafeHtml addToIndexFolder(String folder); + String addToIndexFolder(String folder); @Key("view.add_to_index.file") - SafeHtml addToIndexFile(String file); + String addToIndexFile(String file); @Key("view.add_to_index.update_field_title") String addToIndexUpdateFieldTitle(); @@ -309,6 +311,9 @@ public interface GitLocalizationConstant extends Messages { @Key("view.add_to_index.title") String addToIndexTitle(); + @Key("view.add_to_index.command_name") + String addToIndexCommandName(); + // Branch @Key("view.branch.create_new") String branchCreateNew(); @@ -348,13 +353,13 @@ public interface GitLocalizationConstant extends Messages { String commitTitle(); @Key("view.commit.all_field_title") - String commitAllFieldTitle(); + String commitAddAllFieldTitle(); @Key("view.commit.selection_field_title") String commitSelectionFieldTitle(); - @Key("view.commit.onlyselection_field_title") - String commitOnlySelectionFieldTitle(); + @Key("view.commit.all_project_field_title") + String commitAllFieldTitle(); @Key("view.commit.amend_field_title") String commitAmendFieldTitle(); @@ -413,10 +418,10 @@ public interface GitLocalizationConstant extends Messages { String removeFromIndexOnly(); @Key("view.remove_from_index.folder") - SafeHtml removeFromIndexFolder(String folder); + String removeFromIndexFolder(String folder); @Key("view.remove_from_index.file") - SafeHtml removeFromIndexFile(String file); + String removeFromIndexFile(String file); @Key("view.remove_from_index.title") String removeFromIndexTitle(); diff --git a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/action/AddToIndexAction.java b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/action/AddToIndexAction.java index f43f289b873..afd4dfb9175 100644 --- a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/action/AddToIndexAction.java +++ b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/action/AddToIndexAction.java @@ -13,38 +13,129 @@ import com.google.inject.Inject; import com.google.inject.Singleton; +import org.eclipse.che.api.git.shared.Status; +import org.eclipse.che.api.promises.client.Operation; +import org.eclipse.che.api.promises.client.OperationException; +import org.eclipse.che.api.promises.client.PromiseError; import org.eclipse.che.ide.api.action.ActionEvent; import org.eclipse.che.ide.api.app.AppContext; -import org.eclipse.che.ide.api.resources.Project; +import org.eclipse.che.ide.api.git.GitServiceClient; +import org.eclipse.che.ide.api.machine.DevMachine; +import org.eclipse.che.ide.api.notification.NotificationManager; +import org.eclipse.che.ide.api.resources.Resource; import org.eclipse.che.ide.ext.git.client.GitLocalizationConstant; import org.eclipse.che.ide.ext.git.client.add.AddToIndexPresenter; import org.eclipse.che.ide.FontAwesome; +import org.eclipse.che.ide.ext.git.client.outputconsole.GitOutputConsole; +import org.eclipse.che.ide.ext.git.client.outputconsole.GitOutputConsoleFactory; +import org.eclipse.che.ide.extension.machine.client.processes.panel.ProcessesPanelPresenter; +import org.eclipse.che.ide.resource.Path; + +import java.util.List; import static com.google.common.base.Preconditions.checkState; +import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.FLOAT_MODE; +import static org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL; /** * @author Andrey Plotnikov * @author Vlad Zhukovskyi + * @author Igor Vinokur **/ @Singleton public class AddToIndexAction extends GitAction { - private final AddToIndexPresenter presenter; + + private final AddToIndexPresenter presenter; + private final GitLocalizationConstant constant; + private final GitOutputConsoleFactory gitOutputConsoleFactory; + private final ProcessesPanelPresenter consolesPanelPresenter; + private final GitServiceClient service; + private final NotificationManager notificationManager; @Inject public AddToIndexAction(AddToIndexPresenter presenter, AppContext appContext, - GitLocalizationConstant constant) { + GitLocalizationConstant constant, + GitOutputConsoleFactory gitOutputConsoleFactory, + ProcessesPanelPresenter consolesPanelPresenter, + GitServiceClient service, + NotificationManager notificationManager) { super(constant.addToIndexTitle(), constant.addToIndexTitle(), FontAwesome.PLUS, appContext); this.presenter = presenter; + this.constant = constant; + this.gitOutputConsoleFactory = gitOutputConsoleFactory; + this.consolesPanelPresenter = consolesPanelPresenter; + this.service = service; + this.notificationManager = notificationManager; } /** {@inheritDoc} */ @Override public void actionPerformed(ActionEvent e) { - final Project project = appContext.getRootProject(); + final Resource[] resources = appContext.getResources(); + checkState(resources != null); + final DevMachine devMachine = appContext.getDevMachine(); + final GitOutputConsole console = gitOutputConsoleFactory.create(constant.addToIndexCommandName()); + consolesPanelPresenter.addCommandOutput(devMachine.getId(), console); + service.getStatus(devMachine, appContext.getRootProject().getLocation()) + .then(new Operation() { + @Override + public void apply(Status status) throws OperationException { + if (containsInSelected(status.getUntracked())) { + presenter.showDialog(); + } else if (containsInSelected(status.getModified())) { + addToIndex(console); + } else { + String message = resources.length > 1 ? constant.nothingAddToIndexMultiSelect() : constant.nothingAddToIndex(); + console.print(message); + notificationManager.notify(message); + } + } + }) + .catchError(new Operation() { + @Override + public void apply(PromiseError error) throws OperationException { + console.printError(constant.statusFailed()); + notificationManager.notify(constant.statusFailed(), FAIL, FLOAT_MODE); + } + }); + } - checkState(project != null, "Null project occurred"); + private void addToIndex(final GitOutputConsole console) { + Resource[] resources = appContext.getResources(); + Path[] paths = new Path[resources.length]; + for (int i = 0; i < resources.length; i++) { + Path path = resources[i].getLocation().removeFirstSegments(1); + paths[i] = path.segmentCount() == 0 ? Path.EMPTY : path; + } + service.add(appContext.getDevMachine(), appContext.getRootProject().getLocation(), false, paths) + .then(new Operation() { + @Override + public void apply(Void arg) throws OperationException { + console.print(constant.addSuccess()); + notificationManager.notify(constant.addSuccess()); + } + }) + .catchError(new Operation() { + @Override + public void apply(PromiseError arg) throws OperationException { + console.printError(constant.addFailed()); + notificationManager.notify(constant.addFailed(), FAIL, FLOAT_MODE); + } + }); + } - presenter.showDialog(project); + private boolean containsInSelected(List items) { + for (String item : items) { + for (Resource selectedItem : appContext.getResources()) { + String selectedItemPath = selectedItem.getLocation() + .removeFirstSegments(appContext.getRootProject().getLocation().segmentCount()) + .toString(); + if (item.startsWith(selectedItemPath)) { + return true; + } + } + } + return false; } } diff --git a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/add/AddToIndexPresenter.java b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/add/AddToIndexPresenter.java index b1054627bf9..f97b6468154 100644 --- a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/add/AddToIndexPresenter.java +++ b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/add/AddToIndexPresenter.java @@ -13,14 +13,14 @@ import com.google.inject.Inject; import com.google.inject.Singleton; -import org.eclipse.che.api.git.shared.Status; import org.eclipse.che.api.promises.client.Operation; import org.eclipse.che.api.promises.client.OperationException; import org.eclipse.che.api.promises.client.PromiseError; import org.eclipse.che.ide.api.app.AppContext; import org.eclipse.che.ide.api.git.GitServiceClient; +import org.eclipse.che.ide.api.machine.DevMachine; import org.eclipse.che.ide.api.notification.NotificationManager; -import org.eclipse.che.ide.api.resources.Project; +import org.eclipse.che.ide.api.resources.Container; import org.eclipse.che.ide.api.resources.Resource; import org.eclipse.che.ide.ext.git.client.GitLocalizationConstant; import org.eclipse.che.ide.ext.git.client.outputconsole.GitOutputConsole; @@ -28,7 +28,6 @@ import org.eclipse.che.ide.extension.machine.client.processes.panel.ProcessesPanelPresenter; import org.eclipse.che.ide.resource.Path; -import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkState; import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.FLOAT_MODE; import static org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL; @@ -38,10 +37,10 @@ * * @author Ann Zhuleva * @author Vlad Zhukovskyi + * @author Igor Vinokur */ @Singleton public class AddToIndexPresenter implements AddToIndexView.ActionDelegate { - protected static final String ADD_TO_INDEX_COMMAND_NAME = "Git add to index"; private final AddToIndexView view; private final GitServiceClient service; @@ -50,7 +49,6 @@ public class AddToIndexPresenter implements AddToIndexView.ActionDelegate { private final NotificationManager notificationManager; private final GitOutputConsoleFactory gitOutputConsoleFactory; private final ProcessesPanelPresenter consolesPanelPresenter; - private Project project; @Inject public AddToIndexPresenter(AddToIndexView view, @@ -70,77 +68,53 @@ public AddToIndexPresenter(AddToIndexView view, this.consolesPanelPresenter = processesPanelPresenter; } - public void showDialog(Project project) { - this.project = project; - - checkArgument(project != null, "Null project occurred"); - - final GitOutputConsole console = gitOutputConsoleFactory.create(ADD_TO_INDEX_COMMAND_NAME); - - service.getStatus(appContext.getDevMachine(), project.getLocation()).then(new Operation() { - @Override - public void apply(Status status) throws OperationException { - if (!status.isClean()) { - final Resource[] resources = appContext.getResources(); - - checkState(resources != null && resources.length > 0); - - view.setMessage(constant.addToIndexAllChanges(), null); - view.setUpdated(false); - view.showDialog(); - } else { - console.print(constant.nothingAddToIndex()); - consolesPanelPresenter.addCommandOutput(appContext.getDevMachine().getId(), console); - notificationManager.notify(constant.nothingAddToIndex()); - } - } - }).catchError(new Operation() { - @Override - public void apply(PromiseError error) throws OperationException { - console.printError(constant.statusFailed()); - consolesPanelPresenter.addCommandOutput(appContext.getDevMachine().getId(), console); - notificationManager.notify(constant.statusFailed(), FAIL, FLOAT_MODE); + public void showDialog() { + Resource[] resources = appContext.getResources(); + checkState(resources != null && resources.length > 0); + if (resources.length == 1) { + Resource resource = appContext.getResource(); + if (resource instanceof Container) { + view.setMessage(constant.addToIndexFolder(resource.getName())); + } else { + view.setMessage(constant.addToIndexFile(resource.getName())); } - }); + } else { + view.setMessage(constant.addToIndexMultiSelect()); + } + view.setUpdated(false); + view.showDialog(); } - /** {@inheritDoc} */ @Override public void onAddClicked() { - final GitOutputConsole console = gitOutputConsoleFactory.create(ADD_TO_INDEX_COMMAND_NAME); - final Resource[] resources = appContext.getResources(); - - checkState(resources != null && resources.length > 0); - - final Path[] paths = new Path[resources.length]; - + DevMachine devMachine = appContext.getDevMachine(); + Resource[] resources = appContext.getResources(); + Path projectLocation = appContext.getRootProject().getLocation(); + Path[] paths = new Path[resources.length]; for (int i = 0; i < resources.length; i++) { - checkState(project.getLocation().isPrefixOf(resources[i].getLocation())); - - final Path tmpPath = resources[i].getLocation().removeFirstSegments(project.getLocation().segmentCount()); - - paths[i] = tmpPath.segmentCount() == 0 ? Path.EMPTY : tmpPath; + Path path = resources[i].getLocation().removeFirstSegments(projectLocation.segmentCount()); + paths[i] = path.segmentCount() == 0 ? Path.EMPTY : path; } - - service.add(appContext.getDevMachine(), project.getLocation(), view.isUpdated(), paths).then(new Operation() { - @Override - public void apply(Void arg) throws OperationException { - console.print(constant.addSuccess()); - consolesPanelPresenter.addCommandOutput(appContext.getDevMachine().getId(), console); - notificationManager.notify(constant.addSuccess()); - view.close(); - } - }).catchError(new Operation() { - @Override - public void apply(PromiseError arg) throws OperationException { - String errorMessage = constant.addFailed(); - console.printError(errorMessage); - consolesPanelPresenter.addCommandOutput(appContext.getDevMachine().getId(), console); - notificationManager.notify(constant.addFailed(), FAIL, FLOAT_MODE); - view.close(); - } - }); + final GitOutputConsole console = gitOutputConsoleFactory.create(constant.addToIndexCommandName()); + consolesPanelPresenter.addCommandOutput(devMachine.getId(), console); + service.add(devMachine, projectLocation, view.isUpdated(), paths) + .then(new Operation() { + @Override + public void apply(Void arg) throws OperationException { + console.print(constant.addSuccess()); + notificationManager.notify(constant.addSuccess()); + view.close(); + } + }) + .catchError(new Operation() { + @Override + public void apply(PromiseError arg) throws OperationException { + console.printError(constant.addFailed()); + notificationManager.notify(constant.addFailed(), FAIL, FLOAT_MODE); + view.close(); + } + }); } /** {@inheritDoc} */ diff --git a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/add/AddToIndexView.java b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/add/AddToIndexView.java index 54dde057dc3..b35ec6f415e 100644 --- a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/add/AddToIndexView.java +++ b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/add/AddToIndexView.java @@ -11,9 +11,6 @@ package org.eclipse.che.ide.ext.git.client.add; import org.eclipse.che.ide.api.mvp.View; -import java.util.List; - -import javax.validation.constraints.NotNull; /** @@ -23,7 +20,7 @@ */ public interface AddToIndexView extends View { /** Needs for delegate some function into CloneRepository view. */ - public interface ActionDelegate { + interface ActionDelegate { /** Performs any actions appropriate in response to the user having pressed the Add button. */ void onAddClicked(); @@ -34,10 +31,10 @@ public interface ActionDelegate { /** * Set content into message field. * - * @param message - * content of message + * @param htmlMessage + * content of the message in html format */ - void setMessage(@NotNull String message, @NotNull List items); + void setMessage(String htmlMessage); /** @return true if new file must be added to index, and false otherwise */ boolean isUpdated(); diff --git a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/add/AddToIndexViewImpl.java b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/add/AddToIndexViewImpl.java index 76c48ddb385..6dbeed8d3fb 100644 --- a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/add/AddToIndexViewImpl.java +++ b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/add/AddToIndexViewImpl.java @@ -13,6 +13,7 @@ import org.eclipse.che.ide.ext.git.client.GitLocalizationConstant; import org.eclipse.che.ide.ext.git.client.GitResources; import org.eclipse.che.ide.ui.window.Window; + import com.google.gwt.core.client.GWT; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; @@ -20,14 +21,11 @@ import com.google.gwt.uibinder.client.UiField; import com.google.gwt.user.client.ui.Button; import com.google.gwt.user.client.ui.CheckBox; -import com.google.gwt.user.client.ui.HTML; -import com.google.gwt.user.client.ui.TextArea; +import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.Widget; import com.google.inject.Inject; import com.google.inject.Singleton; -import java.util.List; -import javax.validation.constraints.NotNull; /** * The implementation of {@link AddToIndexView}. * @@ -41,9 +39,7 @@ interface AddToIndexViewImplUiBinder extends UiBinder items) { - this.message.setHTML(message); - if (items == null || items.isEmpty()) { - this.items.setVisible(false); - this.items.setText(""); - } else { - this.items.setVisible(true); - final StringBuilder sb = new StringBuilder(); - String toAppend = ""; - for (String item : items) { - sb.append(toAppend); - toAppend = "\n"; - sb.append(item); - } - this.items.setText(sb.toString()); - } + public void setMessage(String htmlMessage) { + this.message.getElement().setInnerHTML(htmlMessage); } /** {@inheritDoc} */ diff --git a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/add/AddToIndexViewImpl.ui.xml b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/add/AddToIndexViewImpl.ui.xml index b1427d381b8..9040ee402b9 100644 --- a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/add/AddToIndexViewImpl.ui.xml +++ b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/add/AddToIndexViewImpl.ui.xml @@ -16,16 +16,12 @@ - .spacing { - margin-bottom: 10px; - } - .emptyBorder { + .content { margin: 6px; - } - .leftPadding { - padding-left: 3px; + width: 480px; + height: 80px; } .panel { @@ -36,18 +32,17 @@ -webkit-align-items: stretch; align-items: stretch; } - .items { - resize: none; - max-height: 10em; - -webkit-flex-grow: 1; - flex-grow: 1; + + .label { + padding: 3px; + overflow: hidden; } - - - + + + + - - - \ 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/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 f9704708002..20166ad4fbf 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 @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.che.ide.ext.git.client.commit; +import com.google.common.annotations.VisibleForTesting; import com.google.inject.Inject; import com.google.inject.Singleton; @@ -40,7 +41,6 @@ import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.FLOAT_MODE; import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.NOT_EMERGE_MODE; import static org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL; -import static org.eclipse.che.ide.util.Arrays.isNullOrEmpty; import static org.eclipse.che.ide.util.ExceptionUtils.getErrorCode; /** @@ -48,10 +48,11 @@ * * @author Ann Zhuleva * @author Vlad Zhukovskyi + * @author Igor Vinokur */ @Singleton public class CommitPresenter implements CommitView.ActionDelegate { - public static final String COMMIT_COMMAND_NAME = "Git commit"; + private static final String COMMIT_COMMAND_NAME = "Git commit"; private final DialogFactory dialogFactory; private final AppContext appContext; @@ -63,7 +64,7 @@ public class CommitPresenter implements CommitView.ActionDelegate { private final GitOutputConsoleFactory gitOutputConsoleFactory; private final ProcessesPanelPresenter consolesPanelPresenter; - private Project project; + private Project project; @Inject public CommitPresenter(CommitView view, @@ -90,10 +91,10 @@ public CommitPresenter(CommitView view, public void showDialog(Project project) { this.project = project; + view.setAddAllExceptNew(false); + view.setAddSelectedFiles(false); + view.setCommitAllFiles(false); view.setAmend(false); - view.setAllFilesInclude(false); - view.setIncludeSelection(false); - view.setOnlySelection(false); view.setEnableCommitButton(!view.getMessage().isEmpty()); view.showDialog(); view.focusInMessageField(); @@ -103,37 +104,29 @@ public void showDialog(Project project) { @Override public void onCommitClicked() { final String message = view.getMessage(); - final boolean all = view.isAllFilesInclued(); + final boolean addAll = view.isAddAllExceptNew(); + final boolean addSelected = view.isAddSelectedFiles(); + final boolean commitAll = view.isCommitAllFiles(); final boolean amend = view.isAmend(); - final boolean selectionFlag = this.view.isIncludeSelection(); - final boolean onlySelectionFlag = this.view.isOnlySelection(); - if (selectionFlag) { - addAndCommitSelection(message, amend); - } else if (onlySelectionFlag) { - commitSelection(message, amend); + if (addSelected) { + addSelectedAndCommit(message, commitAll, amend); } else { - doCommit(message, all, amend); + doCommit(message, addAll, commitAll, amend); } } - protected void addAndCommitSelection(final String message, final boolean amend) { - final Resource[] resources = appContext.getResources(); - - if (isNullOrEmpty(resources)) { - doCommit(message, false, amend); - } else { - service.add(appContext.getDevMachine(), project.getLocation(), false, toRelativePaths(resources)) - .then(new Operation() { - @Override - public void apply(Void ignored) throws OperationException { - doCommit(message, false, amend); - } - }); - } + private void addSelectedAndCommit(final String message, final boolean commitAll, final boolean amend) { + service.add(appContext.getDevMachine(), project.getLocation(), false, toRelativePaths(appContext.getResources())) + .then(new Operation() { + @Override + public void apply(Void ignored) throws OperationException { + doCommit(message, false, commitAll, amend); + } + }); } - protected Path[] toRelativePaths(Resource[] resources) { + private Path[] toRelativePaths(Resource[] resources) { final Path[] paths = new Path[resources.length]; for (int i = 0; i < resources.length; i++) { @@ -147,23 +140,16 @@ protected Path[] toRelativePaths(Resource[] resources) { return paths; } - protected void commitSelection(final String message, final boolean amend) { + @VisibleForTesting + void doCommit(final String message, final boolean addAll, final boolean commitAll, final boolean amend) { final Resource[] resources = appContext.getResources(); - - checkState(!isNullOrEmpty(resources)); - - service.commit(appContext.getDevMachine(), project.getLocation(), message, toRelativePaths(resources), amend) - .then(new Operation() { - @Override - public void apply(Revision revision) throws OperationException { - onCommitSuccess(revision); - view.close(); - } - }); - } - - protected void doCommit(final String message, final boolean all, final boolean amend) { - service.commit(appContext.getDevMachine(), project.getLocation(), message, all, amend) + checkState(resources != null); + service.commit(appContext.getDevMachine(), + project.getLocation(), + message, + addAll, + commitAll ? new Path[]{Path.valueOf(".")} : toRelativePaths(resources), + amend) .then(new Operation() { @Override public void apply(Revision revision) throws OperationException { @@ -180,7 +166,7 @@ public void apply(PromiseError error) throws OperationException { }); } - protected void onCommitSuccess(@NotNull final Revision revision) { + private void onCommitSuccess(@NotNull final Revision revision) { String date = dateTimeFormatter.getFormattedDate(revision.getCommitTime()); String message = constant.commitMessage(revision.getId(), date); @@ -195,7 +181,7 @@ protected void onCommitSuccess(@NotNull final Revision revision) { view.setMessage(""); } - protected void handleError(@NotNull Throwable exception) { + private void handleError(@NotNull Throwable exception) { if (exception instanceof ServerException && ((ServerException)exception).getErrorCode() == ErrorCodes.NO_COMMITTER_NAME_OR_EMAIL_DEFINED) { dialogFactory.createMessageDialog(constant.commitTitle(), constant.committerIdentityInfoEmpty(), null).show(); diff --git a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/commit/CommitView.java b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/commit/CommitView.java index 26294f326ea..01d60ed4a89 100644 --- a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/commit/CommitView.java +++ b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/commit/CommitView.java @@ -21,7 +21,7 @@ */ public interface CommitView extends View { /** Needs for delegate some function into Commit view. */ - public interface ActionDelegate { + interface ActionDelegate { /** Performs any actions appropriate in response to the user having pressed the Commit button. */ void onCommitClicked(); @@ -49,46 +49,43 @@ public interface ActionDelegate { */ void setMessage(@NotNull String message); - /** @return true if need to include all changes except from new files, and false otherwise */ - boolean isAllFilesInclued(); - /** - * Set status of include changes to commit. - * - * @param isAllFiles - * true need to include all changes except from new, false include all changes + * Returns true if need to add all changes to index except from new files before commit, and false otherwise */ - void setAllFilesInclude(boolean isAllFiles); + boolean isAddAllExceptNew(); /** - * Returns true if the project explorer selection must be included in the commited files. - * - * @return true iff the selection mus tbe commited + * Set status of flag that represents add all changes to index except from new files before commit. + * + * @param addAllExceptNew + * true if need to add all changes to index except from new files before commit, + * false otherwise */ - boolean isIncludeSelection(); + void setAddAllExceptNew(boolean addAllExceptNew); - /** - * Sets the display of the include selection flag. - * - * @param includeSelection is selection included - */ - void setIncludeSelection(boolean includeSelection); + /** Returns true if the selection must be added to index before commit, and false otherwise. */ + boolean isAddSelectedFiles(); /** - * Tells the state of the field 'commit only selection'. - * - * @return true iff the field is checked + * Sets the status of flag that represents add selected files. + * + * @param addSelectedFiles + * true if need to add selected files before commit, false otherwise */ - boolean isOnlySelection(); + void setAddSelectedFiles(boolean addSelectedFiles); + + /** Returns true if need to commit all files in the project, and false otherwise. */ + boolean isCommitAllFiles(); /** - * Sets the state of the field 'commit only selection'. - * - * @return true to check the field + * Sets the status of flag that represents add selected files. + * + * @param commitAllFiles + * true if need to add selected files before commit, false otherwise */ - void setOnlySelection(boolean onlySelection); + void setCommitAllFiles(boolean commitAllFiles); - /** @return true if need to amend the last commit, and false otherwise */ + /** Returns true if need to amend the last commit, and false otherwise. */ boolean isAmend(); /** diff --git a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/commit/CommitViewImpl.java b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/commit/CommitViewImpl.java index c5345d05d0b..5404cd2737e 100644 --- a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/commit/CommitViewImpl.java +++ b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/commit/CommitViewImpl.java @@ -13,6 +13,7 @@ import org.eclipse.che.ide.ext.git.client.GitLocalizationConstant; import org.eclipse.che.ide.ext.git.client.GitResources; import org.eclipse.che.ide.ui.window.Window; + import com.google.gwt.core.client.GWT; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; @@ -49,7 +50,7 @@ interface CommitViewImplUiBinder extends UiBinder { @UiField CheckBox addAll; /** - * The 'include selection' in commit field. + * The 'add to index selected files' selection in commit field. */ @UiField CheckBox addSelection; @@ -57,7 +58,7 @@ interface CommitViewImplUiBinder extends UiBinder { * The 'commit only selection' field. */ @UiField - CheckBox onlySelection; + CheckBox commitAllSelection; /** * The amend commit flag. @@ -142,14 +143,14 @@ public void setMessage(@NotNull String message) { /** {@inheritDoc} */ @Override - public boolean isAllFilesInclued() { + public boolean isAddAllExceptNew() { return this.addAll.getValue(); } /** {@inheritDoc} */ @Override - public void setAllFilesInclude(boolean isAllFiles) { - this.addAll.setValue(isAllFiles); + public void setAddAllExceptNew(boolean isAddAllExceptNew) { + this.addAll.setValue(isAddAllExceptNew); } /** {@inheritDoc} */ @@ -165,23 +166,23 @@ public void setAmend(boolean isAmend) { } @Override - public boolean isIncludeSelection() { + public boolean isAddSelectedFiles() { return this.addSelection.getValue(); } @Override - public void setIncludeSelection(final boolean includeSelection) { + public void setAddSelectedFiles(final boolean includeSelection) { this.addSelection.setValue(includeSelection); } @Override - public boolean isOnlySelection() { - return this.onlySelection.getValue(); + public boolean isCommitAllFiles() { + return this.commitAllSelection.getValue(); } @Override - public void setOnlySelection(final boolean onlySelection) { - this.onlySelection.setValue(onlySelection); + public void setCommitAllFiles(final boolean onlySelection) { + this.commitAllSelection.setValue(onlySelection); } /** {@inheritDoc} */ @@ -228,7 +229,6 @@ public void onMessageChanged(KeyUpEvent event) { public void onAddAllValueChange(final ValueChangeEvent event) { if (event.getValue()) { this.addSelection.setValue(false); - this.onlySelection.setValue(false); } } @@ -236,16 +236,12 @@ public void onAddAllValueChange(final ValueChangeEvent event) { public void onAddSelectionValueChange(final ValueChangeEvent event) { if (event.getValue()) { this.addAll.setValue(false); - this.onlySelection.setValue(false); } } - @UiHandler("onlySelection") + @UiHandler("commitAllSelection") public void onOnlySelectionValueChange(final ValueChangeEvent event) { - if (event.getValue()) { - this.addAll.setValue(false); - this.addSelection.setValue(false); - } + this.commitAllSelection.setValue(event.getValue()); } @UiHandler("amend") diff --git a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/commit/CommitViewImpl.ui.xml b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/commit/CommitViewImpl.ui.xml index 08f119bebbe..67c33370623 100644 --- a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/commit/CommitViewImpl.ui.xml +++ b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/commit/CommitViewImpl.ui.xml @@ -41,13 +41,13 @@
- - 0); this.project = project; - - view.setMessage(constant.removeFromIndexAll()); + if (resources.length == 1) { + Resource resource = appContext.getResource(); + String selectedItemName = resource.getName(); + if (resource instanceof Container) { + view.setMessage(constant.removeFromIndexFolder(selectedItemName)); + } else { + view.setMessage(constant.removeFromIndexFile(selectedItemName)); + } + } else { + view.setMessage(constant.removeFromIndexAll()); + } view.setRemoved(false); view.showDialog(); } diff --git a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/reset/files/ResetFilesPresenter.java b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/reset/files/ResetFilesPresenter.java index 6e462c3ecd1..84c49b1345d 100644 --- a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/reset/files/ResetFilesPresenter.java +++ b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/reset/files/ResetFilesPresenter.java @@ -23,6 +23,7 @@ import org.eclipse.che.ide.api.git.GitServiceClient; import org.eclipse.che.ide.api.notification.NotificationManager; import org.eclipse.che.ide.api.resources.Project; +import org.eclipse.che.ide.api.resources.Resource; import org.eclipse.che.ide.dto.DtoFactory; import org.eclipse.che.ide.ext.git.client.GitLocalizationConstant; import org.eclipse.che.ide.ext.git.client.outputconsole.GitOutputConsole; @@ -116,6 +117,18 @@ public void apply(Status status) throws OperationException { return; } + //Mark selected items to reset from index + Resource[] resources = appContext.getResources(); + if (resources != null) { + for (Resource selectedItem : resources) { + String selectedItemPath = selectedItem.getLocation().removeFirstSegments(1).toString(); + for (IndexFile file : indexedFiles) + if (file.getPath().startsWith(selectedItemPath)) { + file.setIndexed(false); + } + } + } + view.setIndexedFiles(indexedFiles); view.showDialog(); } 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 106a363de82..7cda7bb18c8 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 @@ -36,7 +36,8 @@ messages.unableGetSshKey = Failed to get private ssh key. \ messages.warningTitle = Warning messages.index_empty=Index is empty messages.add_success=Git index updated -messages.nothingAddToIndex = Git index clear +messages.nothingAddToIndex = Selected item does not have any unstaged changes +messages.nothingAddToIndexMultiSelect = Selected items do not have any unstaged changes messages.add_failed=Failed to update git index messages.remove_files_success=Files removed from index messages.remove_files_failed=Failed to remove files from index @@ -107,11 +108,12 @@ view.import.gitImporterPage.keepDirectoryField = Directory: view.import.gitImporterPage.branchField = Enter the name of imported branch (master by default): #Add view.add_to_index.all_changes=Add all changes in repository to index? -view.add_to_index.multiple=Add to the following files and folders to the index? +view.add_to_index.multiselect=Add selected items to the index? view.add_to_index.folder=Add content of folder {0} to index? view.add_to_index.file=Add file {0} to index? view.add_to_index.update_field_title=Update (do not add new files to index) view.add_to_index.title=Add To Index... +view.add_to_index.command_name=Git add to index #Branch view.branch.create_new=Create new branch view.branch.confirm_rename.title=Confirm rename branch @@ -132,7 +134,7 @@ view.reset.mixed.type.description=(Change the ref and the index, the workdir is view.reset.hard.type.title=hard view.reset.hard.type.description=(Change the ref, the index and the workdir) #Remove -view.remove_from_index.all=Are you sure you want to remove the entire project from index? +view.remove_from_index.all=Are you sure you want to remove selected items from index? view.remove_from_index.only=Remove only from index (file will be untouched) view.remove_from_index.folder=Remove content of folder {0} from index? view.remove_from_index.file=Remove file {0} from index? @@ -144,7 +146,7 @@ view.commit.commit_user= by user {0} view.commit.title=Commit to repository view.commit.all_field_title=Add all changes except of new files view.commit.selection_field_title=Add selected files -view.commit.onlyselection_field_title=Commit only selected files +view.commit.all_project_field_title=Commit all files in the project view.commit.amend_field_title=Amend previous commit view.commit.grid.date=Date view.commit.grid.commiter=Committer @@ -232,8 +234,8 @@ control.branches.title=Branches... control.branches.prompt=Work With Branches... control.delete.title=Delete Repository... control.delete.prompt=Delete Git Repository... -control.commit.title=Commit... -control.commit.prompt=Commit... +control.commit.title=Commit selected... +control.commit.prompt=Commit selected... control.fetch.title=Fetch... control.fetch.prompt=Fetch Data from Remote Repository... control.init.title=Initialize Repository... diff --git a/plugins/plugin-git/che-plugin-git-ext-git/src/test/java/org/eclipse/che/ide/ext/git/client/add/AddToIndexPresenterTest.java b/plugins/plugin-git/che-plugin-git-ext-git/src/test/java/org/eclipse/che/ide/ext/git/client/add/AddToIndexPresenterTest.java index 4af003b4509..d87d1dbef65 100644 --- a/plugins/plugin-git/che-plugin-git-ext-git/src/test/java/org/eclipse/che/ide/ext/git/client/add/AddToIndexPresenterTest.java +++ b/plugins/plugin-git/che-plugin-git-ext-git/src/test/java/org/eclipse/che/ide/ext/git/client/add/AddToIndexPresenterTest.java @@ -10,20 +10,23 @@ *******************************************************************************/ package org.eclipse.che.ide.ext.git.client.add; -import org.eclipse.che.api.git.shared.Status; import org.eclipse.che.api.promises.client.Operation; +import org.eclipse.che.ide.api.machine.DevMachine; +import org.eclipse.che.ide.api.resources.Container; +import org.eclipse.che.ide.api.resources.File; +import org.eclipse.che.ide.api.resources.Project; import org.eclipse.che.ide.api.resources.Resource; import org.eclipse.che.ide.ext.git.client.BaseTest; +import org.eclipse.che.ide.ext.git.client.outputconsole.GitOutputConsole; import org.eclipse.che.ide.resource.Path; import org.junit.Test; -import org.mockito.Matchers; import org.mockito.Mock; -import java.util.List; - +import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.FLOAT_MODE; +import static org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyObject; +import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -34,14 +37,17 @@ * * @author Andrey Plotnikov * @author Vlad Zhukovskyi + * @author Igor Vinokur */ public class AddToIndexPresenterTest extends BaseTest { - public static final String MESSAGE = "message"; + private static final String MESSAGE = "message"; + private static final String FOLDER_NAME = "folder name"; + private static final String FILE_NAME = "file name"; @Mock - private AddToIndexView view; + private AddToIndexView view; @Mock - private Status statusResponse; + private GitOutputConsole console; private AddToIndexPresenter presenter; @@ -56,27 +62,90 @@ public void disarm() { processesPanelPresenter, service, notificationManager); + + when(appContext.getResources()).thenReturn(new Resource[]{}); + when(appContext.getDevMachine()).thenReturn(mock(DevMachine.class)); + when(appContext.getRootProject()).thenReturn(mock(Project.class)); + when(voidPromise.then(any(Operation.class))).thenReturn(voidPromise); + when(voidPromise.catchError(any(Operation.class))).thenReturn(voidPromise); + when(service.add(any(DevMachine.class), any(Path.class), anyBoolean(), any(Path[].class))).thenReturn(voidPromise); + when(gitOutputConsoleFactory.create(anyString())).thenReturn(console); } @Test - public void testShowDialogWhenRootFolderIsSelected() throws Exception { - when(service.getStatus(anyObject(), any(Path.class))).thenReturn(statusPromise); - when(statusPromise.then(any(Operation.class))).thenReturn(statusPromise); - when(statusPromise.catchError(any(Operation.class))).thenReturn(statusPromise); - when(appContext.getResources()).thenReturn(new Resource[]{mock(Resource.class)}); - when(constant.addToIndexAllChanges()).thenReturn(MESSAGE); + public void shouldSetFolderMessageToViewAndShowDialog() throws Exception { + Container folder = mock(Container.class); + when(folder.getName()).thenReturn(FOLDER_NAME); + when(appContext.getResource()).thenReturn(folder); + when(appContext.getResources()).thenReturn(new Resource[]{folder}); + when(constant.addToIndexFolder(FOLDER_NAME)).thenReturn(MESSAGE); + + presenter.showDialog(); + + verify(constant).addToIndexFolder(eq(FOLDER_NAME)); + verify(view).setMessage(eq(MESSAGE)); + verify(view).setUpdated(eq(false)); + verify(view).showDialog(); + } - presenter.showDialog(project); + @Test + public void shouldSetFileMessageToViewAndShowDialog() throws Exception { + File file = mock(File.class); + when(file.getName()).thenReturn(FILE_NAME); + when(appContext.getResource()).thenReturn(file); + when(appContext.getResources()).thenReturn(new Resource[]{file}); + when(constant.addToIndexFile(FILE_NAME)).thenReturn(MESSAGE); - verify(statusPromise).then(statusPromiseCaptor.capture()); - statusPromiseCaptor.getValue().apply(statusResponse); + presenter.showDialog(); - verify(constant).addToIndexAllChanges(); - verify(view).setMessage(eq(MESSAGE), Matchers.>eq(null)); - verify(view).setUpdated(anyBoolean()); + verify(constant).addToIndexFile(eq(FILE_NAME)); + verify(view).setMessage(eq(MESSAGE)); + verify(view).setUpdated(eq(false)); verify(view).showDialog(); } + @Test + public void shouldSetMultiSelectionMessageToViewAndShowDialog() throws Exception { + File file1 = mock(File.class); + File file2 = mock(File.class); + when(file1.getName()).thenReturn(FILE_NAME + "1"); + when(file2.getName()).thenReturn(FILE_NAME + "2"); + when(appContext.getResource()).thenReturn(file2); + when(appContext.getResources()).thenReturn(new Resource[]{file1, file2}); + when(constant.addToIndexMultiSelect()).thenReturn(MESSAGE); + + presenter.showDialog(); + + verify(constant).addToIndexMultiSelect(); + verify(view).setMessage(eq(MESSAGE)); + verify(view).setUpdated(eq(false)); + verify(view).showDialog(); + } + + @Test + public void shouldAddToIndexWhenAddButtonClicked() throws Exception { + when(constant.addSuccess()).thenReturn(MESSAGE); + + presenter.onAddClicked(); + verify(voidPromise).then(voidPromiseCaptor.capture()); + voidPromiseCaptor.getValue().apply(null); + + verify(console).print(eq(MESSAGE)); + verify(notificationManager).notify(MESSAGE); + } + + @Test + public void shouldPrintErrorWhenFailedAddToIndex() throws Exception { + when(constant.addFailed()).thenReturn(MESSAGE); + + presenter.onAddClicked(); + verify(voidPromise).catchError(promiseErrorCaptor.capture()); + promiseErrorCaptor.getValue().apply(null); + + verify(console).printError(eq(MESSAGE)); + verify(notificationManager).notify(eq(MESSAGE), eq(FAIL), eq(FLOAT_MODE)); + } + @Test public void testOnCancelClicked() throws Exception { presenter.onCancelClicked(); diff --git a/plugins/plugin-git/che-plugin-git-ext-git/src/test/java/org/eclipse/che/ide/ext/git/client/commit/CommitPresenterTest.java b/plugins/plugin-git/che-plugin-git-ext-git/src/test/java/org/eclipse/che/ide/ext/git/client/commit/CommitPresenterTest.java index 4828ddef0ec..6f38a5a022f 100644 --- a/plugins/plugin-git/che-plugin-git-ext-git/src/test/java/org/eclipse/che/ide/ext/git/client/commit/CommitPresenterTest.java +++ b/plugins/plugin-git/che-plugin-git-ext-git/src/test/java/org/eclipse/che/ide/ext/git/client/commit/CommitPresenterTest.java @@ -10,16 +10,28 @@ *******************************************************************************/ package org.eclipse.che.ide.ext.git.client.commit; +import org.eclipse.che.api.git.shared.GitUser; import org.eclipse.che.api.git.shared.Revision; +import org.eclipse.che.api.promises.client.Operation; +import org.eclipse.che.ide.api.machine.DevMachine; +import org.eclipse.che.ide.api.resources.Project; +import org.eclipse.che.ide.api.resources.Resource; import org.eclipse.che.ide.ext.git.client.BaseTest; import org.eclipse.che.ide.ext.git.client.DateTimeFormatter; -import org.eclipse.che.ide.rest.AsyncRequestCallback; +import org.eclipse.che.ide.resource.Path; import org.junit.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.Captor; import org.mockito.Mock; +import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.FLOAT_MODE; +import static org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyBoolean; +import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -30,18 +42,15 @@ * @author Vlad Zhukovskyi */ public class CommitPresenterTest extends BaseTest { - @Captor - private ArgumentCaptor> asyncRequestCallbackRevisionCaptor; - public static final boolean ALL_FILE_INCLUDES = true; - public static final boolean IS_OVERWRITTEN = true; - public static final String COMMIT_TEXT = "commit text"; - @Mock - private CommitView view; + private static final boolean ALL_FILE_INCLUDES = true; + private static final boolean IS_OVERWRITTEN = true; + private static final String COMMIT_TEXT = "commit text"; + @Mock - private Revision revision; + private CommitView view; @Mock - private DateTimeFormatter dateTimeFormatter; + private DateTimeFormatter dateTimeFormatter; private CommitPresenter presenter; @@ -49,24 +58,37 @@ public class CommitPresenterTest extends BaseTest { public void disarm() { super.disarm(); - presenter = new CommitPresenter(view, - service, - constant, - notificationManager, - dialogFactory, - appContext, - dateTimeFormatter, - gitOutputConsoleFactory, - processesPanelPresenter); + presenter = spy(new CommitPresenter(view, + service, + constant, + notificationManager, + dialogFactory, + appContext, + dateTimeFormatter, + gitOutputConsoleFactory, + processesPanelPresenter)); + + when(view.getMessage()).thenReturn(EMPTY_TEXT); + + when(appContext.getResources()).thenReturn(new Resource[]{}); + when(appContext.getDevMachine()).thenReturn(mock(DevMachine.class)); + when(appContext.getRootProject()).thenReturn(mock(Project.class)); + + when(voidPromise.then(any(Operation.class))).thenReturn(voidPromise); + when(voidPromise.catchError(any(Operation.class))).thenReturn(voidPromise); + when(revisionPromise.then(any(Operation.class))).thenReturn(revisionPromise); + when(revisionPromise.catchError(any(Operation.class))).thenReturn(revisionPromise); + when(service.add(any(DevMachine.class), any(Path.class), anyBoolean(), any(Path[].class))).thenReturn(voidPromise); + when(service.commit(any(DevMachine.class), any(Path.class), anyString(), anyBoolean(), any(Path[].class), anyBoolean())) + .thenReturn(revisionPromise); } @Test public void testShowDialog() throws Exception { - when(view.getMessage()).thenReturn(EMPTY_TEXT); presenter.showDialog(project); verify(view).setAmend(eq(!IS_OVERWRITTEN)); - verify(view).setAllFilesInclude(eq(!ALL_FILE_INCLUDES)); + verify(view).setAddAllExceptNew(eq(!ALL_FILE_INCLUDES)); verify(view).focusInMessageField(); verify(view).setEnableCommitButton(eq(DISABLE_BUTTON)); verify(view).getMessage(); @@ -79,7 +101,7 @@ public void testShowDialogWithExistingMessage() throws Exception { presenter.showDialog(project); verify(view).setAmend(eq(!IS_OVERWRITTEN)); - verify(view).setAllFilesInclude(eq(!ALL_FILE_INCLUDES)); + verify(view).setAddAllExceptNew(eq(!ALL_FILE_INCLUDES)); verify(view).focusInMessageField(); verify(view).setEnableCommitButton(eq(ENABLE_BUTTON)); verify(view).getMessage(); @@ -102,6 +124,64 @@ public void testOnValueChangedWhenCommitMessageEmpty() throws Exception { verify(view).setEnableCommitButton(eq(DISABLE_BUTTON)); } + @Test + public void shouldPrintSuccessMessageOnCommitSuccess() throws Exception { + Revision revision = mock(Revision.class); + GitUser gitUser = mock(GitUser.class); + when(gitUser.getName()).thenReturn("commiterName"); + when(revision.getId()).thenReturn("commitId"); + when(revision.getCommitter()).thenReturn(gitUser); + when(constant.commitMessage(eq("commitId"), anyString())).thenReturn("commitMessage"); + when(constant.commitUser(anyString())).thenReturn("commitUser"); + + presenter.showDialog(project); + presenter.doCommit(COMMIT_TEXT, true, true, true); + verify(revisionPromise).then(revisionCaptor.capture()); + revisionCaptor.getValue().apply(revision); + + verify(console).print("commitMessage commitUser"); + verify(notificationManager).notify("commitMessage commitUser"); + } + + @Test + public void shouldPrintFailMessageOnCommitFailed() throws Exception { + when(constant.commitFailed()).thenReturn("commitFailed"); + + presenter.showDialog(project); + presenter.doCommit(COMMIT_TEXT, true, true, true); + verify(revisionPromise).catchError(promiseErrorCaptor.capture()); + promiseErrorCaptor.getValue().apply(promiseError); + + verify(console).printError("error"); + verify(notificationManager).notify(eq("commitFailed"), eq("error"), eq(FAIL), eq(FLOAT_MODE)); + } + + @Test + public void shouldAddAndCommitIfAddSelectedIsSetToTrue() throws Exception { + when(view.isAddSelectedFiles()).thenReturn(true); + doNothing().when(presenter).doCommit(anyString(), anyBoolean(), anyBoolean(), anyBoolean()); + + presenter.showDialog(project); + presenter.onCommitClicked(); + verify(voidPromise).then(voidPromiseCaptor.capture()); + voidPromiseCaptor.getValue().apply(null); + + verify(service).add(any(DevMachine.class), any(Path.class), anyBoolean(), any(Path[].class)); + verify(presenter).doCommit(anyString(), anyBoolean(), anyBoolean(), anyBoolean()); + } + + @Test + public void shouldNotAddBeforeCommitIfAddSelectedIsSetToFalse() throws Exception { + when(view.isAddSelectedFiles()).thenReturn(false); + doNothing().when(presenter).doCommit(anyString(), anyBoolean(), anyBoolean(), anyBoolean()); + + presenter.showDialog(project); + presenter.onCommitClicked(); + + verify(service, never()).add(any(DevMachine.class), any(Path.class), anyBoolean(), any(Path[].class)); + verify(presenter).doCommit(anyString(), anyBoolean(), anyBoolean(), anyBoolean()); + } + @Test public void testOnValueChanged() throws Exception { when(view.getMessage()).thenReturn(COMMIT_TEXT); diff --git a/plugins/plugin-git/che-plugin-git-ext-git/src/test/java/org/eclipse/che/ide/ext/git/client/reset/files/ResetFilesPresenterTest.java b/plugins/plugin-git/che-plugin-git-ext-git/src/test/java/org/eclipse/che/ide/ext/git/client/reset/files/ResetFilesPresenterTest.java index ef343008875..4bcf80e868e 100644 --- a/plugins/plugin-git/che-plugin-git-ext-git/src/test/java/org/eclipse/che/ide/ext/git/client/reset/files/ResetFilesPresenterTest.java +++ b/plugins/plugin-git/che-plugin-git-ext-git/src/test/java/org/eclipse/che/ide/ext/git/client/reset/files/ResetFilesPresenterTest.java @@ -14,6 +14,7 @@ import org.eclipse.che.api.git.shared.ResetRequest; import org.eclipse.che.api.git.shared.Status; import org.eclipse.che.api.promises.client.Operation; +import org.eclipse.che.ide.api.resources.Resource; import org.eclipse.che.ide.ext.git.client.BaseTest; import org.eclipse.che.ide.api.dialogs.MessageDialog; import org.eclipse.che.ide.resource.Path; @@ -66,10 +67,10 @@ public void disarm() { when(indexFile.withIndexed(anyBoolean())).thenReturn(indexFile); when(indexFile.withPath(anyString())).thenReturn(indexFile); when(indexFile.getPath()).thenReturn("foo"); - when(service.getStatus(anyObject(), any(Path.class))).thenReturn(statusPromise); when(statusPromise.then(any(Operation.class))).thenReturn(statusPromise); when(statusPromise.catchError(any(Operation.class))).thenReturn(statusPromise); + when(appContext.getResources()).thenReturn(new Resource[]{}); } @Test diff --git a/wsagent/che-core-api-git/src/test/java/org/eclipse/che/git/impl/CommitTest.java b/wsagent/che-core-api-git/src/test/java/org/eclipse/che/git/impl/CommitTest.java index 2381a740a98..b21368f1d39 100644 --- a/wsagent/che-core-api-git/src/test/java/org/eclipse/che/git/impl/CommitTest.java +++ b/wsagent/che-core-api-git/src/test/java/org/eclipse/che/git/impl/CommitTest.java @@ -21,6 +21,7 @@ import org.eclipse.che.api.git.params.LogParams; import org.eclipse.che.api.git.shared.AddRequest; import org.eclipse.che.api.git.shared.Revision; +import org.eclipse.che.api.git.shared.StatusFormat; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -29,11 +30,14 @@ import java.io.IOException; import static java.nio.file.Files.write; +import static java.util.Arrays.asList; +import static java.util.Collections.singletonList; import static org.eclipse.che.git.impl.GitTestUtil.addFile; import static org.eclipse.che.git.impl.GitTestUtil.cleanupTestRepo; import static org.eclipse.che.git.impl.GitTestUtil.connectToGitRepositoryWithContent; import static org.eclipse.che.git.impl.GitTestUtil.connectToInitializedGitRepository; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; /** * @author Eugene Voevodin @@ -127,6 +131,22 @@ public void testChangeMessageOfLastCommit(GitConnectionFactory connectionFactory assertEquals(connection.log(LogParams.create()).getCommits().get(0).getMessage(), commitParams.getMessage()); } + @Test(dataProvider = "GitConnectionFactory", dataProviderClass = org.eclipse.che.git.impl.GitConnectionFactoryProvider.class) + public void testCommitSeparateFiles(GitConnectionFactory connectionFactory) throws GitException, IOException { + //given + GitConnection connection = connectToGitRepositoryWithContent(connectionFactory, repository); + addFile(connection, "File1.txt", CONTENT); + addFile(connection, "File2.txt", CONTENT); + connection.add(AddParams.create(asList("File1.txt", "File2.txt"))); + + //when + connection.commit(CommitParams.create("commit").withFiles(singletonList("File1.txt"))); + + //then + assertTrue(connection.status(StatusFormat.LONG).getAdded().contains("File2.txt")); + assertTrue(connection.status(StatusFormat.LONG).getAdded().size() == 1); + } + @Test(dataProvider = "GitConnectionFactory", dataProviderClass = org.eclipse.che.git.impl.GitConnectionFactoryProvider.class, expectedExceptions = GitException.class) public void testCommitWithNotStagedChanges(GitConnectionFactory connectionFactory) throws GitException, IOException { diff --git a/wsagent/che-core-git-impl-jgit/src/main/java/org/eclipse/che/git/impl/jgit/JGitConnection.java b/wsagent/che-core-git-impl-jgit/src/main/java/org/eclipse/che/git/impl/jgit/JGitConnection.java index c1b5f93e064..bb4dfbd244e 100644 --- a/wsagent/che-core-git-impl-jgit/src/main/java/org/eclipse/che/git/impl/jgit/JGitConnection.java +++ b/wsagent/che-core-git-impl-jgit/src/main/java/org/eclipse/che/git/impl/jgit/JGitConnection.java @@ -569,6 +569,10 @@ public Revision commit(CommitParams params) throws GitException { .setAll(params.isAll()) .setAmend(params.isAmend()); + if (!params.isAll()) { + params.getFiles().forEach(commitCommand::setOnly); + } + // Check if repository is configured with Gerrit Support String gerritSupportConfigValue = repository.getConfig().getString(ConfigConstants.CONFIG_GERRIT_SECTION, null, ConfigConstants.CONFIG_KEY_CREATECHANGEID);