Skip to content

Commit

Permalink
Merge branch 'release/0.3.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
OpherV committed Apr 10, 2014
2 parents 639eb67 + ca9df4b commit 78c87c3
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 42 deletions.
4 changes: 2 additions & 2 deletions META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
<name>Git Flow Integration</name>
<id>Gitflow</id>
<description>Git Flow Integration</description>
<version>0.3.5</version>
<version>0.3.6</version>
<category>VCS Integration</category>
<vendor url="http://www.opherv.com">Opher Vishnia</vendor>

<depends>com.intellij.modules.vcs</depends>
<depends>Git4Idea</depends>

<idea-version since-build="129" until-build="135.999999"/>
<idea-version since-build="129" until-build="136.999999"/>

<actions>
<action id="Gitflow.InitRepo" class="gitflow.actions.InitRepoAction" text="Initialize Gitflow Repository"></action>
Expand Down
43 changes: 8 additions & 35 deletions src/gitflow/actions/FinishFeatureAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void run(@NotNull ProgressIndicator indicator) {
NotifyUtil.notifySuccess(myProject, featureName, finishedFeatureMessage);
}
else if(errorLineHandler.hasMergeError){

// (merge errors are handled in the onSuccess handler)
}
else {
NotifyUtil.notifyError(myProject, "Error", "Please have a look at the Version Control console for more details");
Expand All @@ -66,42 +66,15 @@ else if(errorLineHandler.hasMergeError){
public void onSuccess() {
super.onSuccess();

//merge conflicts if necessary
if (errorLineHandler.hasMergeError){
if (handleMerge()){
FinishFeatureAction completeFinishFeatureAction = new FinishFeatureAction(featureName);
completeFinishFeatureAction.actionPerformed(event);
}

//ugly, but required for intellij to catch up with the external changes made by
//the CLI before being able to run the merge tool
virtualFileMananger.syncRefresh();
try {
Thread.sleep(500);
}
catch (InterruptedException ignored) {
}


//TODO: refactor this logic to work in case of finishRelease as well
if (errorLineHandler.hasMergeError){
GitflowActions.runMergeTool();
repo.update();

//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
int answer = Messages.showYesNoDialog(myProject, "Was the merge completed succesfully?", "Merge", Messages.getQuestionIcon());
if (answer==0){
GitMerger gitMerger=new GitMerger(myProject);
}

try {
gitMerger.mergeCommit(gitMerger.getMergingRoots());
} catch (VcsException e1) {
NotifyUtil.notifyError(myProject, "Error", "Error committing merge result");
e1.printStackTrace();
}

FinishFeatureAction completeFinishFeatureAction = new FinishFeatureAction(featureName);
completeFinishFeatureAction.actionPerformed(event);

}


}
}
}.queue();
}
Expand Down
35 changes: 31 additions & 4 deletions src/gitflow/actions/FinishReleaseAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,49 @@

