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 aa1a24145af..1746b09eb8d 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 @@ -25,7 +25,6 @@ import org.eclipse.che.api.git.shared.Revision; import org.eclipse.che.api.git.shared.ShowFileContentResponse; import org.eclipse.che.api.git.shared.Status; -import org.eclipse.che.api.git.shared.StatusFormat; import org.eclipse.che.api.promises.client.Promise; import org.eclipse.che.commons.annotation.Nullable; import org.eclipse.che.ide.resource.Path; @@ -345,17 +344,20 @@ Promise log( * * * @param project project (root of GIT repository) - * @param format to show in short format or not */ - Promise statusText(Path project, StatusFormat format); + Promise statusText(Path project); /** - * Returns the current working tree status. + * Returns the current status. * * @param project the project. + * @param filter list of paths to filter the status. Status result will include only files witch + * paths are contained in the filter list, or are children of the folder paths that are + * mentioned in the filter list. Unfiltered status of working tree will be returned, if the + * filter list is empty * @return the promise which either resolves working tree status or rejects with an error */ - Promise getStatus(Path project); + Promise getStatus(Path project, List filter); /** * Remove the git repository from given path. 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 a045423d279..f8f951eccf2 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 @@ -13,7 +13,6 @@ import static java.util.Arrays.stream; import static java.util.stream.Collectors.toList; import static org.eclipse.che.api.git.shared.AddRequest.DEFAULT_PATTERN; -import static org.eclipse.che.api.git.shared.StatusFormat.PORCELAIN; import static org.eclipse.che.ide.MimeType.APPLICATION_JSON; import static org.eclipse.che.ide.MimeType.TEXT_PLAIN; import static org.eclipse.che.ide.rest.HTTPHeader.ACCEPT; @@ -45,7 +44,6 @@ import org.eclipse.che.api.git.shared.Revision; import org.eclipse.che.api.git.shared.ShowFileContentResponse; import org.eclipse.che.api.git.shared.Status; -import org.eclipse.che.api.git.shared.StatusFormat; import org.eclipse.che.api.promises.client.Promise; import org.eclipse.che.ide.MimeType; import org.eclipse.che.ide.api.app.AppContext; @@ -131,8 +129,8 @@ public Promise clone(Path project, String remoteUri, String remoteName) { } @Override - public Promise statusText(Path project, StatusFormat format) { - String params = "?projectPath=" + project + "&format=" + format; + public Promise statusText(Path project) { + String params = "?projectPath=" + project; String url = getWsAgentBaseUrl() + STATUS + params; return asyncRequestFactory @@ -249,8 +247,15 @@ public Promise> branchList(Path project, BranchListMode listMode) { } @Override - public Promise getStatus(Path project) { - String params = "?projectPath=" + project + "&format=" + PORCELAIN; + public Promise getStatus(Path project, List filter) { + StringBuilder params = new StringBuilder("?projectPath=" + project); + if (filter != null) { + for (String path : filter) { + if (!path.isEmpty()) { + params.append("&filter=").append(path); + } + } + } String url = getWsAgentBaseUrl() + STATUS + params; return asyncRequestFactory .createGetRequest(url) 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 865785d8f01..fdfc98d71a1 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 @@ -16,7 +16,9 @@ import com.google.inject.Inject; import com.google.inject.Singleton; +import java.util.Arrays; import java.util.List; +import java.util.stream.Collectors; import org.eclipse.che.ide.FontAwesome; import org.eclipse.che.ide.api.action.ActionEvent; import org.eclipse.che.ide.api.app.AppContext; @@ -72,8 +74,12 @@ public void actionPerformed(ActionEvent e) { final GitOutputConsole console = gitOutputConsoleFactory.create(constant.addToIndexCommandName()); consolesPanelPresenter.addCommandOutput(appContext.getDevMachine().getId(), console); + List selected = + Arrays.stream(appContext.getResources()) + .map(path -> path.getLocation().removeFirstSegments(1).toString()) + .collect(Collectors.toList()); service - .getStatus(appContext.getRootProject().getLocation()) + .getStatus(appContext.getRootProject().getLocation(), selected) .then( status -> { if (containsInSelected(status.getUntracked())) { 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 5e979765825..16ab5c25c1d 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 @@ -12,6 +12,7 @@ import static com.google.common.collect.Iterables.getFirst; import static java.util.Arrays.stream; +import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; import static java.util.stream.Collectors.joining; import static org.eclipse.che.api.git.shared.BranchListMode.LIST_REMOTE; @@ -127,7 +128,7 @@ public void showDialog(Project project) { if (getErrorCode(error.getCause()) == ErrorCodes.INIT_COMMIT_WAS_NOT_PERFORMED) { service - .getStatus(project.getLocation()) + .getStatus(project.getLocation(), emptyList()) .then( status -> { view.setEnableAmendCheckBox(false); 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 22d93a6cf50..165a3b6866b 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 @@ -16,6 +16,9 @@ import com.google.inject.Inject; import com.google.inject.Singleton; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; import org.eclipse.che.api.git.shared.IndexFile; import org.eclipse.che.ide.api.app.AppContext; import org.eclipse.che.ide.api.dialogs.DialogFactory; @@ -85,8 +88,13 @@ public ResetFilesPresenter( public void showDialog(Project project) { this.project = project; + List selected = + Arrays.stream(appContext.getResources()) + .map(path -> path.getLocation().removeFirstSegments(1).toString()) + .collect(Collectors.toList()); + service - .getStatus(project.getLocation()) + .getStatus(project.getLocation(), selected) .then( status -> { if (status.isClean()) { diff --git a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/status/StatusCommandPresenter.java b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/status/StatusCommandPresenter.java index ffa4ee5d208..62160b53d9b 100644 --- a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/status/StatusCommandPresenter.java +++ b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/status/StatusCommandPresenter.java @@ -10,7 +10,6 @@ */ package org.eclipse.che.ide.ext.git.client.status; -import static org.eclipse.che.api.git.shared.StatusFormat.LONG; import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.FLOAT_MODE; import static org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL; @@ -65,7 +64,7 @@ public StatusCommandPresenter( /** Show status. */ public void showStatus(Project project) { service - .statusText(project.getLocation(), LONG) + .statusText(project.getLocation()) .then( status -> { printGitStatus(status); 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 ae37d6d2745..ee10e37cceb 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,6 +10,7 @@ */ package org.eclipse.che.ide.ext.git.client.commit; +import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.FLOAT_MODE; import static org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL; @@ -122,7 +123,7 @@ public void disarm() { .thenReturn(pushPromise); when(service.log(any(Path.class), eq(null), anyInt(), anyInt(), anyBoolean())) .thenReturn(logPromise); - when(service.getStatus(any(Path.class))).thenReturn(statusPromise); + when(service.getStatus(any(Path.class), eq(emptyList()))).thenReturn(statusPromise); } @Test 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 e1f160c8186..9c4b39f7038 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 @@ -10,6 +10,7 @@ */ package org.eclipse.che.ide.ext.git.client.reset.files; +import static java.util.Collections.emptyList; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyBoolean; import static org.mockito.Matchers.anyObject; @@ -66,7 +67,7 @@ public void disarm() { when(indexFile.withIndexed(anyBoolean())).thenReturn(indexFile); when(indexFile.withPath(anyString())).thenReturn(indexFile); when(indexFile.getPath()).thenReturn("foo"); - when(service.getStatus(any(Path.class))).thenReturn(statusPromise); + when(service.getStatus(any(Path.class), eq(emptyList()))).thenReturn(statusPromise); when(statusPromise.then(any(Operation.class))).thenReturn(statusPromise); when(statusPromise.catchError(any(Operation.class))).thenReturn(statusPromise); when(appContext.getResources()).thenReturn(new Resource[] {}); diff --git a/plugins/plugin-git/che-plugin-git-ext-git/src/test/java/org/eclipse/che/ide/ext/git/client/status/StatusCommandPresenterTest.java b/plugins/plugin-git/che-plugin-git-ext-git/src/test/java/org/eclipse/che/ide/ext/git/client/status/StatusCommandPresenterTest.java index 857871f941e..43f1a9e587f 100644 --- a/plugins/plugin-git/che-plugin-git-ext-git/src/test/java/org/eclipse/che/ide/ext/git/client/status/StatusCommandPresenterTest.java +++ b/plugins/plugin-git/che-plugin-git-ext-git/src/test/java/org/eclipse/che/ide/ext/git/client/status/StatusCommandPresenterTest.java @@ -17,7 +17,6 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import org.eclipse.che.api.git.shared.StatusFormat; import org.eclipse.che.api.promises.client.Operation; import org.eclipse.che.ide.api.notification.StatusNotification; import org.eclipse.che.ide.ext.git.client.BaseTest; @@ -54,7 +53,7 @@ public void disarm() { constant, notificationManager); - when(service.statusText(any(Path.class), any(StatusFormat.class))).thenReturn(stringPromise); + when(service.statusText(any(Path.class))).thenReturn(stringPromise); when(stringPromise.then(any(Operation.class))).thenReturn(stringPromise); when(stringPromise.catchError(any(Operation.class))).thenReturn(stringPromise); } diff --git a/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/src/main/java/org/eclipse/che/plugin/pullrequest/client/vcs/GitVcsService.java b/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/src/main/java/org/eclipse/che/plugin/pullrequest/client/vcs/GitVcsService.java index abe65eea3b0..729ccf2132c 100644 --- a/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/src/main/java/org/eclipse/che/plugin/pullrequest/client/vcs/GitVcsService.java +++ b/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/src/main/java/org/eclipse/che/plugin/pullrequest/client/vcs/GitVcsService.java @@ -10,6 +10,8 @@ */ package org.eclipse.che.plugin.pullrequest.client.vcs; +import static java.util.Collections.emptyList; + import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.inject.Inject; import com.google.inject.Singleton; @@ -137,7 +139,7 @@ public void deleteRemote( @Override public Promise getBranchName(ProjectConfig project) { return service - .getStatus(Path.valueOf(project.getPath())) + .getStatus(Path.valueOf(project.getPath()), emptyList()) .then((Function) status -> status.getBranchName()); } @@ -145,7 +147,7 @@ public Promise getBranchName(ProjectConfig project) { public void hasUncommittedChanges( @NotNull final ProjectConfig project, @NotNull final AsyncCallback callback) { service - .getStatus(Path.valueOf(project.getPath())) + .getStatus(Path.valueOf(project.getPath()), emptyList()) .then( status -> { callback.onSuccess(!status.isClean()); diff --git a/wsagent/che-core-api-git-shared/src/main/java/org/eclipse/che/api/git/shared/Status.java b/wsagent/che-core-api-git-shared/src/main/java/org/eclipse/che/api/git/shared/Status.java index e1aa83ba234..6a2e4f62a56 100644 --- a/wsagent/che-core-api-git-shared/src/main/java/org/eclipse/che/api/git/shared/Status.java +++ b/wsagent/che-core-api-git-shared/src/main/java/org/eclipse/che/api/git/shared/Status.java @@ -20,10 +20,6 @@ public interface Status { void setClean(boolean isClean); - StatusFormat getFormat(); - - void setFormat(StatusFormat format); - String getBranchName(); void setBranchName(String branchName); diff --git a/wsagent/che-core-api-git-shared/src/main/java/org/eclipse/che/api/git/shared/StatusFormat.java b/wsagent/che-core-api-git-shared/src/main/java/org/eclipse/che/api/git/shared/StatusFormat.java deleted file mode 100644 index cd375210da1..00000000000 --- a/wsagent/che-core-api-git-shared/src/main/java/org/eclipse/che/api/git/shared/StatusFormat.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2012-2017 Red Hat, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Red Hat, Inc. - initial API and implementation - */ -package org.eclipse.che.api.git.shared; - -/** Format for the status output. */ -public enum StatusFormat { - - /** Short format, to show the user (has colors) but harder to understand than long format. */ - SHORT, - /** Long format, to show the user. */ - LONG, - /** Porcelain format, made to be fed to scripts and guaranteed to not change. */ - PORCELAIN -} diff --git a/wsagent/che-core-api-git/src/main/java/org/eclipse/che/api/git/GitChangesDetector.java b/wsagent/che-core-api-git/src/main/java/org/eclipse/che/api/git/GitChangesDetector.java index 5bec1af3c30..9e0aeb1a4c8 100644 --- a/wsagent/che-core-api-git/src/main/java/org/eclipse/che/api/git/GitChangesDetector.java +++ b/wsagent/che-core-api-git/src/main/java/org/eclipse/che/api/git/GitChangesDetector.java @@ -12,6 +12,7 @@ import static com.google.common.collect.Sets.newConcurrentHashSet; import static java.nio.file.Files.isDirectory; +import static java.util.Collections.singletonList; import static org.eclipse.che.api.project.shared.dto.event.GitChangeEventDto.Type.ADDED; import static org.eclipse.che.api.project.shared.dto.event.GitChangeEventDto.Type.MODIFIED; import static org.eclipse.che.api.project.shared.dto.event.GitChangeEventDto.Type.UNTRACKED; @@ -29,7 +30,6 @@ import org.eclipse.che.api.core.jsonrpc.commons.RequestTransmitter; import org.eclipse.che.api.git.exception.GitException; import org.eclipse.che.api.git.shared.Status; -import org.eclipse.che.api.git.shared.StatusFormat; import org.eclipse.che.api.project.shared.dto.event.GitChangeEventDto; import org.eclipse.che.api.vfs.watcher.FileWatcherManager; import org.slf4j.Logger; @@ -111,7 +111,7 @@ private Consumer transmitConsumer(String path) { String project = normalizedPath.split("/")[0]; String itemPath = normalizedPath.substring(normalizedPath.indexOf("/") + 1); try { - Status status = gitConnectionFactory.getConnection(project).status(StatusFormat.SHORT); + Status status = gitConnectionFactory.getConnection(project).status(singletonList(itemPath)); GitChangeEventDto.Type type; if (status.getAdded().contains(itemPath)) { type = ADDED; diff --git a/wsagent/che-core-api-git/src/main/java/org/eclipse/che/api/git/GitConnection.java b/wsagent/che-core-api-git/src/main/java/org/eclipse/che/api/git/GitConnection.java index 4a82c6bf081..75673d22076 100644 --- a/wsagent/che-core-api-git/src/main/java/org/eclipse/che/api/git/GitConnection.java +++ b/wsagent/che-core-api-git/src/main/java/org/eclipse/che/api/git/GitConnection.java @@ -45,7 +45,6 @@ import org.eclipse.che.api.git.shared.Revision; import org.eclipse.che.api.git.shared.ShowFileContentResponse; import org.eclipse.che.api.git.shared.Status; -import org.eclipse.che.api.git.shared.StatusFormat; import org.eclipse.che.api.git.shared.Tag; /** @@ -330,13 +329,16 @@ void cloneWithSparseCheckout(String directory, String remoteUrl) void rm(RmParams params) throws GitException; /** - * Get status of working tree. + * Get status. * - * @param format the format of the ouput + * @param filter list of paths to filter the status. Status result will include only files witch + * paths are contained in the filter list, or are children of the folder paths that are + * mentioned in the filter list. Unfiltered status of working tree will be returned, if the + * filter list is empty * @return status. * @throws GitException if any error occurs */ - Status status(StatusFormat format) throws GitException; + Status status(List filter) throws GitException; /** * Create new tag. diff --git a/wsagent/che-core-api-git/src/main/java/org/eclipse/che/api/git/GitIndexChangedDetector.java b/wsagent/che-core-api-git/src/main/java/org/eclipse/che/api/git/GitIndexChangedDetector.java index 1d8789f6236..8d47ae42601 100644 --- a/wsagent/che-core-api-git/src/main/java/org/eclipse/che/api/git/GitIndexChangedDetector.java +++ b/wsagent/che-core-api-git/src/main/java/org/eclipse/che/api/git/GitIndexChangedDetector.java @@ -12,6 +12,7 @@ import static com.google.common.collect.Sets.newConcurrentHashSet; import static java.nio.file.Files.isDirectory; +import static java.util.Collections.emptyList; import static org.eclipse.che.api.vfs.watcher.FileWatcherManager.EMPTY_CONSUMER; import static org.eclipse.che.dto.server.DtoFactory.newDto; import static org.slf4j.LoggerFactory.getLogger; @@ -26,7 +27,6 @@ import org.eclipse.che.api.core.jsonrpc.commons.RequestTransmitter; import org.eclipse.che.api.git.exception.GitException; import org.eclipse.che.api.git.shared.Status; -import org.eclipse.che.api.git.shared.StatusFormat; import org.eclipse.che.api.vfs.watcher.FileWatcherManager; import org.slf4j.Logger; @@ -108,7 +108,7 @@ private Consumer transmitConsumer(String path) { return id -> { String project = (path.startsWith("/") ? path.substring(1) : path).split("/")[0]; try { - Status status = gitConnectionFactory.getConnection(project).status(StatusFormat.SHORT); + Status status = gitConnectionFactory.getConnection(project).status(emptyList()); Status statusDto = newDto(Status.class); statusDto.setAdded(status.getAdded()); statusDto.setUntracked(status.getUntracked()); diff --git a/wsagent/che-core-api-git/src/main/java/org/eclipse/che/api/git/GitService.java b/wsagent/che-core-api-git/src/main/java/org/eclipse/che/api/git/GitService.java index 0cf8830482c..47ba629849f 100644 --- a/wsagent/che-core-api-git/src/main/java/org/eclipse/che/api/git/GitService.java +++ b/wsagent/che-core-api-git/src/main/java/org/eclipse/che/api/git/GitService.java @@ -76,7 +76,6 @@ import org.eclipse.che.api.git.shared.Revision; import org.eclipse.che.api.git.shared.ShowFileContentResponse; import org.eclipse.che.api.git.shared.Status; -import org.eclipse.che.api.git.shared.StatusFormat; import org.eclipse.che.api.git.shared.Tag; import org.eclipse.che.api.git.shared.TagCreateRequest; import org.eclipse.che.api.project.server.FolderEntry; @@ -439,9 +438,9 @@ public void reset(ResetRequest request) throws ApiException { @GET @Path("status") @Produces({MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN}) - public Status status(@QueryParam("format") StatusFormat format) throws ApiException { + public Status status(@QueryParam("filter") List filter) throws ApiException { try (GitConnection gitConnection = getGitConnection()) { - return gitConnection.status(format); + return gitConnection.status(filter); } } diff --git a/wsagent/che-core-api-git/src/main/java/org/eclipse/che/api/git/GitStatusProvider.java b/wsagent/che-core-api-git/src/main/java/org/eclipse/che/api/git/GitStatusProvider.java index 97cc263274e..724662e64e9 100644 --- a/wsagent/che-core-api-git/src/main/java/org/eclipse/che/api/git/GitStatusProvider.java +++ b/wsagent/che-core-api-git/src/main/java/org/eclipse/che/api/git/GitStatusProvider.java @@ -10,11 +10,15 @@ */ package org.eclipse.che.api.git; +import static java.util.Collections.singletonList; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; import javax.inject.Inject; import org.eclipse.che.api.core.ServerException; import org.eclipse.che.api.git.exception.GitException; import org.eclipse.che.api.git.shared.Status; -import org.eclipse.che.api.git.shared.StatusFormat; import org.eclipse.che.api.project.server.VcsStatusProvider; /** @@ -42,7 +46,7 @@ public VcsStatus getStatus(String path) throws ServerException { Status status = gitConnectionFactory .getConnection(normalizedPath.split("/")[0]) - .status(StatusFormat.SHORT); + .status(singletonList(normalizedPath.substring(normalizedPath.indexOf("/") + 1))); String itemPath = normalizedPath.substring(normalizedPath.indexOf("/") + 1); if (status.getUntracked().contains(itemPath)) { return VcsStatus.UNTRACKED; @@ -58,4 +62,29 @@ public VcsStatus getStatus(String path) throws ServerException { throw new ServerException(e.getMessage()); } } + + @Override + public Map getStatus(String project, List paths) + throws ServerException { + Map statusMap = new HashMap<>(); + try { + Status status = gitConnectionFactory.getConnection(project).status(paths); + paths.forEach( + path -> { + if (status.getUntracked().contains(path)) { + statusMap.put("/" + project + "/" + path, VcsStatus.UNTRACKED); + } else if (status.getAdded().contains(path)) { + statusMap.put("/" + project + "/" + path, VcsStatus.ADDED); + } else if (status.getModified().contains(path) || status.getChanged().contains(path)) { + statusMap.put("/" + project + "/" + path, VcsStatus.MODIFIED); + } else { + statusMap.put("/" + project + "/" + path, VcsStatus.NOT_MODIFIED); + } + }); + + } catch (GitException e) { + throw new ServerException(e.getMessage()); + } + return statusMap; + } } diff --git a/wsagent/che-core-api-git/src/test/java/org/eclipse/che/git/impl/AddTest.java b/wsagent/che-core-api-git/src/test/java/org/eclipse/che/git/impl/AddTest.java index bb3ddf14671..f7a4b6495e7 100644 --- a/wsagent/che-core-api-git/src/test/java/org/eclipse/che/git/impl/AddTest.java +++ b/wsagent/che-core-api-git/src/test/java/org/eclipse/che/git/impl/AddTest.java @@ -10,6 +10,7 @@ */ package org.eclipse.che.git.impl; +import static java.util.Collections.emptyList; import static org.eclipse.che.git.impl.GitTestUtil.CONTENT; import static org.eclipse.che.git.impl.GitTestUtil.addFile; import static org.eclipse.che.git.impl.GitTestUtil.cleanupTestRepo; @@ -30,7 +31,6 @@ import org.eclipse.che.api.git.params.CommitParams; import org.eclipse.che.api.git.params.LsFilesParams; import org.eclipse.che.api.git.shared.AddRequest; -import org.eclipse.che.api.git.shared.StatusFormat; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -124,7 +124,7 @@ public void testAddDeletedFile(GitConnectionFactory connectionFactory) // then // the deleted file is added to index, so it becomes removed for git - List stagedDeletedFiles = connection.status(StatusFormat.SHORT).getRemoved(); + List stagedDeletedFiles = connection.status(emptyList()).getRemoved(); assertEquals(stagedDeletedFiles.size(), 1); assertEquals(stagedDeletedFiles.get(0), "CHANGELOG.txt"); } 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 4d55f3e48f7..61644031b9a 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 @@ -12,6 +12,7 @@ import static java.nio.file.Files.write; import static java.util.Arrays.asList; +import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; import static org.eclipse.che.git.impl.GitTestUtil.addFile; import static org.eclipse.che.git.impl.GitTestUtil.cleanupTestRepo; @@ -32,7 +33,6 @@ 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; @@ -191,8 +191,8 @@ public void testCommitSeparateFiles(GitConnectionFactory connectionFactory) 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); + assertTrue(connection.status(emptyList()).getAdded().contains("File2.txt")); + assertTrue(connection.status(emptyList()).getAdded().size() == 1); } @Test( diff --git a/wsagent/che-core-api-git/src/test/java/org/eclipse/che/git/impl/RemoveTest.java b/wsagent/che-core-api-git/src/test/java/org/eclipse/che/git/impl/RemoveTest.java index 4563572d94b..c90e8886536 100644 --- a/wsagent/che-core-api-git/src/test/java/org/eclipse/che/git/impl/RemoveTest.java +++ b/wsagent/che-core-api-git/src/test/java/org/eclipse/che/git/impl/RemoveTest.java @@ -10,6 +10,7 @@ */ package org.eclipse.che.git.impl; +import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; import static org.eclipse.che.git.impl.GitTestUtil.cleanupTestRepo; import static org.eclipse.che.git.impl.GitTestUtil.connectToGitRepositoryWithContent; @@ -24,7 +25,6 @@ import org.eclipse.che.api.git.GitConnectionFactory; import org.eclipse.che.api.git.exception.GitException; import org.eclipse.che.api.git.params.RmParams; -import org.eclipse.che.api.git.shared.StatusFormat; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -56,8 +56,8 @@ public void testNotCachedRemove(GitConnectionFactory connectionFactory) connection.rm(RmParams.create(singletonList("README.txt")).withCached(false)); //then assertFalse(new File(connection.getWorkingDir(), "README.txt").exists()); - assertEquals(connection.status(StatusFormat.SHORT).getRemoved().get(0), "README.txt"); - assertTrue(connection.status(StatusFormat.SHORT).getUntracked().isEmpty()); + assertEquals(connection.status(emptyList()).getRemoved().get(0), "README.txt"); + assertTrue(connection.status(emptyList()).getUntracked().isEmpty()); } @Test( @@ -72,7 +72,7 @@ public void testCachedRemove(GitConnectionFactory connectionFactory) connection.rm(RmParams.create(singletonList("README.txt")).withCached(true)); //then assertTrue(new File(connection.getWorkingDir(), "README.txt").exists()); - assertEquals(connection.status(StatusFormat.SHORT).getRemoved().get(0), "README.txt"); - assertEquals(connection.status(StatusFormat.SHORT).getUntracked().get(0), "README.txt"); + assertEquals(connection.status(emptyList()).getRemoved().get(0), "README.txt"); + assertEquals(connection.status(emptyList()).getUntracked().get(0), "README.txt"); } } diff --git a/wsagent/che-core-api-git/src/test/java/org/eclipse/che/git/impl/ResetTest.java b/wsagent/che-core-api-git/src/test/java/org/eclipse/che/git/impl/ResetTest.java index 35d85168296..bb5f2552a3b 100644 --- a/wsagent/che-core-api-git/src/test/java/org/eclipse/che/git/impl/ResetTest.java +++ b/wsagent/che-core-api-git/src/test/java/org/eclipse/che/git/impl/ResetTest.java @@ -10,6 +10,7 @@ */ package org.eclipse.che.git.impl; +import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; import static org.eclipse.che.dto.server.DtoFactory.newDto; import static org.eclipse.che.git.impl.GitTestUtil.CONTENT; @@ -32,7 +33,6 @@ import org.eclipse.che.api.git.params.LogParams; import org.eclipse.che.api.git.params.ResetParams; import org.eclipse.che.api.git.shared.ResetRequest; -import org.eclipse.che.api.git.shared.StatusFormat; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -72,7 +72,7 @@ public void testResetHard(GitConnectionFactory connectionFactory) throws Excepti //then assertEquals(connection.log(LogParams.create()).getCommits().get(0).getMessage(), initMessage); assertFalse(aaa.exists()); - assertTrue(connection.status(StatusFormat.SHORT).isClean()); + assertTrue(connection.status(emptyList()).isClean()); assertEquals( CONTENT, Files.toString(new File(connection.getWorkingDir(), "README.txt"), Charsets.UTF_8)); @@ -98,8 +98,8 @@ public void testResetSoft(GitConnectionFactory connectionFactory) throws Excepti //then assertEquals(connection.log(LogParams.create()).getCommits().get(0).getMessage(), initMessage); assertTrue(aaa.exists()); - assertEquals(connection.status(StatusFormat.SHORT).getAdded().get(0), "aaa"); - assertEquals(connection.status(StatusFormat.SHORT).getChanged().get(0), "README.txt"); + assertEquals(connection.status(emptyList()).getAdded().get(0), "aaa"); + assertEquals(connection.status(emptyList()).getChanged().get(0), "README.txt"); assertEquals( Files.toString(new File(connection.getWorkingDir(), "README.txt"), Charsets.UTF_8), "MODIFIED\n"); @@ -126,8 +126,8 @@ public void testResetMixed(GitConnectionFactory connectionFactory) throws Except //then assertEquals(connection.log(LogParams.create()).getCommits().get(0).getMessage(), initMessage); assertTrue(aaa.exists()); - assertEquals(connection.status(StatusFormat.SHORT).getUntracked().get(0), "aaa"); - assertEquals(connection.status(StatusFormat.SHORT).getModified().get(0), "README.txt"); + assertEquals(connection.status(emptyList()).getUntracked().get(0), "aaa"); + assertEquals(connection.status(emptyList()).getModified().get(0), "README.txt"); assertEquals( Files.toString(new File(connection.getWorkingDir(), "README.txt"), Charsets.UTF_8), "MODIFIED\n"); diff --git a/wsagent/che-core-api-git/src/test/java/org/eclipse/che/git/impl/StatusTest.java b/wsagent/che-core-api-git/src/test/java/org/eclipse/che/git/impl/StatusTest.java index b58ae0407ae..72f3cce4494 100644 --- a/wsagent/che-core-api-git/src/test/java/org/eclipse/che/git/impl/StatusTest.java +++ b/wsagent/che-core-api-git/src/test/java/org/eclipse/che/git/impl/StatusTest.java @@ -10,6 +10,8 @@ */ package org.eclipse.che.git.impl; +import static java.util.Collections.emptyList; +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.connectToInitializedGitRepository; @@ -54,7 +56,7 @@ public void testEmptyStatus(GitConnectionFactory connectionFactory) throws Excep //given GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository); //when - final Status status = connection.status(StatusFormat.SHORT); + final Status status = connection.status(emptyList()); //then assertTrue(status.getAdded().isEmpty()); assertTrue(status.getChanged().isEmpty()); @@ -75,7 +77,7 @@ public void testUntracked(GitConnectionFactory connectionFactory) throws Excepti addFile(connection, "a", "a content"); addFile(connection, "b", "b content"); //when - final Status status = connection.status(StatusFormat.SHORT); + final Status status = connection.status(emptyList()); //then assertEquals(status.getUntracked(), ImmutableList.of("a", "b")); assertTrue(status.getAdded().isEmpty()); @@ -95,7 +97,7 @@ public void testUntrackedFolder(GitConnectionFactory connectionFactory) throws E GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository); addFile(connection.getWorkingDir().toPath().resolve("new_directory"), "a", "content of a"); //when - final Status status = connection.status(StatusFormat.SHORT); + final Status status = connection.status(emptyList()); //then assertEquals(status.getUntrackedFolders(), ImmutableList.of("new_directory")); assertTrue(status.getAdded().isEmpty()); @@ -118,7 +120,7 @@ public void testAdded(GitConnectionFactory connectionFactory) throws Exception { //add "a" and "b" files connection.add(AddParams.create(ImmutableList.of("a", "b"))); //when - final Status status = connection.status(StatusFormat.SHORT); + final Status status = connection.status(emptyList()); //then assertEquals(status.getAdded(), ImmutableList.of("a", "b")); assertEquals(status.getUntracked(), ImmutableList.of("c")); @@ -143,7 +145,7 @@ public void testModified(GitConnectionFactory connectionFactory) throws Exceptio //modify "a" addFile(connection, "a", "new content of a"); //when - final Status status = connection.status(StatusFormat.SHORT); + final Status status = connection.status(emptyList()); //then assertEquals(status.getModified(), ImmutableList.of("a")); assertTrue(status.getUntracked().isEmpty()); @@ -174,7 +176,7 @@ public void testChanged(GitConnectionFactory connectionFactory) throws Exception //change "a" addFile(connection, "a", "changed content of a"); //when - final Status status = connection.status(StatusFormat.SHORT); + final Status status = connection.status(emptyList()); //then assertEquals(status.getChanged(), ImmutableList.of("a")); assertTrue(status.getAdded().isEmpty()); @@ -211,7 +213,7 @@ public void testConflicting(GitConnectionFactory connectionFactory) throws Excep //merge with "new_branch" to get conflict connection.merge("new_branch"); //when - final Status status = connection.status(StatusFormat.SHORT); + final Status status = connection.status(emptyList()); //then assertEquals(status.getConflicting(), ImmutableList.of("a")); assertTrue(status.getModified().isEmpty()); @@ -235,7 +237,7 @@ public void testMissing(GitConnectionFactory connectionFactory) throws Exception //delete "a" deleteFile(connection, "a"); //when - final Status status = connection.status(StatusFormat.SHORT); + final Status status = connection.status(emptyList()); //then assertEquals(status.getMissing(), ImmutableList.of("a")); assertEquals(status.getAdded(), ImmutableList.of("a")); @@ -262,7 +264,7 @@ public void testRemovedFromFilesSystem(GitConnectionFactory connectionFactory) t //delete "a" deleteFile(connection, "a"); //when - final Status status = connection.status(StatusFormat.SHORT); + final Status status = connection.status(emptyList()); //then assertTrue(status.getRemoved().isEmpty()); assertTrue(status.getAdded().isEmpty()); @@ -289,7 +291,7 @@ public void testRemovedFromIndex(GitConnectionFactory connectionFactory) throws //remove "a" from index connection.rm(RmParams.create(ImmutableList.of("a"))); //when - final Status status = connection.status(StatusFormat.SHORT); + final Status status = connection.status(emptyList()); //then assertEquals(status.getRemoved(), ImmutableList.of("a")); assertTrue(status.getAdded().isEmpty()); @@ -299,4 +301,28 @@ public void testRemovedFromIndex(GitConnectionFactory connectionFactory) throws assertTrue(status.getUntracked().isEmpty()); assertTrue(status.getUntrackedFolders().isEmpty()); } + + @Test( + dataProvider = "GitConnectionFactory", + dataProviderClass = org.eclipse.che.git.impl.GitConnectionFactoryProvider.class + ) + public void testStatusWithFilter(GitConnectionFactory connectionFactory) throws Exception { + // given + GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository); + addFile(connection, "a", "a content"); + addFile(connection, "b", "b content"); + // add "a" and "b" + connection.add(AddParams.create(ImmutableList.of("a", "b"))); + // when + final Status status = connection.status(singletonList("a")); + // then + assertTrue(status.getAdded().size() == 1); + assertEquals(status.getAdded().get(0), "a"); + assertTrue(status.getRemoved().isEmpty()); + assertTrue(status.getChanged().isEmpty()); + assertTrue(status.getConflicting().isEmpty()); + assertTrue(status.getMissing().isEmpty()); + assertTrue(status.getUntracked().isEmpty()); + assertTrue(status.getUntrackedFolders().isEmpty()); + } } diff --git a/wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/project/server/ProjectService.java b/wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/project/server/ProjectService.java index ed47ddc2b49..d2c71872062 100644 --- a/wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/project/server/ProjectService.java +++ b/wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/project/server/ProjectService.java @@ -889,13 +889,13 @@ public List getChildren( final ArrayList result = new ArrayList<>(children.size()); for (VirtualFileEntry child : children) { if (child.isFile()) { - result.add(injectFileLinks(vcsStatusInjector.injectVcsStatus(asDto((FileEntry) child)))); + result.add(injectFileLinks(asDto((FileEntry) child))); } else { result.add(injectFolderLinks(asDto((FolderEntry) child))); } } - return result; + return vcsStatusInjector.injectVcsStatus(result); } @GET @@ -1145,14 +1145,11 @@ private List getTree(FolderEntry folder, int depth, boolean include .withNode(injectFolderLinks(asDto((FolderEntry) child))) .withChildren(getTree((FolderEntry) child, depth - 1, includeFiles))); } else { - nodes.add( - newDto(TreeElement.class) - .withNode( - injectFileLinks(vcsStatusInjector.injectVcsStatus(asDto((FileEntry) child))))); + nodes.add(newDto(TreeElement.class).withNode(injectFileLinks(asDto((FileEntry) child)))); } } - return nodes; + return vcsStatusInjector.injectVcsStatusTreeElements(nodes); } /* --------------------------------------------------------------------------- */ diff --git a/wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/project/server/ProjectServiceVcsStatusInjector.java b/wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/project/server/ProjectServiceVcsStatusInjector.java index d8c79f512b3..ec44aa95c45 100644 --- a/wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/project/server/ProjectServiceVcsStatusInjector.java +++ b/wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/project/server/ProjectServiceVcsStatusInjector.java @@ -15,11 +15,13 @@ import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.stream.Collectors; import javax.inject.Inject; import javax.inject.Singleton; import org.eclipse.che.api.core.NotFoundException; import org.eclipse.che.api.core.ServerException; import org.eclipse.che.api.project.shared.dto.ItemReference; +import org.eclipse.che.api.project.shared.dto.TreeElement; /** * Injects VCS status to attributes of {@link ItemReference} dto. @@ -45,22 +47,9 @@ public ProjectServiceVcsStatusInjector( * * @param itemReference file to update */ - public ItemReference injectVcsStatus(ItemReference itemReference) + ItemReference injectVcsStatus(ItemReference itemReference) throws ServerException, NotFoundException { - List vcsAttributes = - projectManager - .getProject(itemReference.getProject()) - .getAttributes() - .get("vcs.provider.name"); - Optional optional = - vcsStatusProviders - .stream() - .filter( - vcsStatusProvider -> - vcsStatusProvider - .getVcsName() - .equals(vcsAttributes != null ? vcsAttributes.get(0) : null)) - .findAny(); + Optional optional = getVcsStatusProvider(itemReference.getProject()); if (optional.isPresent()) { Map attributes = new HashMap<>(itemReference.getAttributes()); attributes.put("vcs.status", optional.get().getStatus(itemReference.getPath()).toString()); @@ -68,4 +57,113 @@ public ItemReference injectVcsStatus(ItemReference itemReference) } return itemReference; } + + /** + * Find related VCS provider and set VCS status of {@link ItemReference} file to it's attributes + * to each item of the given list, if VCS provider is present. + * + * @param itemReferences list of {@link ItemReference} files to update + */ + List injectVcsStatus(List itemReferences) + throws ServerException, NotFoundException { + Optional itemReferenceOptional = + itemReferences + .stream() + .filter(itemReference -> "file".equals(itemReference.getType())) + .findAny(); + if (itemReferenceOptional.isPresent()) { + String project = normalizeProjectPath(itemReferenceOptional.get().getProject()); + Optional vcsStatusProviderOptional = getVcsStatusProvider(project); + if (vcsStatusProviderOptional.isPresent()) { + List itemReferenceFiles = + itemReferences + .stream() + .filter(itemReference -> "file".equals(itemReference.getType())) + .map(itemReference -> normalizeFilePath(itemReference.getPath())) + .collect(Collectors.toList()); + Map status = + vcsStatusProviderOptional.get().getStatus(project, itemReferenceFiles); + + itemReferences + .stream() + .filter(itemReference -> "file".equals(itemReference.getType())) + .forEach( + itemReference -> { + Map attributes = new HashMap<>(itemReference.getAttributes()); + attributes.put("vcs.status", status.get(itemReference.getPath()).toString()); + itemReference.setAttributes(attributes); + }); + } + } + return itemReferences; + } + + /** + * Find related VCS provider and set VCS status of {@link TreeElement} file to it's attributes to + * each item of the given list, if VCS provider is present. + * + * @param treeElements list of {@link TreeElement} files to update + */ + List injectVcsStatusTreeElements(List treeElements) + throws ServerException, NotFoundException { + Optional treeElementOptional = + treeElements + .stream() + .filter(treeElement -> "file".equals(treeElement.getNode().getType())) + .findAny(); + if (treeElementOptional.isPresent()) { + String project = normalizeProjectPath(treeElementOptional.get().getNode().getProject()); + Optional vcsStatusProviderOptional = getVcsStatusProvider(project); + if (vcsStatusProviderOptional.isPresent()) { + List treeElementFiles = + treeElements + .stream() + .filter(treeElement -> "file".equals(treeElement.getNode().getType())) + .map(treeElement -> normalizeFilePath(treeElement.getNode().getPath())) + .collect(Collectors.toList()); + Map status = + vcsStatusProviderOptional.get().getStatus(project, treeElementFiles); + + treeElements + .stream() + .filter(itemReference -> "file".equals(itemReference.getNode().getType())) + .forEach( + itemReference -> { + Map attributes = + new HashMap<>(itemReference.getNode().getAttributes()); + attributes.put( + "vcs.status", status.get(itemReference.getNode().getPath()).toString()); + itemReference.getNode().setAttributes(attributes); + }); + } + } + + return treeElements; + } + + private String normalizeFilePath(String filePath) { + String normalizedPath = filePath.startsWith("/") ? filePath.substring(1) : filePath; + return normalizedPath.substring(normalizedPath.indexOf("/") + 1); + } + + private String normalizeProjectPath(String projectPath) { + if (projectPath.startsWith("/")) { + projectPath = projectPath.substring(1); + } + return projectPath; + } + + private Optional getVcsStatusProvider(String projectPath) + throws ServerException, NotFoundException { + List vcsAttributes = + projectManager.getProject(projectPath).getAttributes().get("vcs.provider.name"); + return vcsStatusProviders + .stream() + .filter( + vcsStatusProvider -> + vcsStatusProvider + .getVcsName() + .equals(vcsAttributes != null ? vcsAttributes.get(0) : null)) + .findAny(); + } } diff --git a/wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/project/server/VcsStatusProvider.java b/wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/project/server/VcsStatusProvider.java index 8cd6f9b92a3..2a7af9f12fb 100644 --- a/wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/project/server/VcsStatusProvider.java +++ b/wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/project/server/VcsStatusProvider.java @@ -10,6 +10,8 @@ */ package org.eclipse.che.api.project.server; +import java.util.List; +import java.util.Map; import org.eclipse.che.api.core.ServerException; /** @@ -29,6 +31,15 @@ public interface VcsStatusProvider { */ VcsStatus getStatus(String path) throws ServerException; + /** + * Get vcs status map of the given list of files. + * + * @param project project path + * @param paths list of file paths (without project item) + * @return map with full file path as a key and it's status as a value + */ + Map getStatus(String project, List paths) throws ServerException; + enum VcsStatus { ADDED, MODIFIED, 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 67437f604bd..3a000d5ee02 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 @@ -109,7 +109,6 @@ import org.eclipse.che.api.git.shared.Revision; import org.eclipse.che.api.git.shared.ShowFileContentResponse; import org.eclipse.che.api.git.shared.Status; -import org.eclipse.che.api.git.shared.StatusFormat; import org.eclipse.che.api.git.shared.Tag; import org.eclipse.che.commons.annotation.Nullable; import org.eclipse.che.commons.proxy.ProxyAuthenticator; @@ -132,6 +131,7 @@ import org.eclipse.jgit.api.ResetCommand; import org.eclipse.jgit.api.ResetCommand.ResetType; import org.eclipse.jgit.api.RmCommand; +import org.eclipse.jgit.api.StatusCommand; import org.eclipse.jgit.api.TagCommand; import org.eclipse.jgit.api.TransportCommand; import org.eclipse.jgit.api.errors.CheckoutConflictException; @@ -636,8 +636,9 @@ public Revision commit(CommitParams params) throws GitException { throw new GitException("Message wasn't set"); } - Status status = status(StatusFormat.SHORT); - List specified = params.getFiles(); + List files = params.getFiles(); + Status status = status(files); + List specified = files; List staged = new ArrayList<>(); staged.addAll(status.getAdded()); @@ -1686,12 +1687,16 @@ public void rm(RmParams params) throws GitException { } @Override - public Status status(StatusFormat format) throws GitException { + public Status status(List filter) throws GitException { if (!RepositoryCache.FileKey.isGitRepository(getRepository().getDirectory(), FS.DETECTED)) { throw new GitException("Not a git repository"); } String branchName = getCurrentBranch(); - return new JGitStatusImpl(branchName, getGit().status(), format); + StatusCommand statusCommand = getGit().status(); + if (filter != null) { + filter.forEach(statusCommand::addPath); + } + return new JGitStatusImpl(branchName, statusCommand); } @Override diff --git a/wsagent/che-core-git-impl-jgit/src/main/java/org/eclipse/che/git/impl/jgit/JGitStatusImpl.java b/wsagent/che-core-git-impl-jgit/src/main/java/org/eclipse/che/git/impl/jgit/JGitStatusImpl.java index 9b0bf72b630..b25b817d0ba 100644 --- a/wsagent/che-core-git-impl-jgit/src/main/java/org/eclipse/che/git/impl/jgit/JGitStatusImpl.java +++ b/wsagent/che-core-git-impl-jgit/src/main/java/org/eclipse/che/git/impl/jgit/JGitStatusImpl.java @@ -20,7 +20,6 @@ import org.eclipse.che.api.git.InfoPage; import org.eclipse.che.api.git.exception.GitException; import org.eclipse.che.api.git.shared.Status; -import org.eclipse.che.api.git.shared.StatusFormat; import org.eclipse.jgit.api.StatusCommand; import org.eclipse.jgit.api.errors.GitAPIException; @@ -32,7 +31,6 @@ public class JGitStatusImpl implements Status, InfoPage { private String branchName; - private StatusFormat format; private boolean clean; private List added; private List changed; @@ -47,13 +45,10 @@ public class JGitStatusImpl implements Status, InfoPage { /** * @param branchName current repository branch name * @param statusCommand Jgit status command - * @param format the output format for the status * @throws GitException when any error occurs */ - public JGitStatusImpl(String branchName, StatusCommand statusCommand, StatusFormat format) - throws GitException { + public JGitStatusImpl(String branchName, StatusCommand statusCommand) throws GitException { this.branchName = branchName; - this.format = format; org.eclipse.jgit.api.Status gitStatus; try { @@ -123,16 +118,6 @@ public void setClean(boolean clean) { this.clean = clean; } - @Override - public StatusFormat getFormat() { - return this.format; - } - - @Override - public void setFormat(final StatusFormat format) { - this.format = format; - } - @Override public String getBranchName() { return branchName;