Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHE-1866: Fix wrong viewing of git compare #2106

Merged
merged 1 commit into from
Aug 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
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.resources.Resource;
import org.eclipse.che.ide.ext.git.client.GitLocalizationConstant;
import org.eclipse.che.ide.ext.git.client.compare.branchList.BranchListPresenter;

Expand Down Expand Up @@ -43,9 +44,10 @@ public CompareWithBranchAction(BranchListPresenter presenter,
@Override
public void actionPerformed(ActionEvent e) {
final Project project = appContext.getRootProject();
final Resource resource = appContext.getResource();

checkState(project != null, "Null project occurred");

presenter.showBranches(project);
presenter.showBranches(project, resource);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@
import org.eclipse.che.ide.api.notification.NotificationManager;
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.GitLocalizationConstant;
import org.eclipse.che.ide.ext.git.client.compare.ComparePresenter;
import org.eclipse.che.ide.ext.git.client.compare.FileStatus.Status;
import org.eclipse.che.ide.ext.git.client.compare.changedList.ChangedListPresenter;
import org.eclipse.che.ide.api.dialogs.DialogFactory;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import static com.google.common.base.Preconditions.checkState;
import static java.util.Collections.singletonList;
import static org.eclipse.che.api.git.shared.DiffRequest.DiffType.NAME_STATUS;
import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.NOT_EMERGE_MODE;
import static org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL;
Expand Down Expand Up @@ -78,10 +78,20 @@ public CompareWithLatestAction(ComparePresenter presenter,
public void actionPerformed(ActionEvent e) {

final Project project = appContext.getRootProject();
final Resource resource = appContext.getResource();

checkState(project != null, "Null project occurred");
checkState(project.getLocation().isPrefixOf(resource.getLocation()), "Given selected item is not descendant of given project");

final String selectedItemPath = resource.getLocation()
.removeFirstSegments(project.getLocation().segmentCount())
.removeTrailingSeparator()
.toString();

service.diff(appContext.getDevMachine(), project.getLocation(), Collections.<String>emptyList(), NAME_STATUS, false, 0, REVISION, false)
service.diff(appContext.getDevMachine(),
project.getLocation(),
selectedItemPath.isEmpty() ? null : singletonList(selectedItemPath),
NAME_STATUS, false, 0, REVISION, false)
.then(new Operation<String>() {
@Override
public void apply(String diff) throws OperationException {
Expand Down Expand Up @@ -109,11 +119,11 @@ public void apply(Optional<File> file) throws OperationException {
}
}
})
.catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
notificationManager.notify(locale.diffFailed(), FAIL, NOT_EMERGE_MODE);
}
});
.catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
notificationManager.notify(locale.diffFailed(), FAIL, NOT_EMERGE_MODE);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.eclipse.che.ide.api.notification.NotificationManager;
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.GitLocalizationConstant;
import org.eclipse.che.ide.ext.git.client.compare.ComparePresenter;
import org.eclipse.che.ide.ext.git.client.compare.FileStatus.Status;
Expand All @@ -33,11 +34,12 @@
import org.eclipse.che.ide.api.dialogs.DialogFactory;

import javax.validation.constraints.NotNull;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.google.common.base.Preconditions.checkState;
import static java.util.Collections.singletonList;
import static org.eclipse.che.api.git.shared.BranchListRequest.LIST_ALL;
import static org.eclipse.che.api.git.shared.DiffRequest.DiffType.NAME_STATUS;
import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.NOT_EMERGE_MODE;
Expand All @@ -64,8 +66,9 @@ public class BranchListPresenter implements BranchListView.ActionDelegate {
private final AppContext appContext;
private final NotificationManager notificationManager;

private Branch selectedBranch;
private Project project;
private Branch selectedBranch;
private Project project;
private Resource selectedItem;

@Inject
public BranchListPresenter(BranchListView view,
Expand Down Expand Up @@ -93,8 +96,11 @@ public BranchListPresenter(BranchListView view,
}

/** Open dialog and shows branches to compare. */
public void showBranches(Project project) {
public void showBranches(Project project, Resource selectedItem) {
checkState(project.getLocation().isPrefixOf(selectedItem.getLocation()), "Given selected item is not descendant of given project");

this.project = project;
this.selectedItem = selectedItem;

getBranches();
}
Expand All @@ -108,9 +114,15 @@ public void onCloseClicked() {
/** {@inheritDoc} */
@Override
public void onCompareClicked() {

final String selectedItemPath = selectedItem.getLocation()
.removeFirstSegments(project.getLocation().segmentCount())
.removeTrailingSeparator()
.toString();

service.diff(appContext.getDevMachine(),
project.getLocation(),
Collections.<String>emptyList(),
selectedItemPath.isEmpty() ? null : singletonList(selectedItemPath),
NAME_STATUS,
false,
0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class RevisionListPresenter implements RevisionListView.ActionDelegate {

private Revision selectedRevision;
private Project project;
private Path selectedPath;
private Path selectedFilePath;

@Inject
public RevisionListPresenter(RevisionListView view,
Expand All @@ -80,13 +80,14 @@ public RevisionListPresenter(RevisionListView view,
}

/** Open dialog and shows revisions to compare. */
public void showRevisions(Project project, File file) {
public void showRevisions(Project project, File selectedFile) {
this.project = project;

checkState(project.getLocation().isPrefixOf(file.getLocation()), "Given file is not descendant of given project");

selectedPath = file.getLocation().removeFirstSegments(project.getLocation().segmentCount());
checkState(project.getLocation().isPrefixOf(selectedFile.getLocation()), "Given selected file is not descendant of given project");

selectedFilePath = selectedFile.getLocation()
.removeFirstSegments(project.getLocation().segmentCount())
.removeTrailingSeparator();
getRevisions();
}

Expand Down Expand Up @@ -126,13 +127,14 @@ public void onRevisionDoubleClicked() {

/** Get list of revisions. */
private void getRevisions() {
service.log(appContext.getDevMachine(), project.getLocation(), new Path[]{selectedPath}, false).then(new Operation<LogResponse>() {
@Override
public void apply(LogResponse log) throws OperationException {
view.setRevisions(log.getCommits());
view.showDialog();
}
}).catchError(new Operation<PromiseError>() {
service.log(appContext.getDevMachine(), project.getLocation(), new Path[]{selectedFilePath}, false)
.then(new Operation<LogResponse>() {
@Override
public void apply(LogResponse log) throws OperationException {
view.setRevisions(log.getCommits());
view.showDialog();
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
if (getErrorCode(error.getCause()) == ErrorCodes.INIT_COMMIT_WAS_NOT_PERFORMED) {
Expand All @@ -149,36 +151,36 @@ public void apply(PromiseError error) throws OperationException {
private void compare() {
service.diff(appContext.getDevMachine(),
project.getLocation(),
singletonList(selectedPath.toString()),
singletonList(selectedFilePath.toString()),
NAME_STATUS,
false,
0,
selectedRevision.getId(),
false)
.then(new Operation<String>() {
@Override
public void apply(final String diff) throws OperationException {
if (diff.isEmpty()) {
dialogFactory.createMessageDialog(locale.compareMessageIdenticalContentTitle(),
locale.compareMessageIdenticalContentText(), null).show();
} else {
project.getFile(diff.substring(2)).then(new Operation<Optional<File>>() {
@Override
public void apply(Optional<File> file) throws OperationException {
if (file.isPresent()) {
comparePresenter.show(file.get(), defineStatus(diff.substring(0, 1)), selectedRevision.getId());
}
}
});

}
}
})
.catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
notificationManager.notify(locale.diffFailed(), FAIL, NOT_EMERGE_MODE);
}
});
.then(new Operation<String>() {
@Override
public void apply(final String diff) throws OperationException {
if (diff.isEmpty()) {
dialogFactory.createMessageDialog(locale.compareMessageIdenticalContentTitle(),
locale.compareMessageIdenticalContentText(), null).show();
} else {
project.getFile(diff.substring(2)).then(new Operation<Optional<File>>() {
@Override
public void apply(Optional<File> file) throws OperationException {
if (file.isPresent()) {
comparePresenter.show(file.get(), defineStatus(diff.substring(0, 1)), selectedRevision.getId());
}
}
});

}
}
})
.catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
notificationManager.notify(locale.diffFailed(), FAIL, NOT_EMERGE_MODE);
}
});
}
}