public class FinishReleaseAction extends GitflowAction {

String customReleaseName=null;
String customtagMessage=null;

FinishReleaseAction() {
super("Finish Release");
}

FinishReleaseAction(String name, String tagMessage) {
super("Finish Release");
customReleaseName=name;
customtagMessage=tagMessage;
}

@Override
public void actionPerformed(AnActionEvent e) {
super.actionPerformed(e);

String currentBranchName = GitBranchUtil.getBranchNameOrRev(repo);
if (currentBranchName.isEmpty()==false){

final String releaseName = GitflowConfigUtil.getReleaseNameFromBranch(myProject, currentBranchName);
final AnActionEvent event=e;

final String tagMessage;
final String releaseName;

// Check if a release name was specified, otherwise take name from current branch
releaseName = customReleaseName!=null ? customReleaseName:GitflowConfigUtil.getReleaseNameFromBranch(myProject, currentBranchName);

final GitflowErrorsListener errorLineHandler = new GitflowErrorsListener(myProject);
String defaultTagMessage= GitflowConfigurable.getCustomTagCommitMessage(myProject);
defaultTagMessage=defaultTagMessage.replace("%name%", releaseName);

String tagMessageDraft;
final String tagMessage;

boolean cancelAction=false;

if (GitflowConfigurable.dontTagRelease(myProject)) {
tagMessage="";
}
else if (customtagMessage!=null){
//probably repeating the release finish after a merge
tagMessage=customtagMessage;
}
else{
tagMessageDraft= Messages.showInputDialog(myProject, "Enter the tag message:", "Finish Release", Messages.getQuestionIcon(), defaultTagMessage, null);
if (tagMessageDraft==null){
Expand All @@ -61,6 +80,9 @@ public void run(@NotNull ProgressIndicator indicator) {
String finishedReleaseMessage = String.format("The release branch '%s%s' was merged into '%s' and '%s'", featurePrefix, releaseName, developBranch, masterBranch);
NotifyUtil.notifySuccess(myProject, releaseName, finishedReleaseMessage);
}
else if(errorLineHandler.hasMergeError){
// (merge errors are handled in the onSuccess handler)
}
else {
NotifyUtil.notifyError(myProject, "Error", "Please have a look at the Version Control console for more details");
}
Expand All @@ -73,8 +95,13 @@ public void run(@NotNull ProgressIndicator indicator) {
public void onSuccess() {
super.onSuccess();

virtualFileMananger.syncRefresh();
repo.update();
//merge conflicts if necessary
if (errorLineHandler.hasMergeError){
if (handleMerge()) {
FinishReleaseAction completeFinisReleaseAction = new FinishReleaseAction(releaseName,tagMessage);
completeFinisReleaseAction.actionPerformed(event);
}
}
}

}.queue();
Expand Down
45 changes: 45 additions & 0 deletions src/gitflow/actions/GitflowAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vfs.VirtualFileManager;
import git4idea.branch.GitBranchUtil;
import git4idea.merge.GitMerger;
import git4idea.repo.GitRepository;
import gitflow.Gitflow;
import gitflow.GitflowBranchUtil;
import gitflow.GitflowConfigUtil;
import gitflow.ui.NotifyUtil;

import java.util.ArrayList;

Expand Down Expand Up @@ -53,4 +57,45 @@ public void actionPerformed(AnActionEvent e) {
masterBranch= GitflowConfigUtil.getMasterBranch(myProject);
developBranch= GitflowConfigUtil.getDevelopBranch(myProject);
}

//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
virtualFileMananger.syncRefresh();
try {
Thread.sleep(500);
}
catch (InterruptedException ignored) {
}


GitflowActions.runMergeTool();
repo.update();

//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
int answer = Messages.showYesNoDialog(myProject, "Was the merge completed succesfully?", "Merge", Messages.getQuestionIcon());
if (answer==0){
GitMerger gitMerger=new GitMerger(myProject);

try {
gitMerger.mergeCommit(gitMerger.getMergingRoots());
} catch (VcsException e1) {
NotifyUtil.notifyError(myProject, "Error", "Error committing merge result");
e1.printStackTrace();
}

return true;
}
else{

NotifyUtil.notifyInfo(myProject,"Merge incomplete","To manually complete the merge choose VCS > Git > Resolve Conflicts.\n" +
"Once done, commit the merged files.\n");
return false;
}


}
}
5 changes: 4 additions & 1 deletion src/gitflow/actions/InitRepoAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.util.Key;
import git4idea.commands.GitCommandResult;
import git4idea.repo.GitRepository;
import gitflow.GitflowInitOptions;
import gitflow.ui.GitflowInitOptionsDialog;
import gitflow.ui.NotifyUtil;
Expand Down Expand Up @@ -35,11 +36,13 @@ public void run(@NotNull ProgressIndicator indicator) {

if (result.success()) {
String publishedFeatureMessage = String.format("Initialized gitflow repo");
NotifyUtil.notifySuccess(myProject, publishedFeatureMessage, "");
NotifyUtil.notifySuccess(myProject, "", publishedFeatureMessage);
} else {
NotifyUtil.notifyError(myProject, "Error", "Please have a look at the Version Control console for more details");
}

//update the widget
myProject.getMessageBus().syncPublisher(GitRepository.GIT_REPO_CHANGE).repositoryChanged(repo);
repo.update();
}
}.queue();
Expand Down
4 changes: 4 additions & 0 deletions src/gitflow/ui/NotifyUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public static void notifySuccess(Project project, String title, String message)
notify(NotificationType.INFORMATION, BALLOON_NOTIFICATION, project, title, message);
}

public static void notifyInfo(Project project, String title, String message) {
notify(NotificationType.INFORMATION, TOOLWINDOW_NOTIFICATION, project, title, message);
}

public static void notifyError(Project project, String title, String message) {
notify(NotificationType.ERROR, TOOLWINDOW_NOTIFICATION, project, title, message);
}
Expand Down

0 comments on commit 78c87c3

Please sign in to comment.