Skip to content

Commit

Permalink
Add compare with parent action (closes #1283)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkondratek committed Feb 13, 2023
1 parent b656bb1 commit 5112285
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## v3.6.0
- Improved the repository selection combobox so that modules are now searchable.
- Added a field to provide/edit a custom annotation in the Slide In dialog.
- Added Compare With Parent action to the context menu.

## v3.5.1
- Improve stability of traverse and slide-out/slide-in actions.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.virtuslab.gitmachete.frontend.actions.base;

import static com.virtuslab.gitmachete.frontend.resourcebundles.GitMacheteBundle.fmt;
import static com.virtuslab.gitmachete.frontend.resourcebundles.GitMacheteBundle.getNonHtmlString;

import java.util.Collections;

import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import git4idea.branch.GitBrancher;
import lombok.val;
import org.checkerframework.checker.guieffect.qual.UIEffect;

public abstract class BaseCompareWithParentAction extends BaseGitMacheteRepositoryReadyAction implements IBranchNameProvider {

@Override
@UIEffect
protected void onUpdate(AnActionEvent anActionEvent) {
super.onUpdate(anActionEvent);

val presentation = anActionEvent.getPresentation();
if (!presentation.isEnabled()) {
return;
}

val branchName = getNameOfBranchUnderAction(anActionEvent);
val gitRepository = getSelectedGitRepository(anActionEvent);
val managedBranch = getManagedBranchByName(anActionEvent, branchName);

if (gitRepository == null || managedBranch == null) {
return;
}

if (managedBranch.isRoot()) {
presentation.setEnabled(false);
presentation.setDescription(
fmt(getNonHtmlString("action.GitMachete.BaseCompareWithParentAction.description.disabled.branch-is-root"),
managedBranch.getName()));
return;
}

val parent = managedBranch.asNonRoot().getParent();

String description = fmt(getNonHtmlString("action.GitMachete.BaseCompareWithParentAction.description.precise"),
parent.getName(),
managedBranch.getName());
presentation.setDescription(description);
}

@Override
@UIEffect
public void actionPerformed(AnActionEvent anActionEvent) {
FileDocumentManager.getInstance().saveAllDocuments();

val project = getProject(anActionEvent);
val branchName = getNameOfBranchUnderAction(anActionEvent);
val gitRepository = getSelectedGitRepository(anActionEvent);
val managedBranch = getManagedBranchByName(anActionEvent, branchName);

if (gitRepository == null || managedBranch == null || managedBranch.isRoot()) {
return;
}

val parent = managedBranch.asNonRoot().getParent();
GitBrancher.getInstance(project).compare(parent.getName(), Collections.singletonList(gitRepository));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.virtuslab.gitmachete.frontend.actions.contextmenu;

import com.intellij.openapi.actionSystem.AnActionEvent;
import kr.pe.kwonnam.slf4jlambda.LambdaLogger;
import lombok.CustomLog;
import org.checkerframework.checker.nullness.qual.Nullable;

import com.virtuslab.gitmachete.frontend.actions.base.BaseCompareWithParentAction;
import com.virtuslab.gitmachete.frontend.actions.expectedkeys.IExpectsKeySelectedBranchName;

@CustomLog
public class CompareSelectedWithParentAction extends BaseCompareWithParentAction implements IExpectsKeySelectedBranchName {
@Override
public LambdaLogger log() {
return LOG;
}

@Override
public @Nullable String getNameOfBranchUnderAction(AnActionEvent anActionEvent) {
return getSelectedBranchName(anActionEvent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ action.GitMachete.MergeCurrentBranchFastForwardOnlyBackgroundable.operation-name

# Base actions

action.GitMachete.BaseCheckoutAction.description.disabled.currently-checked-out=Branch ''{0}'' is currently checked out
action.GitMachete.BaseCheckoutAction.description.precise=Checkout branch ''{0}''
action.GitMachete.BaseCheckoutAction.undefined.current-branch=There is no current branch; the repository is probably in detached HEAD state


action.GitMachete.BaseCompareWithParentAction.description.disabled.branch-is-root=Cannot compare with a parent. Branch ''{0}'' is a root.
action.GitMachete.BaseCompareWithParentAction.description.precise=Show commits in ''{0}'' that are missing in ''{1}''


action.GitMachete.BaseFastForwardMergeToParentAction.description-action-name=Fast-forward merge
action.GitMachete.BaseFastForwardMergeToParentAction.description=Fast-forward merge branch ''{1}'' to ''{0}''
action.GitMachete.BaseFastForwardMergeToParentAction.notification.title.ff-fail=Fast-forward merge failed
Expand Down Expand Up @@ -203,10 +212,8 @@ action.GitMachete.CheckoutSelectedAction.text=Git Machete: Checkout Selected Bra
action.GitMachete.CheckoutSelectedAction.GitMacheteContextMenu.text=_Checkout
action.GitMachete.CheckoutSelectedAction.undefined.branch-name=Checkout disabled due to undefined branch name

action.GitMachete.BaseCheckoutAction.description.disabled.currently-checked-out=Branch ''{0}'' is currently checked out
action.GitMachete.BaseCheckoutAction.description.precise=Checkout branch ''{0}''
action.GitMachete.BaseCheckoutAction.undefined.current-branch=There is no current branch; the repository is probably in detached HEAD state

action.GitMachete.CompareSelectedWithParentAction.text=Git Machete: Compare Selected Branch with Parent
action.GitMachete.CompareSelectedWithParentAction.GitMacheteContextMenu.text=Compare _With Parent

action.GitMachete.FastForwardMergeSelectedToParentAction.text=Git Machete: Fast-forward Merge into Parent
action.GitMachete.FastForwardMergeSelectedToParentAction.GitMacheteContextMenu.text=_Fast-forward Merge into Parent
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@
<override-text place="GitMacheteContextMenu"/>
</action>

<action id="GitMachete.CompareSelectedWithParentAction"
class="com.virtuslab.gitmachete.frontend.actions.contextmenu.CompareSelectedWithParentAction">
<override-text place="GitMacheteContextMenu"/>
</action>

<action class="com.virtuslab.gitmachete.frontend.actions.contextmenu.ShowSelectedInGitLogAction"
id="GitMachete.ShowSelectedInGitLogAction">
<override-text place="GitMacheteContextMenu"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ public void only_continues_in_background_methods_should_enqueue_background_tasks
String calledMethodName = calledMethod.getName();
JavaClass calledMethodOwner = calledMethod.getOwner();
return calledMethodOwner.isAssignableTo(Task.Backgroundable.class) && calledMethodName.equals("queue") ||
calledMethodOwner.isAssignableTo(GitBrancher.class) && !calledMethodName.equals("getInstance") ||
calledMethodOwner.isAssignableTo(GitBrancher.class)
&& !(calledMethodName.equals("getInstance") || calledMethodName.equals("compare"))
||
calledMethodOwner.isAssignableTo(VcsPushDialog.class) && calledMethodName.equals("show") ||
calledMethod.getRawReturnType().isEquivalentTo(java.util.concurrent.Future.class);
}))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public boolean test(JavaMethod method) {
"git4idea.GitUtil.getRepositoryManager(com.intellij.openapi.project.Project)",
"git4idea.branch.GitBranchUtil.sortBranchNames(java.util.Collection)",
"git4idea.branch.GitBrancher.checkout(java.lang.String, boolean, java.util.List, java.lang.Runnable)",
"git4idea.branch.GitBrancher.compare(java.lang.String, java.util.List)",
"git4idea.branch.GitBrancher.createBranch(java.lang.String, java.util.Map)",
"git4idea.branch.GitBrancher.deleteBranch(java.lang.String, java.util.List)",
"git4idea.branch.GitBrancher.deleteBranches(java.util.Map, java.lang.Runnable)",
Expand Down

0 comments on commit 5112285

Please sign in to comment.