@@ -23,12 +23,17 @@ public class GitflowBranchUtil {
2323 Project myProject ;
2424 GitRepository myRepo ;
2525
26- String currentBranchName ;
27- String branchnameMaster ;
28- String prefixFeature ;
29- String prefixRelease ;
30- String prefixHotfix ;
31- String prefixBugfix ;
26+ private String currentBranchName ;
27+ private String branchnameMaster ;
28+ private String branchnameDevelop ;
29+ private String prefixFeature ;
30+ private String prefixRelease ;
31+ private String prefixHotfix ;
32+ private String prefixBugfix ;
33+ private ArrayList <GitRemoteBranch > remoteBranches ;
34+ private ArrayList <String > remoteBranchNames ;
35+ private ArrayList <GitLocalBranch > localBranches ;
36+ private ArrayList <String > localBranchNames ;
3237
3338 public GitflowBranchUtil (Project project , GitRepository repo ){
3439 myProject =project ;
@@ -38,27 +43,57 @@ public GitflowBranchUtil(Project project, GitRepository repo){
3843 currentBranchName = GitBranchUtil .getBranchNameOrRev (repo );
3944
4045 branchnameMaster = GitflowConfigUtil .getMasterBranch (project , repo );
46+ branchnameDevelop = GitflowConfigUtil .getDevelopBranch (project , repo );
4147 prefixFeature = GitflowConfigUtil .getFeaturePrefix (project , repo );
4248 prefixRelease = GitflowConfigUtil .getReleasePrefix (project , repo );
4349 prefixHotfix = GitflowConfigUtil .getHotfixPrefix (project , repo );
4450 prefixBugfix = GitflowConfigUtil .getBugfixPrefix (project , repo );
51+
52+ initRemoteBranches ();
53+ initLocalBranchNames ();
4554 }
4655 }
4756
48- public boolean hasGitflow (){
49- boolean hasGitflow =false ;
57+ public String getCurrentBranchName () {
58+ return currentBranchName ;
59+ }
5060
51- hasGitflow = myRepo != null
52- && GitflowConfigUtil .getMasterBranch (myProject , myRepo )!=null
53- && GitflowConfigUtil .getDevelopBranch (myProject , myRepo )!=null
54- && GitflowConfigUtil .getFeaturePrefix (myProject , myRepo )!=null
55- && GitflowConfigUtil .getReleasePrefix (myProject , myRepo )!=null
56- && GitflowConfigUtil .getHotfixPrefix (myProject , myRepo )!=null
57- && GitflowConfigUtil .getBugfixPrefix (myProject , myRepo )!=null ;
61+ public boolean hasGitflow (){
62+ boolean hasGitflow = myRepo != null
63+ && branchnameMaster != null
64+ && branchnameDevelop != null
65+ && prefixFeature != null
66+ && prefixRelease != null
67+ && prefixHotfix != null
68+ && prefixBugfix != null ;
5869
5970 return hasGitflow ;
6071 }
6172
73+ public String getBranchnameMaster () {
74+ return branchnameMaster ;
75+ }
76+
77+ public String getBranchnameDevelop () {
78+ return branchnameDevelop ;
79+ }
80+
81+ public String getPrefixFeature () {
82+ return prefixFeature ;
83+ }
84+
85+ public String getPrefixRelease () {
86+ return prefixRelease ;
87+ }
88+
89+ public String getPrefixHotfix () {
90+ return prefixHotfix ;
91+ }
92+
93+ public String getPrefixBugfix () {
94+ return prefixBugfix ;
95+ }
96+
6297 public boolean isCurrentBranchMaster (){
6398 return currentBranchName .startsWith (branchnameMaster );
6499 }
@@ -97,9 +132,31 @@ public boolean isBranchBugfix(String branchName){
97132 return branchName .startsWith (prefixBugfix );
98133 }
99134
135+ private void initRemoteBranches () {
136+ remoteBranches =
137+ new ArrayList <GitRemoteBranch >(myRepo .getBranches ().getRemoteBranches ());
138+ remoteBranchNames = new ArrayList <String >();
139+
140+ for (Iterator <GitRemoteBranch > i = remoteBranches .iterator (); i .hasNext (); ) {
141+ GitRemoteBranch branch = i .next ();
142+ remoteBranchNames .add (branch .getName ());
143+ }
144+ }
145+
146+ private void initLocalBranchNames (){
147+ localBranches =
148+ new ArrayList <GitLocalBranch >(myRepo .getBranches ().getLocalBranches ());
149+ localBranchNames = new ArrayList <String >();
150+
151+ for (Iterator <GitLocalBranch > i = localBranches .iterator (); i .hasNext (); ) {
152+ GitLocalBranch branch = i .next ();
153+ localBranchNames .add (branch .getName ());
154+ }
155+ }
156+
100157 //if no prefix specified, returns all remote branches
101158 public ArrayList <String > getRemoteBranchesWithPrefix (String prefix ){
102- ArrayList <String > remoteBranches = getRemoteBranchNames () ;
159+ ArrayList <String > remoteBranches = remoteBranchNames ;
103160 ArrayList <String > selectedBranches = new ArrayList <String >();
104161
105162 for (Iterator <String > i = remoteBranches .iterator (); i .hasNext (); ) {
@@ -127,40 +184,19 @@ public ArrayList<String> filterBranchListByPrefix(Collection<String> inputBranch
127184 }
128185
129186 public ArrayList <String > getRemoteBranchNames (){
130- ArrayList <GitRemoteBranch > remoteBranches = new ArrayList <GitRemoteBranch >(myRepo .getBranches ().getRemoteBranches ());
131- ArrayList <String > branchNameList = new ArrayList <String >();
132-
133- for (Iterator <GitRemoteBranch > i = remoteBranches .iterator (); i .hasNext (); ) {
134- GitRemoteBranch branch = i .next ();
135- branchNameList .add (branch .getName ());
136- }
137-
138- return branchNameList ;
187+ return remoteBranchNames ;
139188 }
140189
141-
142- public ArrayList <String > getLocalBranchNames (){
143- ArrayList <GitLocalBranch > localBranches = new ArrayList <GitLocalBranch >(myRepo .getBranches ().getLocalBranches ());
144- ArrayList <String > branchNameList = new ArrayList <String >();
145-
146- for (Iterator <GitLocalBranch > i = localBranches .iterator (); i .hasNext (); ) {
147- GitLocalBranch branch = i .next ();
148- branchNameList .add (branch .getName ());
149- }
150-
151- return branchNameList ;
190+ public ArrayList <String > getLocalBranchNames () {
191+ return localBranchNames ;
152192 }
153193
154-
155-
156194 public GitRemote getRemoteByBranch (String branchName ){
157195 GitRemote remote =null ;
158196
159- ArrayList <GitRemoteBranch > remoteBranches = new ArrayList <GitRemoteBranch >(myRepo .getBranches ().getRemoteBranches ());
160-
161197 for (Iterator <GitRemoteBranch > i = remoteBranches .iterator (); i .hasNext (); ) {
162198 GitRemoteBranch branch = i .next ();
163- if (branch .getName ()== branchName ){
199+ if (branch .getName (). equals ( branchName ) ){
164200 remote =branch .getRemote ();
165201 break ;
166202 }
0 commit comments