Skip to content

Commit

Permalink
Merge branch 'pull/295' into develop
Browse files Browse the repository at this point in the history
# Conflicts:
#	build.gradle
#	src/main/java/gitflow/GitflowComponent.java
#	src/main/java/gitflow/ui/GitflowUnsupportedVersionWidget.java
#	src/main/java/gitflow/ui/GitflowWidget.java
  • Loading branch information
OpherV committed May 3, 2020
2 parents d4ecb64 + d9cb7d3 commit 0d4825e
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 41 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ Feedback and suggestions are also very welcome.
## License

This plugin is under the [Apache 2.0 license](http://www.apache.org/licenses/LICENSE-2.0.html).
Copyright 2013-2019, Opher Vishnia.
Copyright 2013-2020, Opher Vishnia.


27 changes: 27 additions & 0 deletions src/main/java/gitflow/GitflowService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package gitflow;

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.Service;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.startup.StartupActivity;
import com.intellij.openapi.util.Disposer;
import org.jetbrains.annotations.NotNull;

/**
* @author Fabien Marsaud / @fabmars
* Only one instance, runActivity is called every time a project is opened
*/
@Service
public final class GitflowService implements StartupActivity {

@Override
public void runActivity(@NotNull Project project) {
// Ensure this isn't part of testing
if (!ApplicationManager.getApplication().isUnitTestMode()) {
// Install Git Flow widget
GitflowComponent gitflowComponent = new GitflowComponent(project);
// Prepare for when the project will be closed
Disposer.register(project, gitflowComponent);
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/gitflow/actions/FinishBugfixAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void onSuccess() {

//merge conflicts if necessary
if (errorLineHandler.hasMergeError){
if (handleMerge()){
if (handleMerge(project)){
that.runAction(project, bugfixName);
FinishBugfixAction completeFinishBugfixAction = new FinishBugfixAction(myRepo, bugfixName);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gitflow/actions/FinishFeatureAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void onSuccess() {

//merge conflicts if necessary
if (errorLineHandler.hasMergeError){
if (handleMerge()){
if (handleMerge(project)) {
that.runAction(project, featureName);
FinishFeatureAction completeFinishFeatureAction = new FinishFeatureAction(myRepo, featureName);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gitflow/actions/FinishReleaseAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void onSuccess() {

//merge conflicts if necessary
if (errorLineHandler.hasMergeError){
if (handleMerge()) {
if (handleMerge(myProject)) {
FinishReleaseAction completeFinisReleaseAction = new FinishReleaseAction(releaseName, tagMessage);
completeFinisReleaseAction.actionPerformed(event);
}
Expand Down
44 changes: 33 additions & 11 deletions src/main/java/gitflow/actions/GitflowAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@

import java.util.ArrayList;

public class GitflowAction extends DumbAwareAction {
public abstract class GitflowAction extends DumbAwareAction {

private static final long VFM_REFRESH_DELAY = 750L;

Project myProject;
Gitflow myGitflow = ServiceManager.getService(Gitflow.class);
ArrayList<GitRepository> repos = new ArrayList<GitRepository>();
Expand Down Expand Up @@ -55,28 +58,47 @@ private void setup(Project project){
branchUtil= GitflowBranchUtilManager.getBranchUtil(myRepo);
}

public void runAction(Project project, final String baseBranchName, final String branchName, @Nullable final Runnable callInAwtLater){
public void runAction(final Project project, final String baseBranchName, final String branchName, @Nullable final Runnable callInAwtLater){
setup(project);
}

//returns true if merge successful, false otherwise
public boolean handleMerge(){
//ugly, but required for intellij to catch up with the external changes made by
//the CLI before being able to run the merge tool
public boolean handleMerge(final Project project) {
// FIXME As of 201.0 the async version of this method still doesn't make use of the callback, else we'd
// simply use a FutureTask (which is a Runnable) and its get() method prior to launching the merge tool.
virtualFileMananger.syncRefresh();

try {
Thread.sleep(500);
long start, end = System.currentTimeMillis();
do {
start = end;
// Hence this ugly hack, to let the time to intellij to catch up with the external changes made by the
// CLI before being able to run the merge tool. Else the tool won't have the right state, won't display,
// and the merge success Y/N dialog will appear directly! Anyway, in v193 500ms was sufficient,
// but in v201 the right value seems to be in the [700-750]ms range (on the committer's machine).
Thread.sleep(VFM_REFRESH_DELAY);

GitflowActions.runMergeTool(project); // The window is modal, so we can measure how long it's opened.
end = System.currentTimeMillis();
} while(end - start < 1000L); // Additional hack: a window open <1s obviously didn't open, let's try again.

myRepo.update();

// And refreshing again so an onscreen file doesn't show in a conflicted state when the Y/N dialog show up.
virtualFileMananger.syncRefresh();
Thread.sleep(VFM_REFRESH_DELAY);

return askUserForMergeSuccess(project);
}
catch (InterruptedException ignored) {
return false;
}
}


GitflowActions.runMergeTool();
myRepo.update();

private static boolean askUserForMergeSuccess(Project myProject) {
//if merge was completed successfully, finish the action
//note that if it wasn't intellij is left in the "merging state", and git4idea provides no UI way to resolve it
//merging can be done via intellij itself or any other util
//merging can be done via intellij itself or any other util
int answer = Messages.showYesNoDialog(myProject, "Was the merge completed succesfully?", "Merge", Messages.getQuestionIcon());
if (answer==0){
GitMerger gitMerger=new GitMerger(myProject);
Expand Down
43 changes: 29 additions & 14 deletions src/main/java/gitflow/actions/GitflowActions.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
package gitflow.actions;

import com.intellij.dvcs.ui.BranchActionGroup;
import com.intellij.dvcs.ui.PopupElementWithAdditionalInfo;
import com.intellij.ide.DataManager;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFileManager;
import git4idea.branch.GitBranchUtil;
import git4idea.repo.GitRepository;
import gitflow.Gitflow;
import gitflow.GitflowBranchUtil;
import gitflow.GitflowBranchUtilManager;
import gitflow.GitflowConfigUtil;
import git4idea.actions.GitResolveConflictsAction;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* All actions associated with Gitflow
Expand All @@ -22,9 +13,33 @@
*/
public class GitflowActions {

public static void runMergeTool(){
git4idea.actions.GitResolveConflictsAction resolveAction= new git4idea.actions.GitResolveConflictsAction();
AnActionEvent e = new AnActionEvent(null, DataManager.getInstance().getDataContext(), ActionPlaces.UNKNOWN, new Presentation(""), ActionManager.getInstance(), 0);
public static void runMergeTool(Project project){
GitResolveConflictsAction resolveAction = new GitResolveConflictsAction();
AnActionEvent e = new AnActionEvent(null, new ProjectDataContext(project), ActionPlaces.UNKNOWN, new Presentation(""), ActionManager.getInstance(), 0);
resolveAction.actionPerformed(e);
}


/**
* Simple wrapper containing just enough to let the conflicts resolver to launch
* We could have transferred the DataContext or wrapped a HackyDataContext from the previous action,
* but that would make the semantics terrible
*/
private final static class ProjectDataContext implements DataContext {
private Project project;

private ProjectDataContext(Project project) {
this.project = project;
}

@Nullable
@Override
public Object getData(@NotNull String dataId) {
if(CommonDataKeys.PROJECT.getName().equals(dataId)) {
return project;
} else {
throw new UnsupportedOperationException(dataId);
}
}
}
}
3 changes: 2 additions & 1 deletion src/main/java/gitflow/actions/StartBugfixAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public void actionPerformed(AnActionEvent e) {
this.runAction(e.getProject(), baseBranchName, bugfixName, null);
}

public void runAction(Project project, final String baseBranchName, final String bugfixName, @Nullable final Runnable callInAwtLater){
@Override
public void runAction(final Project project, final String baseBranchName, final String bugfixName, @Nullable final Runnable callInAwtLater){
super.runAction(project, baseBranchName, bugfixName, callInAwtLater);

new Task.Backgroundable(myProject, "Starting bugfix " + bugfixName, false) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gitflow/actions/StartFeatureAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void actionPerformed(AnActionEvent e) {
this.runAction(e.getProject(), baseBranchName, featureName, null);
}

public void runAction(Project project, final String baseBranchName, final String featureName, @Nullable final Runnable callInAwtLater){
public void runAction(final Project project, final String baseBranchName, final String featureName, @Nullable final Runnable callInAwtLater){
super.runAction(project, baseBranchName, featureName, callInAwtLater);

new Task.Backgroundable(myProject, "Starting feature " + featureName, false) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gitflow/actions/StartHotfixAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void actionPerformed(AnActionEvent e) {
this.runAction(e.getProject(), baseBranchName, hotfixName, null);
}

public void runAction(Project project, final String baseBranchName, final String hotfixName, @Nullable final Runnable callInAwtLater){
public void runAction(final Project project, final String baseBranchName, final String hotfixName, @Nullable final Runnable callInAwtLater){
super.runAction(project, baseBranchName, hotfixName, callInAwtLater);

new Task.Backgroundable(myProject, "Starting hotfix " + hotfixName, false) {
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/gitflow/ui/GitflowTaskDialogPanelProvider.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package gitflow.ui;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.project.Project;
import com.intellij.tasks.LocalTask;
import com.intellij.tasks.Task;
Expand All @@ -13,14 +12,19 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Enumeration;
import java.util.HashMap;

public class GitflowTaskDialogPanelProvider extends TaskDialogPanelProvider {

@Deprecated
@Nullable
@Override
public TaskDialogPanel getOpenTaskPanel(@NotNull Project project, @NotNull Task task) {
return null;
}

@Nullable
@Override
public TaskDialogPanel getOpenTaskPanel(@NotNull Project project, @NotNull LocalTask task) {
GitRepository currentRepo = GitBranchUtil.getCurrentRepository(project);
GitflowBranchUtil branchUtil = GitflowBranchUtilManager.getBranchUtil(currentRepo);
if (branchUtil.hasGitflow()) {
Expand Down
7 changes: 1 addition & 6 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,10 @@
</group>
</actions>

<project-components>
<component>
<implementation-class>gitflow.GitflowComponent</implementation-class>
</component>
</project-components>

<extensions defaultExtensionNs="com.intellij">
<applicationService serviceInterface="gitflow.Gitflow" serviceImplementation="gitflow.GitflowImpl"/>
<applicationService serviceInterface="gitflow.GitflowState" serviceImplementation="gitflow.GitflowState"></applicationService>
<postStartupActivity implementation="gitflow.GitflowService"/>
<projectConfigurable instance="gitflow.GitflowConfigurable"/>
<tasks.dialogPanelProvider implementation="gitflow.ui.GitflowTaskDialogPanelProvider"/>
<statusBarWidgetFactory id="gitflowWidget" implementation="gitflow.ui.GitflowStatusBarWidgetFactory" order="after inspectionProfileWidget"/>
Expand Down

0 comments on commit 0d4825e

Please sign in to comment.