Skip to content

Commit

Permalink
Merge branch 'release/0.4.9'
Browse files Browse the repository at this point in the history
  • Loading branch information
OpherV committed Aug 17, 2016
2 parents 8a3c83e + 98e8e6d commit 36d5afa
Show file tree
Hide file tree
Showing 14 changed files with 708 additions and 98 deletions.
8 changes: 5 additions & 3 deletions META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
<name>Git Flow Integration</name>
<id>Gitflow</id>
<description>Git Flow Integration</description>
<version>0.4.8</version>
<version>0.4.9</version>
<category>VCS Integration</category>
<vendor url="http://www.opherv.com">Opher Vishnia</vendor>

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

<idea-version since-build="162.0" until-build="162.*"/>
Expand Down Expand Up @@ -39,8 +40,9 @@
</project-components>

<extensions defaultExtensionNs="com.intellij">
<applicationService serviceInterface="gitflow.Gitflow"
serviceImplementation="gitflow.GitflowImpl"/>
<applicationService serviceInterface="gitflow.Gitflow" serviceImplementation="gitflow.GitflowImpl"/>
<applicationService serviceInterface="gitflow.GitflowState" serviceImplementation="gitflow.GitflowState"></applicationService>
<projectConfigurable instance="gitflow.GitflowConfigurable" />
<tasks.dialogPanelProvider implementation="gitflow.ui.GitflowTaskDialogPanelProvider" />
</extensions>
</idea-plugin>
66 changes: 64 additions & 2 deletions src/gitflow/GitflowBranchUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
import git4idea.branch.GitBranchUtil;
import git4idea.repo.GitRemote;
import git4idea.repo.GitRepository;
import gitflow.ui.AbstractBranchStartDialog;

import javax.swing.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

/**
*
Expand Down Expand Up @@ -55,7 +58,7 @@ public boolean isCurrentBranchMaster(){
}

public boolean isCurrentBranchFeature(){
return currentBranchName.startsWith(prefixFeature);
return isBranchFeature(currentBranchName);
}


Expand All @@ -64,14 +67,21 @@ public boolean isCurrentBranchRelease(){
}

public boolean isCurrentBranchHotfix(){
return currentBranchName.startsWith(prefixHotfix);
return isBranchHotfix(currentBranchName);
}

//checks whether the current branch also exists on the remote
public boolean isCurrentBranchPublished(){
return getRemoteBranchesWithPrefix(currentBranchName).isEmpty()==false;
}

public boolean isBranchFeature(String branchName){
return branchName.startsWith(prefixFeature);
}

public boolean isBranchHotfix(String branchName){
return branchName.startsWith(prefixHotfix);
}

//if no prefix specified, returns all remote branches
public ArrayList<String> getRemoteBranchesWithPrefix(String prefix){
Expand Down Expand Up @@ -180,4 +190,56 @@ public boolean areAllBranchesTracked(String prefix){

return true;
}

public ComboBoxModel createBranchComboModel(String defaultBranch) {
final List<String> branchList = this.getLocalBranchNames();
branchList.remove(defaultBranch);

ComboEntry[] entries = new ComboEntry[branchList.size() + 1];
entries[0] = new ComboEntry(defaultBranch, defaultBranch + " (default)");
for (int i = 1; i <= branchList.size(); i++) {
String branchName = branchList.get(i - 1);
entries[i] = new ComboEntry(branchName, branchName);
}

return new DefaultComboBoxModel(entries);
}

/**
* Strip a full branch name from its gitflow prefix
* @param taskFullBranchName full name of the branch (e.g. 'feature/hello');
* @return the branch name, prefix free (e.g. 'hello')
*/
public String stripFullBranchName(String taskFullBranchName) {
if (taskFullBranchName.startsWith(prefixFeature)){
return taskFullBranchName.substring(prefixFeature.length(), taskFullBranchName.length());
}
else if (taskFullBranchName.startsWith(prefixHotfix)){
return taskFullBranchName.substring(prefixHotfix.length(), taskFullBranchName.length());
}
else{
return null;
}
};

