Skip to content

Commit dac5b66

Browse files
authored
CHE-6024: Revert commit action (eclipse-che#6386)
* CHE-6024: Revert commit action
1 parent 16854d4 commit dac5b66

24 files changed

Lines changed: 935 additions & 12 deletions

File tree

ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/git/GitServiceClient.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.eclipse.che.api.git.shared.PushResponse;
2323
import org.eclipse.che.api.git.shared.Remote;
2424
import org.eclipse.che.api.git.shared.ResetRequest.ResetType;
25+
import org.eclipse.che.api.git.shared.RevertResult;
2526
import org.eclipse.che.api.git.shared.Revision;
2627
import org.eclipse.che.api.git.shared.ShowFileContentResponse;
2728
import org.eclipse.che.api.git.shared.Status;
@@ -366,4 +367,13 @@ Promise<LogResponse> log(
366367
* @return the promise with success status
367368
*/
368369
Promise<Void> deleteRepository(Path project);
370+
371+
/**
372+
* Reverts commit.
373+
*
374+
* @param project the project path
375+
* @param commit the hash of the commit to revert
376+
* @return result of the revert operation
377+
*/
378+
Promise<RevertResult> revert(Path project, String commit);
369379
}

ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/git/GitServiceClientImpl.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
import org.eclipse.che.api.git.shared.Remote;
4444
import org.eclipse.che.api.git.shared.RemoteAddRequest;
4545
import org.eclipse.che.api.git.shared.ResetRequest;
46+
import org.eclipse.che.api.git.shared.RevertRequest;
47+
import org.eclipse.che.api.git.shared.RevertResult;
4648
import org.eclipse.che.api.git.shared.Revision;
4749
import org.eclipse.che.api.git.shared.ShowFileContentResponse;
4850
import org.eclipse.che.api.git.shared.Status;
@@ -86,6 +88,7 @@ public class GitServiceClientImpl implements GitServiceClient {
8688
private static final String REMOVE = "/git/remove";
8789
private static final String RESET = "/git/reset";
8890
private static final String REPOSITORY = "/git/repository";
91+
private static final String REVERT = "/git/revert";
8992

9093
/** Loader to be displayed. */
9194
private final AsyncRequestLoader loader;
@@ -503,6 +506,16 @@ public Promise<Void> deleteRepository(Path project) {
503506
return asyncRequestFactory.createDeleteRequest(url).loader(loader).send();
504507
}
505508

509+
@Override
510+
public Promise<RevertResult> revert(Path project, String commit) {
511+
RevertRequest revertRequest = dtoFactory.createDto(RevertRequest.class).withCommit(commit);
512+
String url = getWsAgentBaseUrl() + REVERT + "?projectPath=" + project;
513+
return asyncRequestFactory
514+
.createPostRequest(url, revertRequest)
515+
.loader(loader)
516+
.send(dtoUnmarshallerFactory.newUnmarshaller(RevertResult.class));
517+
}
518+
506519
private String getWsAgentBaseUrl() {
507520
return appContext.getDevMachine().getWsAgentBaseUrl();
508521
}

plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/GitExtension.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.eclipse.che.ide.ext.git.client.action.RemoveFromIndexAction;
4040
import org.eclipse.che.ide.ext.git.client.action.ResetFilesAction;
4141
import org.eclipse.che.ide.ext.git.client.action.ResetToCommitAction;
42+
import org.eclipse.che.ide.ext.git.client.action.RevertCommitAction;
4243
import org.eclipse.che.ide.ext.git.client.action.ShowBranchesAction;
4344
import org.eclipse.che.ide.ext.git.client.action.ShowMergeAction;
4445
import org.eclipse.che.ide.ext.git.client.action.ShowRemoteAction;
@@ -92,6 +93,7 @@ public GitExtension(
9293
CompareWithRevisionAction compareWithRevisionAction,
9394
NextDiffAction nextDiffAction,
9495
PreviousDiffAction previousDiffAction,
96+
RevertCommitAction revertCommitAction,
9597
KeyBindingAgent keyBinding) {
9698

9799
resources.gitCSS().ensureInjected();
@@ -131,6 +133,8 @@ public GitExtension(
131133
commandGroup.add(compareGroup);
132134
actionManager.registerAction("gitResetToCommit", resetToCommitAction);
133135
commandGroup.add(resetToCommitAction);
136+
actionManager.registerAction("gitRevertCommit", revertCommitAction);
137+
commandGroup.add(revertCommitAction);
134138
actionManager.registerAction("gitRemoveFromIndexCommit", removeFromIndexAction);
135139
commandGroup.add(removeFromIndexAction);
136140
actionManager.registerAction(GIT_SHOW_COMMIT_WINDOW, commitAction);
@@ -174,6 +178,7 @@ public GitExtension(
174178
gitContextMenuGroup.add(addToIndexAction);
175179
gitContextMenuGroup.add(removeFromIndexAction);
176180
gitContextMenuGroup.add(resetFilesAction);
181+
gitContextMenuGroup.add(revertCommitAction);
177182
gitContextMenuGroup.add(commitAction);
178183
gitContextMenuGroup.add(historyAction);
179184
gitContextMenuGroup.addSeparator();

plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/GitLocalizationConstant.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ public interface GitLocalizationConstant extends Messages {
7272
@Key("button.compare")
7373
String buttonCompare();
7474

75+
@Key("button.revert")
76+
String buttonRevert();
77+
7578
@Key("button.save_changes")
7679
String buttonSaveChanges();
7780

@@ -425,13 +428,50 @@ public interface GitLocalizationConstant extends Messages {
425428
@Key("view.reset.hard.type.description")
426429
String resetHardTypeDescription();
427430

431+
// Revert
432+
@Key("view.revert.commit.title")
433+
String revertCommitViewTitle();
434+
435+
@Key("view.revert.no_commit.type.title")
436+
String revertNoCommitTypeTitle();
437+
438+
@Key("view.revert.no_commit.type.description")
439+
String revertNoCommitTypeDescription();
440+
441+
@Key("view.revert.revision.table.id.title")
442+
String viewRevertRevisionTableIdTitle();
443+
444+
@Key("view.revert.revision.table.date.title")
445+
String viewRevertRevisionTableDateTitle();
446+
447+
@Key("view.revert.revision.table.author.title")
448+
String viewRevertRevisionTableAuthorTitle();
449+
450+
@Key("view.revert.revision.table.comment.title")
451+
String viewRevertRevisionTableCommentTitle();
452+
453+
@Key("reverted.commits")
454+
String revertedCommits(String commits);
455+
456+
@Key("reverted.new.head")
457+
String revertedNewHead(String newHead);
458+
459+
@Key("reverted.conflicts")
460+
String revertedConflicts();
461+
428462
// Remove
429463
@Key("view.remove_from_index.all")
430464
String removeFromIndexAll();
431465

432466
@Key("view.remove_from_index.only")
433467
String removeFromIndexOnly();
434468

469+
@Key("control.revert.commit.title")
470+
String revertCommitControlTitle();
471+
472+
@Key("control.revert.commit.prompt")
473+
String revertCommitControlPrompt();
474+
435475
@Key("view.remove_from_index.folder")
436476
String removeFromIndexFolder(String folder);
437477

plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/GitResources.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,7 @@ interface GitCSS extends CssResource {
101101

102102
@Source("controls/git-output-icon.svg")
103103
SVGResource gitOutput();
104+
105+
@Source("controls/revert.svg")
106+
SVGResource revert();
104107
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (c) 2012-2017 Red Hat, Inc.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Red Hat, Inc. - initial API and implementation
10+
*/
11+
package org.eclipse.che.ide.ext.git.client.action;
12+
13+
import static com.google.common.base.Preconditions.checkState;
14+
15+
import com.google.inject.Inject;
16+
import org.eclipse.che.ide.FontAwesome;
17+
import org.eclipse.che.ide.api.action.ActionEvent;
18+
import org.eclipse.che.ide.api.app.AppContext;
19+
import org.eclipse.che.ide.api.resources.Project;
20+
import org.eclipse.che.ide.ext.git.client.GitLocalizationConstant;
21+
import org.eclipse.che.ide.ext.git.client.revert.RevertCommitPresenter;
22+
23+
/** @author Anatolii Bazko */
24+
public class RevertCommitAction extends GitAction {
25+
private final RevertCommitPresenter presenter;
26+
27+
@Inject
28+
public RevertCommitAction(
29+
RevertCommitPresenter presenter, AppContext appContext, GitLocalizationConstant constant) {
30+
super(
31+
constant.revertCommitControlTitle(),
32+
constant.revertCommitControlPrompt(),
33+
FontAwesome.BAN,
34+
appContext);
35+
this.presenter = presenter;
36+
}
37+
38+
@Override
39+
public void actionPerformed(ActionEvent e) {
40+
final Project project = appContext.getRootProject();
41+
42+
checkState(project != null, "Null project occurred");
43+
44+
presenter.show(project);
45+
}
46+
}

plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/inject/GitGinModule.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
import org.eclipse.che.ide.ext.git.client.reset.commit.ResetToCommitViewImpl;
6161
import org.eclipse.che.ide.ext.git.client.reset.files.ResetFilesView;
6262
import org.eclipse.che.ide.ext.git.client.reset.files.ResetFilesViewImpl;
63+
import org.eclipse.che.ide.ext.git.client.revert.RevertCommitView;
64+
import org.eclipse.che.ide.ext.git.client.revert.RevertCommitViewImpl;
6365

6466
/** @author Andrey Plotnikov */
6567
@ExtensionGinModule
@@ -80,6 +82,7 @@ protected void configure() {
8082
bind(RemoveFromIndexView.class).to(RemoveFromIndexViewImpl.class).in(Singleton.class);
8183
bind(RevisionListView.class).to(RevisionListViewImpl.class).in(Singleton.class);
8284
bind(CommitView.class).to(CommitViewImpl.class).in(Singleton.class);
85+
bind(RevertCommitView.class).to(RevertCommitViewImpl.class).in(Singleton.class);
8386
bind(ChangesListView.class).to(ChangesListViewImpl.class).in(Singleton.class);
8487
bind(BranchView.class).to(BranchViewImpl.class).in(Singleton.class);
8588
bind(BranchListView.class).to(BranchListViewImpl.class).in(Singleton.class);

0 commit comments

Comments
 (0)