@@ -23,12 +23,17 @@ public class GitflowBranchUtil {
23
23
Project myProject ;
24
24
GitRepository myRepo ;
25
25
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 ;
32
37
33
38
public GitflowBranchUtil (Project project , GitRepository repo ){
34
39
myProject =project ;
@@ -38,27 +43,57 @@ public GitflowBranchUtil(Project project, GitRepository repo){
38
43
currentBranchName = GitBranchUtil .getBranchNameOrRev (repo );
39
44
40
45
branchnameMaster = GitflowConfigUtil .getMasterBranch (project , repo );
46
+ branchnameDevelop = GitflowConfigUtil .getDevelopBranch (project , repo );
41
47
prefixFeature = GitflowConfigUtil .getFeaturePrefix (project , repo );
42
48
prefixRelease = GitflowConfigUtil .getReleasePrefix (project , repo );
43
49
prefixHotfix = GitflowConfigUtil .getHotfixPrefix (project , repo );
44
50
prefixBugfix = GitflowConfigUtil .getBugfixPrefix (project , repo );
51
+
52
+ initRemoteBranches ();
53
+ initLocalBranchNames ();
45
54
}
46
55
}
47
56
48
- public boolean hasGitflow (){
49
- boolean hasGitflow =false ;
57
+ public String getCurrentBranchName () {
58
+ return currentBranchName ;
59
+ }
50
60
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 ;
58
69
59
70
return hasGitflow ;
60
71
}
61
72
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
+
62
97
public boolean isCurrentBranchMaster (){
63
98
return currentBranchName .startsWith (branchnameMaster );
64
99
}
@@ -97,9 +132,31 @@ public boolean isBranchBugfix(String branchName){
97
132
return branchName .startsWith (prefixBugfix );
98
133
}
99
134
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
+
100
157
//if no prefix specified, returns all remote branches
101
158
public ArrayList <String > getRemoteBranchesWithPrefix (String prefix ){
102
- ArrayList <String > remoteBranches = getRemoteBranchNames () ;
159
+ ArrayList <String > remoteBranches = remoteBranchNames ;
103
160
ArrayList <String > selectedBranches = new ArrayList <String >();
104
161
105
162
for (Iterator <String > i = remoteBranches .iterator (); i .hasNext (); ) {
@@ -127,40 +184,19 @@ public ArrayList<String> filterBranchListByPrefix(Collection<String> inputBranch
127
184
}
128
185
129
186
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 ;
139
188
}
140
189
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 ;
152
192
}
153
193
154
-
155
-
156
194
public GitRemote getRemoteByBranch (String branchName ){
157
195
GitRemote remote =null ;
158
196
159
- ArrayList <GitRemoteBranch > remoteBranches = new ArrayList <GitRemoteBranch >(myRepo .getBranches ().getRemoteBranches ());
160
-
161
197
for (Iterator <GitRemoteBranch > i = remoteBranches .iterator (); i .hasNext (); ) {
162
198
GitRemoteBranch branch = i .next ();
163
- if (branch .getName ()== branchName ){
199
+ if (branch .getName (). equals ( branchName ) ){
164
200
remote =branch .getRemote ();
165
201
break ;
166
202
}
0 commit comments