/**
* An entry for the branch selection dropdown/combo.
*/
public static class ComboEntry {
private String branchName, label;

public ComboEntry(String branchName, String label) {
this.branchName = branchName;
this.label = label;
}

public String getBranchName() {
return branchName;
}

@Override
public String toString() {
return label;
}
}
}
61 changes: 61 additions & 0 deletions src/gitflow/GitflowState.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package gitflow;

import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.tasks.Task;
import com.intellij.util.xmlb.XmlSerializerUtil;
import org.jetbrains.annotations.Nullable;

import java.util.HashMap;

/**
* Persistent state for Gitflow component
* Created by opherv on 8/17/16.
*/

@State(
name = "GitflowState", storages = {
@Storage(
id = "other",
file = "$APP_CONFIG$/GitflowState.xml")
})
public class GitflowState implements PersistentStateComponent<GitflowState> {

private HashMap<String, String> taskBranches;


public GitflowState() {
taskBranches = new HashMap<String, String>();
}


public HashMap<String, String> getTaskBranches() {
return taskBranches;
}

public void setTaskBranches(HashMap<String, String> taskBranches) {
this.taskBranches = taskBranches;
}

@Nullable
@Override
public GitflowState getState() {
return this;
}

@Override
public void loadState(GitflowState state) {
XmlSerializerUtil.copyBean(state, this);

}

public String getTaskBranch(Task task){
return taskBranches.get(task.getId());
}


public void setTaskBranch(Task task, String branchName){
taskBranches.put(task.getId(), branchName);
}
}
67 changes: 38 additions & 29 deletions src/gitflow/actions/FinishFeatureAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.vcs.VcsException;
import git4idea.branch.GitBranchUtil;
Expand All @@ -16,7 +17,7 @@ public class FinishFeatureAction extends GitflowAction {

String customFeatureName=null;

FinishFeatureAction() {
public FinishFeatureAction() {
super("Finish Feature");
}

Expand All @@ -41,46 +42,54 @@ public void actionPerformed(AnActionEvent e) {
else{
featureName = GitflowConfigUtil.getFeatureNameFromBranch(myProject, currentBranchName);
}
final GitflowErrorsListener errorLineHandler = new GitflowErrorsListener(myProject);

new Task.Backgroundable(myProject,"Finishing feature "+featureName,false){
@Override
public void run(@NotNull ProgressIndicator indicator) {
GitCommandResult result = myGitflow.finishFeature(repo,featureName,errorLineHandler);
this.runAction(myProject, featureName);
}

}

if (result.success()) {
String finishedFeatureMessage = String.format("The feature branch '%s%s' was merged into '%s'", featurePrefix, featureName, developBranch);
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");
}
public void runAction(final Project project, final String featureName){
super.runAction(project, null, featureName);

final GitflowErrorsListener errorLineHandler = new GitflowErrorsListener(myProject);
final FinishFeatureAction that = this;

new Task.Backgroundable(myProject,"Finishing feature "+featureName,false){
@Override
public void run(@NotNull ProgressIndicator indicator) {
GitCommandResult result = myGitflow.finishFeature(repo,featureName,errorLineHandler);

repo.update();

if (result.success()) {
String finishedFeatureMessage = String.format("The feature branch '%s%s' was merged into '%s'", featurePrefix, featureName, developBranch);
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");
}

@Override
public void onSuccess() {
super.onSuccess();
repo.update();

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

}
@Override
public void onSuccess() {
super.onSuccess();

//merge conflicts if necessary
if (errorLineHandler.hasMergeError){
if (handleMerge()){
that.runAction(project, featureName);
FinishFeatureAction completeFinishFeatureAction = new FinishFeatureAction(featureName);
}

}
}.queue();
}

}
}.queue();;
}

}
43 changes: 26 additions & 17 deletions src/gitflow/actions/FinishHotfixAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import git4idea.branch.GitBranchUtil;
import git4idea.commands.GitCommandResult;
Expand All @@ -13,7 +14,7 @@

public class FinishHotfixAction extends GitflowAction {

FinishHotfixAction() {
public FinishHotfixAction() {
super("Finish Hotfix");
}

Expand Down Expand Up @@ -41,27 +42,35 @@ public void actionPerformed(AnActionEvent e) {
tagMessage = Messages.showInputDialog(myProject, "Enter the tag message:", "Finish Hotfix", Messages.getQuestionIcon(), defaultTagMessage, null);
}

final GitflowErrorsListener errorLineHandler = new GitflowErrorsListener(myProject);
this.runAction(e.getProject(), hotfixName, tagMessage);

if (tagMessage!=null){
new Task.Backgroundable(myProject,"Finishing hotfix "+hotfixName,false){
@Override
public void run(@NotNull ProgressIndicator indicator) {
GitCommandResult result= myGitflow.finishHotfix(repo, hotfixName, tagMessage, errorLineHandler);
}

}

public void runAction(final Project project, final String hotfixName, final String tagMessage){
super.runAction(project, null, hotfixName);

if (result.success()) {
String finishedHotfixMessage = String.format("The hotfix branch '%s%s' was merged into '%s' and '%s'", hotfixPrefix, hotfixName, developBranch, masterBranch);
NotifyUtil.notifySuccess(myProject, hotfixName, finishedHotfixMessage);
}
else {
NotifyUtil.notifyError(myProject, "Error", "Please have a look at the Version Control console for more details");
}
final GitflowErrorsListener errorLineHandler = new GitflowErrorsListener(myProject);

repo.update();
if (tagMessage!=null){
new Task.Backgroundable(myProject,"Finishing hotfix "+hotfixName,false){
@Override
public void run(@NotNull ProgressIndicator indicator) {
GitCommandResult result= myGitflow.finishHotfix(repo, hotfixName, tagMessage, errorLineHandler);

if (result.success()) {
String finishedHotfixMessage = String.format("The hotfix branch '%s%s' was merged into '%s' and '%s'", hotfixPrefix, hotfixName, developBranch, masterBranch);
NotifyUtil.notifySuccess(myProject, hotfixName, finishedHotfixMessage);
}
}.queue();
}
else {
NotifyUtil.notifyError(myProject, "Error", "Please have a look at the Version Control console for more details");
}

repo.update();

}
}.queue();
}

}
Expand Down
24 changes: 17 additions & 7 deletions src/gitflow/actions/GitflowAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,31 @@ public class GitflowAction extends DumbAwareAction {

@Override
public void actionPerformed(AnActionEvent e) {
setup(e.getProject());
}

public void setup(Project project){
myProject = project;
virtualFileMananger = VirtualFileManager.getInstance();
myProject=e.getProject();
branchUtil=new GitflowBranchUtil(myProject);

featurePrefix = GitflowConfigUtil.getFeaturePrefix(myProject);
releasePrefix = GitflowConfigUtil.getReleasePrefix(myProject);
hotfixPrefix= GitflowConfigUtil.getHotfixPrefix(myProject);
masterBranch= GitflowConfigUtil.getMasterBranch(myProject);
developBranch= GitflowConfigUtil.getDevelopBranch(myProject);

branchUtil=new GitflowBranchUtil(project);

repo = GitBranchUtil.getCurrentRepository(myProject);
repos.add(repo);

if (repo!=null){
currentBranchName= GitBranchUtil.getBranchNameOrRev(repo);
}
}

featurePrefix = GitflowConfigUtil.getFeaturePrefix(myProject);
releasePrefix = GitflowConfigUtil.getReleasePrefix(myProject);
hotfixPrefix= GitflowConfigUtil.getHotfixPrefix(myProject);
masterBranch= GitflowConfigUtil.getMasterBranch(myProject);
developBranch= GitflowConfigUtil.getDevelopBranch(myProject);
public void runAction(Project project, final String baseBranchName, final String branchName){
setup(project);
}

//returns true if merge successful, false otherwise
Expand Down
Loading

0 comments on commit 36d5afa

Please sign in to comment.