@@ -74,26 +74,26 @@ type BranchInfos struct {
74
74
brLines []string
75
75
76
76
current * BranchInfo
77
- // local branches. key is short branch name, eg: dev
78
- locales map [ string ]* BranchInfo
79
- // remote branches. key is full branch name, eg: origin/dev
80
- remotes map [ string ]* BranchInfo
77
+ // local branch list
78
+ locales [ ]* BranchInfo
79
+ // all remote branch list
80
+ remotes [ ]* BranchInfo
81
81
}
82
82
83
83
// EmptyBranchInfos instance
84
84
func EmptyBranchInfos () * BranchInfos {
85
85
return & BranchInfos {
86
- locales : make (map [string ]* BranchInfo ),
87
- remotes : make (map [string ]* BranchInfo ),
86
+ // locales: make(map[string]*BranchInfo),
87
+ // remotes: make(map[string]*BranchInfo),
88
88
}
89
89
}
90
90
91
91
// NewBranchInfos create
92
92
func NewBranchInfos (gitOut string ) * BranchInfos {
93
93
return & BranchInfos {
94
94
brLines : strings .Split (strings .TrimSpace (gitOut ), "\n " ),
95
- locales : make (map [string ]* BranchInfo ),
96
- remotes : make (map [string ]* BranchInfo ),
95
+ // locales: make(map[string]*BranchInfo),
96
+ // remotes: make(map[string]*BranchInfo),
97
97
}
98
98
}
99
99
@@ -124,10 +124,9 @@ func (bs *BranchInfos) Parse() *BranchInfos {
124
124
125
125
// collect
126
126
if info .IsRemoted () {
127
- bs .remotes [ info . Name ] = info
127
+ bs .remotes = append ( bs . remotes , info )
128
128
} else {
129
- bs .locales [info .Name ] = info
130
-
129
+ bs .locales = append (bs .locales , info )
131
130
if info .Current {
132
131
bs .current = info
133
132
}
@@ -187,7 +186,7 @@ const (
187
186
// // search on remotes
188
187
// Search("fea", BrSearchRemote)
189
188
// // search on remotes and remote name must be equals "origin"
190
- // Search("origin fea", BrSearchRemote)
189
+ // Search("origin: fea", BrSearchRemote)
191
190
func (bs * BranchInfos ) Search (name string , flag int ) []* BranchInfo {
192
191
var list []* BranchInfo
193
192
@@ -198,8 +197,8 @@ func (bs *BranchInfos) Search(name string, flag int) []*BranchInfo {
198
197
199
198
var remote string
200
199
// "remote name" - search on the remote
201
- if strings .Contains (name , " " ) {
202
- remote , name = strutil .MustCut (name , " " )
200
+ if strings .Contains (name , ": " ) {
201
+ remote , name = strutil .MustCut (name , ": " )
203
202
}
204
203
205
204
if remote == "" && flag & BrSearchLocal == BrSearchLocal {
@@ -246,23 +245,36 @@ func (bs *BranchInfos) Current() *BranchInfo {
246
245
}
247
246
248
247
// Locales branches
249
- func (bs * BranchInfos ) Locales () map [ string ]* BranchInfo {
248
+ func (bs * BranchInfos ) Locales () [ ]* BranchInfo {
250
249
return bs .locales
251
250
}
252
251
253
252
// Remotes branch infos get
254
253
//
255
254
// if remote="", will return all remote branches
256
- func (bs * BranchInfos ) Remotes (remote string ) map [ string ]* BranchInfo {
255
+ func (bs * BranchInfos ) Remotes (remote string ) [ ]* BranchInfo {
257
256
if remote == "" {
258
257
return bs .remotes
259
258
}
260
259
261
- rs := make (map [ string ]* BranchInfo )
262
- for name , info := range bs .remotes {
260
+ ls := make ([ ]* BranchInfo , 0 )
261
+ for _ , info := range bs .remotes {
263
262
if info .Remote == remote {
264
- rs [ name ] = info
263
+ ls = append ( ls , info )
265
264
}
266
265
}
267
- return rs
266
+ return ls
267
+ }
268
+
269
+ // All branches list
270
+ func (bs * BranchInfos ) All () []* BranchInfo {
271
+ ls := make ([]* BranchInfo , 0 , len (bs .locales )+ len (bs .remotes ))
272
+ for _ , info := range bs .locales {
273
+ ls = append (ls , info )
274
+ }
275
+
276
+ for _ , info := range bs .remotes {
277
+ ls = append (ls , info )
278
+ }
279
+ return ls
268
280
}
0 commit comments