Skip to content

Commit

Permalink
Merge branch 'release/0.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
OpherV committed Jun 20, 2017
2 parents eccb0e7 + e70e3fa commit 19224cb
Show file tree
Hide file tree
Showing 32 changed files with 527 additions and 284 deletions.
2 changes: 1 addition & 1 deletion META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<depends>com.intellij.tasks</depends>
<depends>Git4Idea</depends>

<idea-version since-build="162.0" until-build="171.*"/>
<idea-version since-build="162.0" until-build="172.*"/>

<actions>
<action id="Gitflow.OpenGitflowPopup" class="gitflow.actions.OpenGitflowPopup"
Expand Down
15 changes: 8 additions & 7 deletions src/gitflow/GitInitLineHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,32 +42,33 @@ protected void processTerminated(final int exitCode) {
protected void onTextAvailable(String s, Key key) {
super.onTextAvailable(s, key);
try {
if (s.contains("Branch name for production releases")) {
if (s.contains("name for production releases")) {
writer.write(_initOptions.getProductionBranch());
myVcs.showCommandLine(_initOptions.getProductionBranch());
writer.newLine();
writer.flush();
}

if (s.contains("Branch name for \"next release\"")) {

if (s.contains("name for \"next release\"")) {
writer.write(_initOptions.getDevelopmentBranch());
myVcs.showCommandLine(_initOptions.getDevelopmentBranch());
writer.newLine();
writer.flush();
}

if (s.contains("Which branch should be used for integration of the")) {
writer.newLine();
writer.flush();
}

if (s.contains("Feature branches")) {
writer.write(_initOptions.getFeaturePrefix());
myVcs.showCommandLine(_initOptions.getFeaturePrefix());
writer.newLine();
writer.flush();
}
if (s.contains("Bugfix branches")) {
writer.write(_initOptions.getBugfixPrefix());
myVcs.showCommandLine(_initOptions.getBugfixPrefix());
writer.newLine();
writer.flush();
}
if (s.contains("Release branches")) {
writer.write(_initOptions.getReleasePrefix());
myVcs.showCommandLine(_initOptions.getReleasePrefix());
Expand Down
32 changes: 16 additions & 16 deletions src/gitflow/GitflowBranchUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,37 @@
public class GitflowBranchUtil {

Project myProject;
GitRepository repo;
GitRepository myRepo;

String currentBranchName;
String branchnameMaster;
String prefixFeature;
String prefixRelease;
String prefixHotfix;

public GitflowBranchUtil(Project project){
public GitflowBranchUtil(Project project, GitRepository repo){
myProject=project;
repo = GitBranchUtil.getCurrentRepository(project);
myRepo = repo;

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

branchnameMaster= GitflowConfigUtil.getMasterBranch(project);
prefixFeature = GitflowConfigUtil.getFeaturePrefix(project);
prefixRelease = GitflowConfigUtil.getReleasePrefix(project);
prefixHotfix = GitflowConfigUtil.getHotfixPrefix(project);
branchnameMaster= GitflowConfigUtil.getMasterBranch(project, repo);
prefixFeature = GitflowConfigUtil.getFeaturePrefix(project, repo);
prefixRelease = GitflowConfigUtil.getReleasePrefix(project, repo);
prefixHotfix = GitflowConfigUtil.getHotfixPrefix(project, repo);
}
}

public boolean hasGitflow(){
boolean hasGitflow=false;

hasGitflow = repo!= null
&& GitflowConfigUtil.getMasterBranch(myProject)!=null
&& GitflowConfigUtil.getDevelopBranch(myProject)!=null
&& GitflowConfigUtil.getFeaturePrefix(myProject)!=null
&& GitflowConfigUtil.getReleasePrefix(myProject)!=null
&& GitflowConfigUtil.getHotfixPrefix(myProject)!=null;
hasGitflow = myRepo != null
&& GitflowConfigUtil.getMasterBranch(myProject, myRepo)!=null
&& GitflowConfigUtil.getDevelopBranch(myProject, myRepo)!=null
&& GitflowConfigUtil.getFeaturePrefix(myProject, myRepo)!=null
&& GitflowConfigUtil.getReleasePrefix(myProject, myRepo)!=null
&& GitflowConfigUtil.getHotfixPrefix(myProject, myRepo)!=null;

return hasGitflow;
}
Expand Down Expand Up @@ -117,7 +117,7 @@ public ArrayList<String> filterBranchListByPrefix(Collection<String> inputBranch
}

public ArrayList<String> getRemoteBranchNames(){
ArrayList<GitRemoteBranch> remoteBranches = new ArrayList<GitRemoteBranch>(repo.getBranches().getRemoteBranches());
ArrayList<GitRemoteBranch> remoteBranches = new ArrayList<GitRemoteBranch>(myRepo.getBranches().getRemoteBranches());
ArrayList<String> branchNameList = new ArrayList<String>();

for(Iterator<GitRemoteBranch> i = remoteBranches.iterator(); i.hasNext(); ) {
Expand All @@ -130,7 +130,7 @@ public ArrayList<String> getRemoteBranchNames(){


public ArrayList<String> getLocalBranchNames(){
ArrayList<GitLocalBranch> localBranches = new ArrayList<GitLocalBranch>(repo.getBranches().getLocalBranches());
ArrayList<GitLocalBranch> localBranches = new ArrayList<GitLocalBranch>(myRepo.getBranches().getLocalBranches());
ArrayList<String> branchNameList = new ArrayList<String>();

for(Iterator<GitLocalBranch> i = localBranches.iterator(); i.hasNext(); ) {
Expand All @@ -146,7 +146,7 @@ public ArrayList<String> getLocalBranchNames(){
public GitRemote getRemoteByBranch(String branchName){
GitRemote remote=null;

ArrayList<GitRemoteBranch> remoteBranches= new ArrayList<GitRemoteBranch>(repo.getBranches().getRemoteBranches());
ArrayList<GitRemoteBranch> remoteBranches= new ArrayList<GitRemoteBranch>(myRepo.getBranches().getRemoteBranches());

for(Iterator<GitRemoteBranch> i = remoteBranches.iterator(); i.hasNext(); ) {
GitRemoteBranch branch = i.next();
Expand Down
45 changes: 45 additions & 0 deletions src/gitflow/GitflowBranchUtilManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package gitflow;

import com.intellij.openapi.project.Project;
import git4idea.GitUtil;
import git4idea.repo.GitRepository;
import gitflow.actions.GitflowActions;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

/**
* This class maps repos to their corresponding branch utils
*/
public class GitflowBranchUtilManager {
private static HashMap<GitRepository, GitflowBranchUtil> repoBranchUtilMap;

static public GitflowBranchUtil getBranchUtil(GitRepository repo){
return repoBranchUtilMap.get(repo);
}

static public void setupBranchUtil(Project project, GitRepository repo){
GitflowBranchUtil gitflowBranchUtil = new GitflowBranchUtil(project, repo);
repoBranchUtilMap.put(repo, gitflowBranchUtil);
}

/**
* Repopulates the branchUtils for each repo
* @param project
*/
static public void update(Project project){
if (repoBranchUtilMap == null){
repoBranchUtilMap = new HashMap<GitRepository, GitflowBranchUtil>();
}
repoBranchUtilMap.clear();

List<GitRepository> gitRepositories = GitUtil.getRepositoryManager(project).getRepositories();

Iterator gitRepositoriesIterator = gitRepositories.iterator();
while(gitRepositoriesIterator.hasNext()){
GitRepository repo = (GitRepository) gitRepositoriesIterator.next();
GitflowBranchUtilManager.setupBranchUtil(project, repo);
}
}
}
11 changes: 7 additions & 4 deletions src/gitflow/GitflowComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,13 @@ public void directoryMappingChanged() {
//git repo present
if (vcsRoots.length>0 && vcsRoots[0].getVcs() instanceof GitVcs){

myGitflowWidget = new GitflowWidget(myProject);
StatusBar statusBar = WindowManager.getInstance().getStatusBar(myProject);
if (statusBar != null) {
statusBar.addWidget(myGitflowWidget, "after " + git4idea.ui.branch.GitBranchWidget.class.getName(), myProject);
//make sure to not reinitialize the widget if it's already present
if (myGitflowWidget == null) {
myGitflowWidget = new GitflowWidget(myProject);
StatusBar statusBar = WindowManager.getInstance().getStatusBar(myProject);
if (statusBar != null) {
statusBar.addWidget(myGitflowWidget, "after " + git4idea.ui.branch.GitBranchWidget.class.getName(), myProject);
}
}
}
else{
Expand Down
58 changes: 26 additions & 32 deletions src/gitflow/GitflowConfigUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public class GitflowConfigUtil {
public static final String PREFIX_SUPPORT = "gitflow.prefix.support";
public static final String PREFIX_VERSIONTAG = "gitflow.prefix.versiontag";

public static String getMasterBranch(Project project){
GitRepository repo = GitBranchUtil.getCurrentRepository(project);
public static String getMasterBranch(Project project, GitRepository repo){
VirtualFile root = repo.getRoot();

String masterBranch=null;
Expand All @@ -41,8 +40,7 @@ public static String getMasterBranch(Project project){
return masterBranch;
}

public static String getDevelopBranch(Project project){
GitRepository repo = GitBranchUtil.getCurrentRepository(project);
public static String getDevelopBranch(Project project, GitRepository repo){
VirtualFile root = repo.getRoot();

String developBranch=null;
Expand All @@ -56,8 +54,7 @@ public static String getDevelopBranch(Project project){
return developBranch;
}

public static String getFeaturePrefix(Project project){
GitRepository repo = GitBranchUtil.getCurrentRepository(project);
public static String getFeaturePrefix(Project project, GitRepository repo){
VirtualFile root = repo.getRoot();

String featurePrefix=null;
Expand All @@ -71,8 +68,7 @@ public static String getFeaturePrefix(Project project){
return featurePrefix;
}

public static String getReleasePrefix(Project project){
GitRepository repo = GitBranchUtil.getCurrentRepository(project);
public static String getReleasePrefix(Project project, GitRepository repo){
VirtualFile root = repo.getRoot();

String releasePrefix=null;
Expand All @@ -86,8 +82,7 @@ public static String getReleasePrefix(Project project){
return releasePrefix;
}

public static String getHotfixPrefix(Project project){
GitRepository repo = GitBranchUtil.getCurrentRepository(project);
public static String getHotfixPrefix(Project project, GitRepository repo){
VirtualFile root = repo.getRoot();

String hotfixPrefix=null;
Expand All @@ -101,28 +96,27 @@ public static String getHotfixPrefix(Project project){
return hotfixPrefix;
}

public static String getFeatureNameFromBranch(Project project, String branchName){
String featurePrefix= GitflowConfigUtil.getFeaturePrefix(project);
public static String getFeatureNameFromBranch(Project project, GitRepository repo, String branchName){
String featurePrefix= GitflowConfigUtil.getFeaturePrefix(project, repo);
return branchName.substring(branchName.indexOf(featurePrefix)+featurePrefix.length(),branchName.length());
}

public static String getReleaseNameFromBranch(Project project, String branchName){
String releasePrefix= GitflowConfigUtil.getReleasePrefix(project);
public static String getReleaseNameFromBranch(Project project, GitRepository repo, String branchName){
String releasePrefix= GitflowConfigUtil.getReleasePrefix(project, repo);
return branchName.substring(branchName.indexOf(releasePrefix) + releasePrefix.length(), branchName.length());
}

public static String getHotfixNameFromBranch(Project project, String branchName){
String hotfixPrefix= GitflowConfigUtil.getHotfixPrefix(project);
public static String getHotfixNameFromBranch(Project project, GitRepository repo, String branchName){
String hotfixPrefix= GitflowConfigUtil.getHotfixPrefix(project, repo);
return branchName.substring(branchName.indexOf(hotfixPrefix) + hotfixPrefix.length(), branchName.length());
}

public static String getRemoteNameFromBranch(Project project, String branchName){
return branchName.substring(0,branchName.indexOf("/"));
}

public static void setMasterBranch(Project project, String branchName)
public static void setMasterBranch(Project project, GitRepository repo, String branchName)
{
GitRepository repo = GitBranchUtil.getCurrentRepository(project);
VirtualFile root = repo.getRoot();

try {
Expand All @@ -132,8 +126,8 @@ public static void setMasterBranch(Project project, String branchName)
}
}

public static void setDevelopBranch(Project project, String branchName) {
GitRepository repo = GitBranchUtil.getCurrentRepository(project);
public static void setDevelopBranch(Project project, GitRepository repo, String branchName) {

VirtualFile root = repo.getRoot();

try {
Expand All @@ -143,8 +137,8 @@ public static void setDevelopBranch(Project project, String branchName) {
}
}

public static void setReleasePrefix(Project project, String prefix) {
GitRepository repo = GitBranchUtil.getCurrentRepository(project);
public static void setReleasePrefix(Project project, GitRepository repo, String prefix) {

VirtualFile root = repo.getRoot();

try {
Expand All @@ -154,8 +148,8 @@ public static void setReleasePrefix(Project project, String prefix) {
}
}

public static void setFeaturePrefix(Project project, String prefix) {
GitRepository repo = GitBranchUtil.getCurrentRepository(project);
public static void setFeaturePrefix(Project project, GitRepository repo, String prefix) {

VirtualFile root = repo.getRoot();

try {
Expand All @@ -165,8 +159,8 @@ public static void setFeaturePrefix(Project project, String prefix) {
}
}

public static void setHotfixPrefix(Project project, String prefix) {
GitRepository repo = GitBranchUtil.getCurrentRepository(project);
public static void setHotfixPrefix(Project project, GitRepository repo, String prefix) {

VirtualFile root = repo.getRoot();

try {
Expand All @@ -176,8 +170,8 @@ public static void setHotfixPrefix(Project project, String prefix) {
}
}

public static void setSupportPrefix(Project project, String prefix) {
GitRepository repo = GitBranchUtil.getCurrentRepository(project);
public static void setSupportPrefix(Project project, GitRepository repo, String prefix) {

VirtualFile root = repo.getRoot();

try {
Expand All @@ -187,8 +181,8 @@ public static void setSupportPrefix(Project project, String prefix) {
}
}

public static void setVersionPrefix(Project project, String prefix) {
GitRepository repo = GitBranchUtil.getCurrentRepository(project);
public static void setVersionPrefix(Project project, GitRepository repo, String prefix) {

VirtualFile root = repo.getRoot();

try {
Expand All @@ -198,8 +192,8 @@ public static void setVersionPrefix(Project project, String prefix) {
}
}

public static String getBaseBranch(Project project, String branchName){
GitRepository repo = GitBranchUtil.getCurrentRepository(project);
public static String getBaseBranch(Project project, GitRepository repo, String branchName){

VirtualFile root = repo.getRoot();

String baseBranch=null;
Expand Down
9 changes: 9 additions & 0 deletions src/gitflow/GitflowInitOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class GitflowInitOptions {
private String featurePrefix;
private String releasePrefix;
private String hotfixPrefix;
private String bugfixPrefix;
private String supportPrefix;
private String versionPrefix;

Expand Down Expand Up @@ -69,6 +70,14 @@ public void setSupportPrefix(String supportPrefix) {
this.supportPrefix = supportPrefix;
}

public String getBugfixPrefix() {
return bugfixPrefix;
}

public void setBugfixPrefix(String bugfixPrefix) {
this.bugfixPrefix = bugfixPrefix;
}

public String getVersionPrefix() {
return versionPrefix;
}
Expand Down
Loading

0 comments on commit 19224cb

Please sign in to comment.