Skip to content

Commit

Permalink
Fix #197 NullPointerException on close active task
Browse files Browse the repository at this point in the history
  • Loading branch information
OpherV committed Sep 21, 2018
1 parent 6e48ae7 commit 0963dcf
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 32 deletions.
18 changes: 18 additions & 0 deletions src/gitflow/DefaultOptions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package gitflow;

import java.util.HashMap;
import java.util.Map;

public class DefaultOptions {
private static final Map<String, String> options;
static
{
options = new HashMap<String, String>();
options.put("RELEASE_customTagCommitMessage", "Tagging version %name%");
options.put("HOTFIX_customHotfixCommitMessage", "Tagging hotfix %name%");
}

public static String getOption(String optionId){
return options.get(optionId);
}
}
9 changes: 8 additions & 1 deletion src/gitflow/GitflowConfigurable.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import javax.swing.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
Expand All @@ -21,12 +22,14 @@ public class GitflowConfigurable implements Configurable {
GitflowOptionsForm gitflowOptionsForm;
PropertiesComponent propertiesComponent;
Map<Enum<GitflowOptionsFactory.TYPE>, ArrayList<Map<String,String>>> gitflowOptions;
Map<String, String> optionDefaults;

static GitflowConfigurable instance;

public GitflowConfigurable(Project project) {
gitflowOptions = GitflowOptionsFactory.getOptions();
propertiesComponent = PropertiesComponent.getInstance(project);
optionDefaults = new HashMap<String, String>();
this.project = project;
instance = this;
}
Expand Down Expand Up @@ -58,7 +61,11 @@ public static boolean isOptionActive(Project project, String optionId){
}

public static String getOptionTextString (Project project, String optionId){
return PropertiesComponent.getInstance(project).getValue(optionId+"_text");
String retValue = PropertiesComponent.getInstance(project).getValue(optionId+"_text");
if (retValue == null){
retValue = DefaultOptions.getOption(optionId);
}
return retValue;
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/gitflow/GitflowOptionsFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ private GitflowOptionsFactory(){
addOption(TYPE.RELEASE, "Keep branch after performing finish", "keepBranch" , "-k");
// addOption(TYPE.RELEASE, "Squash release during merge", "squash" , "-S");
addOption(TYPE.RELEASE, "Don't tag release", "dontTag" , "-n");
addOption(TYPE.RELEASE, "Use custom tag commit message", "customTagCommitMessage" , null, "Tagging version %name%" ,"Use %name% for the branch name");
addOption(TYPE.RELEASE, "Use custom tag commit message", "customTagCommitMessage" , null, DefaultOptions.getOption("RELEASE_customTagCommitMessage") ,"Use %name% for the branch name");

addBranchType(TYPE.HOTFIX);
addOption(TYPE.HOTFIX, "Fetch from Origin", "fetchFromOrigin" , "-F");
addOption(TYPE.HOTFIX, "Push on finish Hotfix", "pushOnFinish" , "-p");
addOption(TYPE.HOTFIX, "Don't tag Hotfix", "dontTag" , "-n");
addOption(TYPE.HOTFIX, "Use custom hotfix commit message", "customHotfixCommitMessage" , null, "Tagging hotfix %name%" ,"Use %name% for the branch name");
addOption(TYPE.HOTFIX, "Use custom hotfix commit message", "customHotfixCommitMessage" , null, DefaultOptions.getOption("HOTFIX_customHotfixCommitMessage") ,"Use %name% for the branch name");
}

private void addBranchType(Enum<TYPE> branchType){
Expand Down
16 changes: 3 additions & 13 deletions src/gitflow/actions/FinishHotfixAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,16 @@ public void actionPerformed(AnActionEvent e) {
String currentBranchName = GitBranchUtil.getBranchNameOrRev(myRepo);


if (currentBranchName.isEmpty()==false){
if (currentBranchName.isEmpty() == false){

//TODO HOTFIX NAME
final String hotfixName = GitflowConfigUtil.getHotfixNameFromBranch(myProject, myRepo, currentBranchName);

final String tagMessage;
String tagMessageTemplate;

String defaultTagMessage = "Tagging hotfix %name%";
String customTagMessage = GitflowConfigurable.getOptionTextString(myProject, "HOTFIX_customHotfixCommitMessage");

if (customTagMessage != null) {
tagMessageTemplate = customTagMessage.replace("%name%", hotfixName);
}
else{
tagMessageTemplate = defaultTagMessage.replace("%name%", hotfixName);
}
String tagMessageTemplate = GitflowConfigurable.getOptionTextString(myProject, "HOTFIX_customHotfixCommitMessage").replace("%name%", hotfixName);

if (GitflowConfigurable.isOptionActive(myProject, "HOTFIX_dontTag")) {
tagMessage="";
tagMessage = "";
}
else {
tagMessage = Messages.showInputDialog(myProject, "Enter the tag message:", "Finish Hotfix", Messages.getQuestionIcon(), tagMessageTemplate, null);
Expand Down
15 changes: 2 additions & 13 deletions src/gitflow/actions/FinishReleaseAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,10 @@ public void actionPerformed(AnActionEvent e) {
releaseName = customReleaseName!=null ? customReleaseName:GitflowConfigUtil.getReleaseNameFromBranch(myProject, myRepo, currentBranchName);

final GitflowErrorsListener errorLineHandler = new GitflowErrorsListener(myProject);

String tagMessageTemplate;

String defaultTagMessage = "Tagging version %name%";
String customTagMessage = GitflowConfigurable.getOptionTextString(myProject, "RELEASE_customTagCommitMessage");
if (customTagMessage != null) {
tagMessageTemplate = customTagMessage.replace("%name%", releaseName);
}
else{
tagMessageTemplate = defaultTagMessage.replace("%name%", releaseName);
}


String tagMessageTemplate = GitflowConfigurable.getOptionTextString(myProject, "RELEASE_customTagCommitMessage").replace("%name%", releaseName);
String tagMessageDraft;


boolean cancelAction=false;

if (GitflowConfigurable.isOptionActive(myProject, "RELEASE_dontTag")) {
Expand Down
4 changes: 1 addition & 3 deletions src/gitflow/ui/GitflowCloseTaskPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ public class GitflowCloseTaskPanel extends TaskDialogPanel {
String branchName = myVcsTaskHandler != null
? myVcsTaskHandler.cleanUpBranchName(myTaskManager.constructDefaultBranchName(task))
: myTaskManager.suggestBranchName(task);

//TODO same code exists in FinishHotfixAction, make DRYer


if (GitflowConfigurable.isOptionActive(project, "HOTFIX_dontTag")) {
tagMessage="";
tagMessageTextField.setEnabled(false);
Expand Down

0 comments on commit 0963dcf

Please sign in to comment.